I'm pretty new to java and I've read some documentation on Layout specifically BoxLayout. I'm not hung up on BoxLayout but it seemed to do what I need. Problem is that label (status) is not left aligned and I can't seem to force it to the left. It will move left if I set the text to a really long line of text. Here is the code:

package tests;	

import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;

public class TestLayout extends JPanel {
	private JFrame frame;
	private JPanel view;
	private JLabel status;
	
  TestLayout(JFrame iframe) {
		frame  = iframe;
		setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
		//setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
		
		status = new JLabel("==> Hello");
		status.setHorizontalAlignment(0);
		//status.setAlignmentX(0.0f);
		view = new JPanel();
		view.setBackground(Color.white); 
		add(view);
	  add(status);
  }
		
  public static void main(String args[]) {
    JFrame frame = new JFrame("Test Layout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Display the window.
    TestLayout tl = new TestLayout(frame);
    frame.add(tl);
    frame.pack();
    frame.setSize(1100, 800);
		frame.validate();
    frame.setVisible(true);
  }
}

Any suggestions would be appreciated.

hi,
first i wonder why u extends the JPanel and make a new panel inside it?? also by this add statements you wrote, the view panel won't appear as the TestLayout object will be above it. so it mostly not appear.
am i right??

I'm pretty new to java and I've read some documentation on Layout specifically BoxLayout. I'm not hung up on BoxLayout but it seemed to do what I need. Problem is that label (status) is not left aligned and I can't seem to force it to the left. It will move left if I set the text to a really long line of text. Here is the code:

package tests;	

import java.awt.*;
import java.awt.geom.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;

public class TestLayout extends JPanel {
	private JFrame frame;
	private JPanel view;
	private JLabel status;
	
  TestLayout(JFrame iframe) {
		frame  = iframe;
		setLayout(new BoxLayout(this,BoxLayout.PAGE_AXIS));
		//setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
		
		status = new JLabel("==> Hello");
		status.setHorizontalAlignment(0);
		//status.setAlignmentX(0.0f);
		view = new JPanel();
		view.setBackground(Color.white); 
		add(view);
	  add(status);
  }
		
  public static void main(String args[]) {
    JFrame frame = new JFrame("Test Layout");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    //Display the window.
    TestLayout tl = new TestLayout(frame);
    frame.add(tl);
    frame.pack();
    frame.setSize(1100, 800);
		frame.validate();
    frame.setVisible(true);
  }
}

Any suggestions would be appreciated.

Yes, it may seem pointless as written but I tried to find a simple code subset that I feel still looks like the original code, such that I felt confident that a fix for this will fix my more complicated setup.

hi,
first i wonder why u extends the JPanel and make a new panel inside it?? also by this add statements you wrote, the view panel won't appear as the TestLayout object will be above it. so it mostly not appear.
am i right??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.