Results 1 to 2 of 2
Thread: Cant get text to align in JLabel
- 02-12-2012, 07:24 PM #1
Member
- Join Date
- Nov 2011
- Posts
- 4
- Rep Power
- 0
Cant get text to align in JLabel
Ok, so this is what I have got so far:

I want the "Output" label to appear to be aligned in the top left. How do I achieve this?
My code snipper is:
Any help appreciated, regardsJava 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:"); output_area.add(output); area = new JTextArea(5,20); area.setOpaque(false); area.setEditable(false); output_area.add(area); input = new JLabel("Input:"); input_area.add(input); inputArea = new JTextField(10); Color color = output.getBackground(); inputArea.setEditable(false); inputArea.setBackground(color); inputArea.setBorder(null); input_area.add(inputArea);
- 02-12-2012, 09:19 PM #2
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,143
- Rep Power
- 5
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
-
How to horizontal align multi-line Text in a JTable-Cell
By Hotkey in forum AWT / SwingReplies: 3Last Post: 01-10-2012, 10:33 AM -
[SOLVED] How do you align/justify idividual table column header text?
By Angie in forum New To JavaReplies: 4Last Post: 02-05-2011, 06:47 PM -
JLabel won't left-align
By gib65 in forum AWT / SwingReplies: 6Last Post: 07-30-2010, 04:07 PM -
Java: How do i align the text in the center?
By nicacutenica in forum New To JavaReplies: 5Last Post: 06-29-2010, 06:50 PM -
JTextArea - text align
By bradder in forum AWT / SwingReplies: 1Last Post: 11-29-2007, 07:08 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks