944,187 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 3899
  • Java RSS
Oct 9th, 2006
0

horizontal line/rule in JComboBox?

Expand Post »
Hi,

If I have a JComboBox which has a list of Strings which can be selected, is there a way to insert a line/horizontal rule inside to indicate some sort of grouping of values? If so, how do I do it? (Also, the actual line ------ should not be selectable in the dropdown. It is merely there to differentiate groups of values..)

Thanks,
winbatch
Similar Threads
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Oct 10th, 2006
0

Re: horizontal line/rule in JComboBox?

Sounds like you may be better off implementing a JTextField in combination with a PopupMenu. There you can use the menu separator. Pack them together into a custom component and you will be able to use it just like a JComboBox.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Oct 10th, 2006
0

Re: horizontal line/rule in JComboBox?

Click to Expand / Collapse  Quote originally posted by masijade ...
Sounds like you may be better off implementing a JTextField in combination with a PopupMenu. There you can use the menu separator. Pack them together into a custom component and you will be able to use it just like a JComboBox.
Would you happen to have some sample code?
Reputation Points: 68
Solved Threads: 18
Posting Pro in Training
winbatch is offline Offline
466 posts
since Feb 2005
Oct 10th, 2006
0

Re: horizontal line/rule in JComboBox?

Not here, and not now. Actually for this exact type of thing, not at all any more. If I still had access to the code from certain parts of the last project I worked on I would have something very similar, but I don't.

Here is the design idea.

Start with a JPanel implementing ActionLisitener
Add an ArrayList (or something else to act as the DataModel)
Add a JTextField
Add a button to the Left that opens a popupmenu
The Action Listener takes the selected menu item, adds it to the JTextfield and fires an ItemEvent

There are a few tweaks still to make, but that is the gist.

Have Fun.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006
Jan 23rd, 2008
0

Re: horizontal line/rule in JComboBox?

Click to Expand / Collapse  Quote originally posted by masijade ...
Sounds like you may be better off implementing a JTextField in combination with a PopupMenu.
All this can be done without that much hassle. The person above just needs to implement a ListCellRenderer object and a ComboBoxModel which would do the task for him/her.
Reputation Points: 10
Solved Threads: 1
Newbie Poster
arun.reginald is offline Offline
3 posts
since Jan 2008
Jan 23rd, 2008
0

Re: horizontal line/rule in JComboBox?

First, this is two years old, I doubt he's waiting any more. Second, don't forget that then the separator is also selectable and that he will have to add some hooks to either prevent it's selection actually doing anything, or better yet that it can't be selected at all, and then you're right back to about the same amount of work as the other possibilty.
Moderator
Reputation Points: 1471
Solved Threads: 490
Industrious Poster
masijade is offline Offline
4,043 posts
since Feb 2006

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: tracking grades
Next Thread in Java Forum Timeline: help at work





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC