Results 1 to 3 of 3
Thread: Help with JTextBox please?
- 02-06-2013, 03:50 AM #1
Senior Member
- Join Date
- Jan 2013
- Posts
- 137
- Rep Power
- 0
Help with JTextBox please?
Hi guys, before I tell you my problem I just want you to know that I looked online but nowhere did I find why this error is happening; I am creating a panel and adding it to the JFrame and then adding a textbox to the panel. The program runs, but the textbox is not displayed? Did I do it completely wrong or is it a quick fix? Thank you!
Java Code:import javax.swing.*; import javax.swing.JTextField; import java.awt.*; public class Box { Box(){ JFrame f = new JFrame("Text Box"); f.setSize(400,400); f.setVisible(true); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(); f.add(p); JTextField t = new JTextField("Enter numbers here.", 15); p.add(t); } public static void main(String[] args) { new Box(); } }
-
Re: Help with JTextBox please?
Resize the JFrame and tell me what happens.... the JTextField appears doesn't it?
Solution:
1) don't set the size of the JFrame.
2) Instead set the preferredSize of the JPanel (or override its getPreferredSize() method)
3) First add your components to the JFrame
4) *Then* call pack and setVisible(true) on the JFrame *after* adding all components to it.
- 02-06-2013, 05:36 AM #3
Senior Member
- Join Date
- Jan 2013
- Posts
- 137
- Rep Power
- 0
Similar Threads
-
Restricting size to a jtextbox
By wired-in=p in forum AWT / SwingReplies: 2Last Post: 03-06-2012, 04:16 AM -
how to save a pdf file as named in a Jtextbox.
By seredi in forum New To JavaReplies: 6Last Post: 09-20-2011, 03:27 PM -
Complex GUI 60 JComboBox + 40+ JTextBox
By Paul_White in forum New To JavaReplies: 8Last Post: 05-12-2011, 07:51 PM -
Jtextbox with dropdown list
By vijay_s in forum AWT / SwingReplies: 1Last Post: 05-08-2008, 10:17 PM -
Jtextbox with dropdown list
By vijay_s in forum AWT / SwingReplies: 3Last Post: 05-08-2008, 06:26 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks