Alignment of JList and JComboBox
I would like to know how to set the horizontal alignment of JList's and JComboBox's. I've searched google but can't find anything.
If you know how to do this please let me know.
NOTE: I tried this on the JList but it had no effect:
Code:
JList.setAlignmentX(JList.CENTER_ALIGNMENT);
Re: Alignment of JList and JComboBox
What are you trying to allign. The content in the combobox or the combobox it self?
A JComboBox inheriths from JComponent. And it should have a setAlignmentX() function that takes a float as a parameter. A value that is 0.0 means left, and 1.0 means right.
- ØØ -
Re: Alignment of JList and JComboBox
That still doesn't work. It's not giving any change at all just like the JList did.
Re: Alignment of JList and JComboBox
Looking at the code System_Error provided it seems he wants to set the alignment of the contents not the Component itself. Same thing as setting the alignment of a JLabel using one of the Constants BOTTOM_ALIGNMENT, CENTER_ALIGNMENT ect ect.
Re: Alignment of JList and JComboBox
Both classes inherit the fields like LEFT_ALIGNMENT and RIGHT_ALIGNMENT, from java.awt.Componet but don't seem to provide a way to align the their contents via
an arg to the constructor or a set() method. :confused:
Re: Alignment of JList and JComboBox
I was searching google and finally found something:
http://forum.java.sun.com/thread.jsp...hreadID=616601
Someone with the same problem as me, but I'm not quit sure of what going on there. Can anyone simplify that or explain a bit?
Re: Alignment of JList and JComboBox
Have you tried it? It seems simple enough. :)
Just try the code first then worry about it later... when you actually try it you'll understand better.
Also I read about using this then... I think in the Javatutorials part.. or was that the JavaAlmanac... sorry havn't done java in a while. :) best bet is try it first. :)
Re: Alignment of JList and JComboBox
You could always write a renderer, for the list and the combo box, that centered the content, i mean then you'd only have to center the text in a JLabel which is as easy as doing setHorizontalJustification() or something simialir, i am lacking an API in front of me at the momment and am to lazy to search for one, but its probably teh easiest way to do it...