0

have this Java JFrame class, in which I want to use a boxlayout, but I get an error saying java.awt.AWTError: BoxLayout can't be shared

here is the code

public class secureChat {

    private JFrame myFrame;

    private int width;
    private int height;

    private JPanel allPanel;
    private JPanel titlePanel;
    private JPanel holdPanel;
    private JPanel serverPanel;
    private JPanel portPanel;
    private JPanel encrypPanel;
    private JPanel decrypPanel;


    public static void main(String[] args) {
        secureChat S = new secureChat();
    }

    public secureChat()
    {
        width = 600;
        height = 480;
        myFrame = new JFrame();
        myFrame.setLocation(450, 200);
        myFrame.setTitle("secure chat");
        myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        myFrame.setSize(width, height);

        allPanel = new JPanel();
        myFrame.add(allPanel);
        allPanel.setLayout(new BoxLayout(allPanel, BoxLayout.Y_AXIS));
        allPanel.setBackground(Color.blue);

        titlePanel = new JPanel();
        allPanel.add(titlePanel);
        titlePanel.setLayout(new BoxLayout(titlePanel, BoxLayout.X_AXIS));

        holdPanel = new JPanel();
        allPanel.add(holdPanel);
        holdPanel.setLayout(new BoxLayout(holdPanel, BoxLayout.X_AXIS));
    }
}

any help would be apreciated

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
  • 1
    I don't get any compilation or runtime error with the posted code. Try to clean and rebuild the project. If an exception is still thrown, post the stack trace and tell us which is the line that throws it (we can't see your line numbering). – user1803551 Apr 24 '15 at 23:09
  • 1
    Also, class names should start with an uppercase. – user1803551 Apr 24 '15 at 23:10
  • I think your problem is answered here: http://stackoverflow.com/questions/761341/boxlayout-cant-be-shared-error – Sruit A.Suk Apr 24 '15 at 23:44

0 Answers0