Results 1 to 3 of 3
  1. #1
    dragon_baby is offline Member
    Join Date
    May 2012
    Posts
    10
    Rep Power
    0

    Default GUI labels allignment

    I cannot get to display different labels on top of each other, they are displayed in a row.
    Java Code:
    						label1.setText(book.getAuthor());
    						
    						icon.getImage().flush();
    						label1.setIcon(icon);
    						label1.setAlignmentX(BOTTOM_ALIGNMENT);
    					
    						label2.setText(book.getTitle());
    						label2.setAlignmentX(BOTTOM_ALIGNMENT);
    						
    						boolean a=book.getAvailability();
    						if(a==true)
    						{
    							label3.setText("Book is available");
                                                            label3.setAlignmentX(BOTTOM_ALIGNMENT);
    						
    						}
    						else
    						{
    							label3.setText("Book is unavailable");
    							label3.setAlignmentX(BOTTOM_ALIGNMENT);
    						
    						}
    What can I do?

    Ideally it would be that they are displayed next to the photo on top of each other, but doesn't matter really, I just don't want them next to each other.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  3. #3
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,663
    Blog Entries
    7
    Rep Power
    21

    Default Re: GUI labels allignment

    Nest your JPanels, i.e. the top level JPanel has a BorderLayout; the center is taken by a JPanel that stores the image and the west or east part is taken by a second JPanel; the second JPanel uses a GridLayout with one column and the appropriate number of rows; each element is taken by a JLabel.

    kind regards,

    Jos

    edit: too slow again (as always) ...
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Change backgroundcolor of Labels
    By Jan D in forum New To Java
    Replies: 2
    Last Post: 01-21-2012, 10:13 PM
  2. Printing labels to A4
    By eggy524 in forum New To Java
    Replies: 3
    Last Post: 09-23-2010, 04:53 PM
  3. size och swt labels
    By larsk in forum SWT / JFace
    Replies: 0
    Last Post: 10-04-2009, 12:01 PM
  4. How do I sent font of labels in an array?
    By Exhonour in forum New To Java
    Replies: 9
    Last Post: 01-14-2009, 03:48 PM
  5. Aligning Labels
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-02-2008, 06:26 PM

Posting Permissions

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