Bloosy
Technical User
- Jun 23, 2003
- 15
I want to make a panel which shows four quarter final football matches, so that user can input result for each match. As I haven't got time for fancy design, I've decided to lay out text fields vertically, using Box layout. So, for one match I need two fields with 40 columns for team name (which is country name), two small fields for scores and a button for exporting data to further processing.
But I found out that program doesn't care for the size of fields I set. It uses all available size, and all the fields are of the maximum width. I spent hours trying to find the way without success. All tutorials claim that box layout respects the preffered size of the components. Here is a piece of code I've been experimenting with:
public class Pan extends JFrame {
private JPanel quarterPanel;
private JTextField match11, match12, match21, match22, match31, match32, match41, match42;
private JTextField score11, score12, score21, score22, score31, score32, score41, score42;
private JButton btnMatch1, btnMatch2, btnMatch3, btnMatch4;
public Pan() {
quarterPanel = new JPanel();
quarterPanel.setLayout(new BoxLayout(quarterPanel, BoxLayout.Y_AXIS));
match11 = new JTextField(40);
quarterPanel.add(match11);
score11 = new JTextField(6);
quarterPanel.add(score11);
match12 = new JTextField(10);
quarterPanel.add(match12);
score12 = new JTextField(6);
quarterPanel.add(score12);
btnMatch1 = new JButton("Enter Result for Match 1");
add(quarterPanel);
}
So this is for the first match, and I have to add three more, but I must somehow get those fields for scores to be small.
I'd really appreciate if somebody could help
But I found out that program doesn't care for the size of fields I set. It uses all available size, and all the fields are of the maximum width. I spent hours trying to find the way without success. All tutorials claim that box layout respects the preffered size of the components. Here is a piece of code I've been experimenting with:
public class Pan extends JFrame {
private JPanel quarterPanel;
private JTextField match11, match12, match21, match22, match31, match32, match41, match42;
private JTextField score11, score12, score21, score22, score31, score32, score41, score42;
private JButton btnMatch1, btnMatch2, btnMatch3, btnMatch4;
public Pan() {
quarterPanel = new JPanel();
quarterPanel.setLayout(new BoxLayout(quarterPanel, BoxLayout.Y_AXIS));
match11 = new JTextField(40);
quarterPanel.add(match11);
score11 = new JTextField(6);
quarterPanel.add(score11);
match12 = new JTextField(10);
quarterPanel.add(match12);
score12 = new JTextField(6);
quarterPanel.add(score12);
btnMatch1 = new JButton("Enter Result for Match 1");
add(quarterPanel);
}
So this is for the first match, and I have to add three more, but I must somehow get those fields for scores to be small.
I'd really appreciate if somebody could help