Results 1 to 8 of 8

Thread: Alignment of JList and JComboBox

Hybrid View

  1. #1

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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);

  2. #2
    Retired G&G Mod NoteMe's Avatar
    Join Date
    Oct 2002
    Location
    @ Opera Software
    Posts
    10,190

    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.


    - ØØ -

  3. #3

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: Alignment of JList and JComboBox

    That still doesn't work. It's not giving any change at all just like the JList did.

  4. #4
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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.

  5. #5
    Dazed Member
    Join Date
    Oct 1999
    Location
    Ridgefield Park, NJ
    Posts
    3,418

    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.

  6. #6

    Thread Starter
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    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?

  7. #7
    Frenzied Member oceanebelle's Avatar
    Join Date
    Jun 2005
    Location
    my n00k.
    Posts
    1,064

    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.

  8. #8
    Addicted Member
    Join Date
    May 2001
    Location
    UK
    Posts
    222

    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width