New in GUI, I have a simple JFrame
two JTextArea
example one Located next to each other and below one JPanel
.
import java.awt. *; Import java.awt.event.ActionListener; Import javax.swing *; Public square demo Jeffrera {Private JP panel; Private JTextArea JTextArea1; Private JTextArea JTextArea2; Personal Decision Decision Panel Panel; Private gridlate grid layout; Private Container Container; Public demo () {super ("demo"); Container myContainer = new container (); JTextArea1 = new JTextArea (); JTextArea2 = new JTextArea (); GridLayout Grid Layout = New Grid Layout (1, 2); MyContainer.setLayout (Grid layout); MyContainer.add (new JScrollPane (JTextArea1)); MyContainer.add (new JScrollPane (JTextArea2)); JFrame f = new JFrame (); F.add (myContainer, BorderLayout.CENTER); F.add (decision panel, border layout. PENDEND); F.setSize (400, 400); F.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); F.setVisible (true); }}
You also have to Or, expand with JFrame
is not visible; this is the correct way to add JTextArea
object to GridLayout
And is the container
used correctly? Do not start by increasing
JFrame
, this is causing you confusion. Basically, in your example code, there are two examples of JFrame
, so when actually it is shown on the screen? NullPointerException
as decision panel
has not been started.
public class demo {// JFrame {Personal JP panel; Private JTextArea JTextArea1; Private JTextArea JTextArea2; Personal Decision Decision Panel Panel; Private gridlate grid layout; Private Container Container; Public Demo () {Container My Container = New Container (); DecisionPanel = new decisionPainel (); JTextArea1 = new JTextArea (); JTextArea2 = new JTextArea (); GridLayout Grid Layout = New Grid Layout (1, 2); MyContainer.setLayout (gridLayout); MyContainer.add (new JScrollPane (JTextArea1)); MyContainer.add (new JScrollPane (JTextArea2)); Jeffram F = New Geoffram ("Demo"); F.add (myContainer, BorderLayout.CENTER); F.add (decision panel, border layout. PENDEND); F.setSize (400, 400); F.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); F.setVisible (true); }}
jpnil
and add the demo panel
to JFrame
independently, Which may be better depending on what you are trying to achieve ...
The public class demo has been expanded into JPanel {Private JPNL panel; Private JTextArea JTextArea1; Private JTextArea JTextArea2; Personal Decision Decision Panel Panel; Private gridlate grid layout; Private Container Container; Public Static Zero Main (String [] Elggs) {EventQueue.invokeLater {@Override Public Zero Run () {{UIManager.setLookAndFeel (UIManager.getSystemLookAndFeelClassName ())}} Hold (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ) {Ex.printStackTrace ();} JFrame frame = new JFrame ("test"); Frame.Set default close operation (JFrame.EXIT_ON_CLOSE); Frame.ed (new demo ()); Frame.ack (); Frame.Setlineschillate (faucet); Frames.Seviable (true);}}); } Public Demo () {setLayout (new border layout ()); Container myContainer = new container (); DecisionPanel = new decisionPainel (); JTextArea1 = new JTextArea (); JTextArea2 = new JTextArea (); GridLayout Grid Layout = New Grid Layout (1, 2); MyContainer.setLayout (gridLayout); MyContainer.add (new JScrollPane (JTextArea1)); MyContainer.add (new JScrollPane (JTextArea2)); Add (myContainer, BorderLayout.CENTER); Plus (decision panel, border layout. PAGE_END); }}
No comments:
Post a Comment