Results 1 to 3 of 3
Thread: Nothing in JFrame
- 02-12-2013, 05:45 PM #1
Senior Member
- Join Date
- Jul 2012
- Posts
- 165
- Rep Power
- 1
Nothing in JFrame
I have just made a JFrame using this code but only the JFrame appears, not the text fields or the button. Why?
I initialise it usingJava Code:import java.awt.GridLayout; import javax.swing.*; public class LoginScreen extends JFrame { public LoginScreen(){ setLayout(new GridLayout(3, 1)); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); setSize(400, 250); JTextField usernameField = new JTextField("Username"); JPasswordField passwordField = new JPasswordField("Password"); JButton enterButton = new JButton("Submit"); add(usernameField); add(passwordField); add(enterButton); } }
Java Code:LoginScreen loginScreen = new LoginScreen();
- 02-12-2013, 06:36 PM #2
Re: Nothing in JFrame
Set it visible only after all content has been added. Oh, and all Swing constructors and methods should be invoked on the EDT. Go through this tutorial for a better understanding: Lesson: Concurrency in Swing (The Java™ Tutorials > Creating a GUI With JFC/Swing)
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-14-2013, 02:50 PM #3
Senior Member
- Join Date
- Jul 2012
- Posts
- 165
- Rep Power
- 1
Similar Threads
-
Click in JFrame Titlebar sets the JFrame Opaque
By tim8w in forum AWT / SwingReplies: 1Last Post: 02-02-2013, 07:29 AM -
Transferring information from one JFrame to Another JFrame
By cherylminor85 in forum AWT / SwingReplies: 4Last Post: 05-24-2012, 05:24 AM -
Calling another JFrame from a JFrame through a JButton...(Help Reqired)
By nish.singha20 in forum AWT / SwingReplies: 3Last Post: 11-27-2011, 05:18 AM -
to pass a parameter from a jframe children to its jframe mother
By anix in forum NetBeansReplies: 5Last Post: 06-14-2010, 06:10 PM -
How to make a Jframe un-focusable when another Jframe is active?
By Robert_85 in forum Advanced JavaReplies: 4Last Post: 04-22-2009, 11:02 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks