User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Java section within the Software Development category of DaniWeb, a massive community of 427,178 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,255 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Java advertiser: Lunarpages Java Web Hosting
Views: 1704 | Replies: 5
Reply
Join Date: Feb 2005
Posts: 462
Reputation: winbatch is on a distinguished road 
Rep Power: 4
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

horizontal line/rule in JComboBox?

  #1  
Oct 9th, 2006
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
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Feb 2006
Posts: 1,460
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: horizontal line/rule in JComboBox?

  #2  
Oct 10th, 2006
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Feb 2005
Posts: 462
Reputation: winbatch is on a distinguished road 
Rep Power: 4
Solved Threads: 18
winbatch's Avatar
winbatch winbatch is offline Offline
Posting Pro in Training

Re: horizontal line/rule in JComboBox?

  #3  
Oct 10th, 2006
Originally Posted by masijade View Post
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?
Reply With Quote  
Join Date: Feb 2006
Posts: 1,460
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: horizontal line/rule in JComboBox?

  #4  
Oct 10th, 2006
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Join Date: Jan 2008
Posts: 3
Reputation: arun.reginald is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 1
arun.reginald's Avatar
arun.reginald arun.reginald is offline Offline
Newbie Poster

Solution Re: horizontal line/rule in JComboBox?

  #5  
Jan 23rd, 2008
Originally Posted by masijade View Post
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.
Reply With Quote  
Join Date: Feb 2006
Posts: 1,460
Reputation: masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice masijade is just really nice 
Rep Power: 9
Solved Threads: 131
masijade's Avatar
masijade masijade is offline Offline
Nearly a Posting Virtuoso

Re: horizontal line/rule in JComboBox?

  #6  
Jan 23rd, 2008
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.
Java Programmer and Sun Systems Administrator

----------------------------------------------

Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it.
--Brian Kernighan
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Java Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the Java Forum

All times are GMT -4. The time now is 9:37 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC