I'm fairly new to Java. I set the size for JButton
and JTextField
, but it looks like it didn't take my variable. Would someone tell me how can I solve this problem: whatever I change the variable, it looks the same. Thanks in advance.
This is my code:
private static int categoryButtonWidth= 140;
private static int categoryTextFieldWidth=260;
private static int categoryHight=40;
private void setCategoryPanel(){
//set the color label category
JPanel panelCategory=new JPanel();
panelCategory.setLayout(new FlowLayout(FlowLayout.LEADING));
JButton btnCategory1=new JButton(" ");
btnCategory_1.setSize(new Dimension ( categoryButtonWidth, categoryHight));
btnCategory_1.setBackground(Color.red);
btnCategory_1.addActionListener(this);
panelCategory.add(btnCategory_1);
JTextField txtCategory1 = new JTextField(20);
txtCategory_1.setSize(new Dimension (categoryTextFieldWidth, categoryHight));
panelCategory.add(txtCategory_1);
JButton btnCategory_2=new JButton(" ");
btnCategory_2.setSize(new Dimension ( categoryButtonWidth, categoryHight));
btnCategory_2.setBackground(Color.YELLOW);
btnCategory_2.addActionListener(this);
panelCategory.add(btnCategory_2);
JTextField txtCategory2 = new JTextField(20);
txtCategory2.setSize(new Dimension (categoryTextFieldWidth, categoryHight));
panelCategory.add(txtCategory2);
this.add(panelCategory, BorderLayout.NORTH);
}