I have problem even my JFrame
is simple: I want Frame with 2 JPanel
one with TextArea
and the other with two button(Save, Close) , when I create my frame either the TextArea
just appear without the buttons, and to solve this I use setVisible(true)
the two panels appear but with this error:
(Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException:
This operation is permitted on the event thread only; currentThread = AWT-EventQueue-0
at com.sun.glass.ui.Application.checkEventThread(Application.java:443)
at com.sun.glass.ui.Cursor.setVisible(Cursor.java:107) for using setVisible(true))
Here my code:
JPanel textAreaGrid = new JPanel(new GridLayout(1, 0, 3, 3)); // gridlayout 1 row
textAreaGrid.add(new JScrollPane(textArea));
JPanel buttonPanel = new JPanel(new GridLayout(1, 0, 3, 3));
buttonPanel.add(new JButton("Save"));
buttonPanel.add(new JButton("End"));
JPanel mainPanel = new JPanel();
mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
mainPanel.setLayout(new BorderLayout(3, 3)); // main GUI uses border layout
mainPanel.add(textAreaGrid, BorderLayout.CENTER);
mainPanel.add(buttonPanel, BorderLayout.PAGE_END);
JFrame frame = new JFrame("The Results");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.getContentPane().add(mainPanel);
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);
setVisible(true);