Java, Swing, JCombobox.
I need a single-line textbox with 2 arrows (up and down) instead of drop down list.
I'm sure that's pretty easy but i've not been succeeded to find solution.
Thanks in advance.
For your requirement, Java Swing already has a component called JSpinner.
have look at JSpinner with SpinnerListModel
Try using a
JList. Just set the height of the list so that only one element is visible at a time. For further infomation please refer to this...
http://zetcode.com/tutorials/javaswingtutorial/basicswingcomponentsII/
Related
I'm trying to set the number of options shown in the JComboBox drop down list when it is used as a JTable RowFilter. Specifically, the filter on occasion can have many options and I'd like to show twice as many as the default (which appears to be 8). See this image:
Combox Box Example http://aalto.tv/test/combobox-image.png
As you can hopefully see, this ComboBox only shows 8 items and I would like to show more if there are more to be seen.
Having searched around the popular solution is to call "setMaximumRowCount" on the JComboBox, however this is having no effect.
Can any one point me in the right direction?
Many thanks for any and all help!
Cheers,
Alex
try the revalidate() (or repaint()) method after setting the rowcount;
if a setXX method does not generate an event to the component, then you have to manually reset it.
failing that, look at the source code of the setMaximumRowCount() method
JComboBox#setMaximumRowCount works for JTable / TableHeader and AutoComplete JComboBox in the JTable too
I need to make an expandable list using java swing. I will attempt to demonstrate:
Unexpanded:
>[Expand me!]
>[And me!]
Expanded:
|[Expand me!]
>[Expand us too!]
>[Expand us too!]
>[Expand us too!]
>[And me!]
So, when you click on the "Expand me" portion of the list, another lists will drop down, possibly containing more expandable lists. If you were to click on it again, it's "sub-lists" would then retract. Pretty basic. And, as you can see, I am not looking for JComboBox, and I do not think JList can do this. If someone were to point me in the right direction, or give some programming examples, I would be grateful.
Thanks,
MirroredFate
How about using a JTree.
A control that displays a set of hierarchical data as an outline.
You can try using a JTable and put a button in the first column. When the button is clicked you add more data in the rows in between.
update
Something like this:
Or this
I think the first uses a JTree but that the idea.
BTW these two belong to JIDE Soft, check if it is feasible for you to buy a license:
http://www.jidesoft.com/products/grids.htm
Is not trivial to roll you own but is not impossible either.
check for TreeTable or one example or Outline, but with notice, that on official Java (SnOracle) pages any progress died ...,
For a specific screen, I'm looking for a JList that I could filter (the same way you can filter a JTable using a RowFilter)
Is there a good implementation of this kind of component anywhere here in the wild (and do you have an experience with it) or do I have to code it myself ?
(it is not that long to do, but if there is any valid implementation, I would be happy to use it)
Yes, I'm sure that the SwingX components provide this. Check out JXList.
You can get SwingX from here.
You could consider using a single column JTable instead of a JList. If you follow this approach you'll get filtering and sorting for free (providing you're using JDK 6).
IMHO glazedlists should do filtering as well as sorting for JTable, JList and JComboBox.
This may be a silly question I don't know.
Is there a way to remove the highlighter to represent focus in a Java GUI?
For example when you click on a button the text will have a slight rectangle around the text.
Thank you
I believe you want to remove the set focusable attribute from your items
using setFocusable(false)
http://java.sun.com/docs/books/tutorial/uiswing/misc/focus.html
That feature is there for a reason because it gives user feedback about which component currently has focus. But if you really must turn it off then you can use:
button.setFocusPainted( false );
As far as I knew one of the selling points of swing when it first appeared was that any GUI element could be completely customised. This might help you out: Custom Swing Controls
I understand how to make a multiple-select list box using JLists but I want to add JCheckBoxes to the list and make it dropdown like. The best visual representation I have found online is dropdown-check-list.
What would be the best way to accomplish the above?
I was thinking of a TableList. Any suggestions?
If you are using JList, then its as simple as changing the ListCellRenderer to return a JCheckbox component.
EDIT:
For JCombobox, you can use combobox.setRenderer(myListRenderer);
This code snippet may help you.
The basic idea is to handle actionPerformed or mouseClick events by yourself and keep states of the corresponding items (checked/unchecked) in your own data structure. You'll be able to use that data structure for rendering checkboxes in a dropdown