Results 1 to 2 of 2
  1. #1
    spect4cle is offline Member
    Join Date
    Nov 2011
    Rep Power

    Default Cant get text to align in JLabel

    Ok, so this is what I have got so far:

    Cant get text to align in JLabel-screen_shot_2012_02_12_at_18_19_52.png

    I want the "Output" label to appear to be aligned in the top left. How do I achieve this?

    My code snipper is:

    Java Code:
    		pane.setLayout(new BorderLayout());
    		// store a gridlayout and place in the center of the borderlayout
    		JPanel output_area = new JPanel(new FlowLayout(FlowLayout.LEFT));
    		JPanel input_area = new JPanel(new FlowLayout(FlowLayout.LEFT));
    		JPanel keyboard = new JPanel(new GridBagLayout());
    		pane.add(output_area, BorderLayout.NORTH);
    		pane.add(input_area, BorderLayout.CENTER);
    		pane.add(keyboard, BorderLayout.SOUTH);
    		output = new JLabel("Output:");
    		area = new JTextArea(5,20);
    		input = new JLabel("Input:");
    		inputArea = new JTextField(10);
    		Color color = output.getBackground();
    Any help appreciated, regards

  2. #2
    camickr is offline Senior Member
    Join Date
    Jul 2009
    Rep Power

    Default Re: Cant get text to align in JLabel

    It looks like your panel has two components, a label and a text area. A FlowLayout displays the components in the center of the vertical space required by the components.

    Try using a horizontal BoxLayout. Then you can control the vertical alignment of the components added to the panel. See: Fixing Alignment Problems.
    Last edited by camickr; 02-12-2012 at 09:24 PM.

Similar Threads

  1. Replies: 3
    Last Post: 01-10-2012, 10:33 AM
  2. Replies: 4
    Last Post: 02-05-2011, 06:47 PM
  3. JLabel won't left-align
    By gib65 in forum AWT / Swing
    Replies: 6
    Last Post: 07-30-2010, 04:07 PM
  4. Java: How do i align the text in the center?
    By nicacutenica in forum New To Java
    Replies: 5
    Last Post: 06-29-2010, 06:50 PM
  5. JTextArea - text align
    By bradder in forum AWT / Swing
    Replies: 1
    Last Post: 11-29-2007, 07:08 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