Results 1 to 4 of 4
- 02-19-2010, 06:51 AM #1
Member
- Join Date
- Aug 2009
- Posts
- 26
- Rep Power
- 0
Manually position JTextfield problem
hey i've got a problem with the following code in my JFrame class
The problem is I want to manually position my JTextField (riddleField) at the position 200,250 with width 90 and height 30 within my JPanel (rp). The frame is non-resizeable. I don't want to use any layout manager i just want it at the position that I've specified. But the problem is my JTextField is always drawn at the very top of the panel which is wrong. So there's something wrong with the way i've used the setBounds() method on my JTextField and I don't know what it is. Could someone please tell me how to have my JTextField set at the right position in my JPanel. I have to position a few objects in specific positions so if I know how to fix this i can apply the same to the others.Java Code:setBounds(halfWidth/2,halfHeight/2,350, 330); Container c = getContentPane(); c.setLayout(null); Font f = new Font("Sanserif", Font.BOLD, 30); riddleField = new JTextField("", 9); riddleField.setFont(f); riddleField.setBounds(200, 250, 90, 30); RiddlePanel rp = new RiddlePanel(); rp.add(riddleField); rp.setBounds(0,0,350,330); c.add(rp);
Thanks heaps, i appreciate all the help. :)
- 02-19-2010, 10:38 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Post the smallest full program that is compilable and runnable and demonstrates the problem.
- 02-19-2010, 04:52 PM #3
Senior Member
- Join Date
- Jul 2009
- Posts
- 1,146
- Rep Power
- 5
Why? Using Layout Managers is much easier. In this case all you need to do is:I don't want to use any layout manager
a) add an EmptyBorder to the panel
b) set the preferred size of the text field
c) add the text field to the panel and it will paint exactly where you want it to.
Null layouts are more trouble than they are worth.
- 02-20-2010, 05:24 AM #4
Member
- Join Date
- Feb 2010
- Posts
- 80
- Rep Power
- 0
Similar Threads
-
Manually adding a component
By djc in forum NetBeansReplies: 3Last Post: 04-01-2009, 11:51 AM -
get position in string from caret position
By helloworld111 in forum AWT / SwingReplies: 5Last Post: 02-19-2009, 01:36 AM -
how to access jTextField of one JFrame1 from JFrame2 & Modify JTextField contents
By sumit1mca in forum AWT / SwingReplies: 1Last Post: 01-30-2009, 06:44 PM -
Got problem with JtextField
By hungleon88 in forum AWT / SwingReplies: 4Last Post: 12-06-2008, 03:01 PM -
Handle exception manually
By John_28 in forum New To JavaReplies: 2Last Post: 06-05-2008, 11:26 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks