I'm making a very basic application here, I've coded many times more complex applications but for some reason I am getting an error with the panel which sometimes shows its components and sometimes it is not even shown in the panel frame
The panel is composed of two basic components: 1 button and 1 Gtex field Buttons are shown sometimes, does not the Jetx field show up?
I am using a grid background layout. The following is very simple code:
Start the public class Start JFrame ActionListener {Public Stable HomeList home; Public stable string user = "default"; Public GridBagConstraints c = New GridBagConstraints (); Public start () {super ("title"); This.pack (); This.setSize (800, 500); // w h. This.setBackground (Color.DARK_GRAY); This.setLocationRelativeTo (zero); This.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); This.setResizable (wrong); This.setVisible (true); Zipel panel = new zpn (); Pane.setLayout (New GridBagLayout ()); Pane.setPreferredSize (new dimension (300, 100)); Pane.setBackground (Color.BLUE); This.getContentPane () Add (panel, BorderLayout.CENTER); Jebton Button = New Pocket ("Enter"); Button.setActionCommand ("Login to"); Button.addActionListener (this); C.gridx = 0; C. Grady = 0; Pane.add (button, c); JTextField text = new JTextField (20); Text.setVisible (true); C.gridx = 1; C. Grady = 0; Pane.add (text, c); } Public static zero main (string [] args) {new start (); } @ Override Public Zero Action Perfid (ActionAvent AE) {If ("Login". Ammons Ignore Sees (AE.Attection Commands)) {this.dispose (); Home = new homelist (user); The problem is that you setVisible (true) / Code> Before adding components of jframe
No comments:
Post a Comment