•
•
•
•
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
![]() |
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
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
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
----------------------------------------------
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
•
•
•
•
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?
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.
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
----------------------------------------------
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
•
•
•
•
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.
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
----------------------------------------------
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
![]() |
•
•
•
•
•
•
•
•
DaniWeb Java Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- Horizontal lines across display (Monitors, Displays and Video Cards)
- LCD- Partial Display, Black, Horizontal Line, Picture Shrunk (Monitors, Displays and Video Cards)
- Display Value in JcomboBox (Java)
Other Threads in the Java Forum
- Previous Thread: tracking grades
- Next Thread: help at work



Linear Mode