I can't set the size of my JTextField
From C++ to PHP, debugging to webhosting; help and discussion about writing your latest program to running your website. NOT for help when your PC won't work.
| Announcements | Posted on | |
|---|---|---|
| Please change your TSR password | 23-05-2013 | |
-
I can't set the size of my JTextField
Hi, here's the code (I think it's only necessary to see this one panel where the problem is happening, but if you think I ought to post the whole 96 lines of code, please say):
The problem is that when the program is run, the JTextField object takes shape of the entire box on the right of the 2x1 grid of the panel object, rather than following my rules of what the size should beCode:JTextField grossIncTxt = new JTextField(5); ... JPanel one = new JPanel(); one.setLayout(new GridLayout(1,2)); one.add(new JLabel("Gross Income")); grossIncTxt.setMinimumSize(new Dimension(150,20)); grossIncTxt.setMaximumSize(new Dimension(150,20)); one.add(grossIncTxt); add(one);
halp plox! -
Re: I can't set the size of my JTextField
Look into the different layouts you can use.
I think if you use FlowLayout that would solve it, but it can be a little awkward sometimes.
http://download.oracle.com/javase/tu...yout/flow.html -
Re: I can't set the size of my JTextFieldah right, I'm not too good at positioning and stuff in Java (had a lot of problems with scrollboxes).(Original post by Dr Ben)
nah i need to use gridlayout for this, there must be some way to do this in gridlayout?
Have you tried using BoxLayout or a layout within a layout? I just play around with it for a while and it usually works. xD -
Re: I can't set the size of my JTextFieldYeah I use netbeans, I love netbeans, but doing that will just hide the gap in my java knowledge, I'd like to learn where I'm going wrong(Original post by xXedixXx)
What IDE are you using? Because if you use NetBean's swing editor it's really easy to set the size of text fields, buttons etc.. both graphically and via a properties dialog. -
Re: I can't set the size of my JTextFieldFair enough; my advice would be to google some tutorials.(Original post by Dr Ben)
Yeah I use netbeans, I love netbeans, but doing that will just hide the gap in my java knowledge, I'd like to learn where I'm going wrong