Results 1 to 18 of 18
- 12-08-2012, 09:03 AM #1
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
JOption Pane Warning message help
So below is my code for a warning pane to pop up and tell the user to select only 1 name from my JList of names that I have. The only thing is that when this warning message runs, it doesn't show up until I click back inside my GUI, then it pops to the front. What I want to solve is have it so that it just automatically appears on the front when it is executed.
any ideas?
Java Code:public static String getSelectedNameController(AddressBookGUI ui) { String name1 = ui.getSelectedContact(); String name2 = ui.getSelectedFavorite(); if(name1 != null && name2 != null){ JOptionPane.showMessageDialog(warningFrame, "Please select names from only one list!", "Warning!", JOptionPane.WARNING_MESSAGE); return null; } else if(name1 != null && name2 == null){ return name1; } else{ return name2; } }
- 12-08-2012, 09:36 AM #2
- 12-08-2012, 09:36 AM #3
Re: JOption Pane Warning message help
Moved from New to Java.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-08-2012, 06:53 PM #4
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Re: JOption Pane Warning message help
because there are 2 different jlists, one is for contacts, the other for favoritesWhy don't you just set the JList's selection mode?
- 12-09-2012, 03:01 AM #5
- 12-09-2012, 04:16 AM #6
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Re: JOption Pane Warning message help
I know what it is. Don't always assume people who post on these forums aren't open for suggestions, because why else would I be posting here.
In my situation I am using 2 different models. a contactListModel, and a favoriteListModel. So now could you please explain to me how I could do that in the case that I am using 2 separate models. I looked into selection mode and it can be applied to a model, but it doesn't communicate between models... hence my issue, hence why I would like to have a warning box, hence my underlying problem of bringing the warning box to the front
-
Re: JOption Pane Warning message help
What Darryl is getting at is that JList has a method setSelectionModel(...) that if called correctly will guarantee that only one selection is ever possible, and that the API will show you all you need to know about this.
- 12-09-2012, 06:15 AM #8
-
Re: JOption Pane Warning message help
oops, yeah, what he says...
- 12-09-2012, 06:21 AM #10
Re: JOption Pane Warning message help
If -- and that's still not clear to me from your ramblings about two ListModels -- you are trying to ensure a single selection across two JLists, the easy way is to set SINGLE_SELECTION_MODE on both and clearSelection() on the other list when a selection is made.
If -- as seems possible from the names -- the 'favoriteListModel' holds a subset of the elements in the 'contactListModel' then selection listeners on both lists could update the selections to match whenever the selected element is present in both lists. Note that you may need a boolean flag to prevent infinite recursion between the two selection listeners.
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 12-09-2012, 06:29 AM #11
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Re: JOption Pane Warning message help
Okay, let me outline what both of the lists do. In fact, favoriteList IS a subset of contact list. Any contact in favorite list will be in contact list.
The way I have it set up is if I add a name to the favorite list it will be added to the contact list.
So now my two questions are being that I have contactListModel and favoritListModel do do I just need to setSelectionMode of the either listModel and my whole GUI will automatically be set so that only one person can be selected at a time? Or would I have to have an if else
- 12-09-2012, 06:31 AM #12
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Re: JOption Pane Warning message help
And if I am not relating to what you are saying could you possibly maybe give me some pseudo code to help me out
- 12-09-2012, 06:31 AM #13
Re: JOption Pane Warning message help
Why do they call it rush hour when nothing moves? - Robin Williams
- 12-09-2012, 06:32 AM #14
- 12-09-2012, 07:57 AM #15
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Re: JOption Pane Warning message help
okay, so I have a mouse click listener for BOTH my contactList and my favoriteList.
So, if I click within the contactList, should I do favoriteListModel.clearSelect();
and vice versa for my favoriteList?
- 12-09-2012, 09:47 AM #16
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Re: JOption Pane Warning message help
alright, so I actually figured it out, thank you. But still back to my original question, now just for clarity sake and for the future, how would I bring that warning frame to the front of the screen?
- 12-09-2012, 01:40 PM #17
Re: JOption Pane Warning message help
Why do they call it rush hour when nothing moves? - Robin Williams
- 12-09-2012, 07:52 PM #18
Senior Member
- Join Date
- Mar 2011
- Posts
- 171
- Rep Power
- 0
Re: JOption Pane Warning message help
I have gone through the API and I have looked into several things. I am using the MouseListener for something else. When the user clicks in the list it grabs the first selected contact, and does stuff with that information. In my current case, a MouseListener applies, and works the way I want it to. So, my plan was to have it so that when I hear a mouse click in the contact list, clear the selections from favorites. And when it hears a mouse click in the favorite list, clear the selections in contact list. And yes, my lists are also in SINGLE_SELECTION mode
Similar Threads
-
Help with Int and JOption Input dialog
By stephanie904 in forum New To JavaReplies: 1Last Post: 02-29-2012, 01:22 AM -
I need help with JOption Panel!
By jakex69 in forum New To JavaReplies: 3Last Post: 01-26-2012, 04:08 AM -
Example of JOption
By RanLineR in forum New To JavaReplies: 4Last Post: 10-20-2010, 12:27 PM -
JOption pop up window is behind all other windows
By biggmann in forum New To JavaReplies: 3Last Post: 10-15-2010, 08:24 PM -
JOption Msgbox title help?
By ZaabZ in forum New To JavaReplies: 7Last Post: 08-26-2010, 09:12 PM


2Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks