I am trying to place the components in the panel like this:
but in my code, it looks like this:
I have tried without FlowLayout
but the problem is the same. When I max the window size then it displays in a row, but when I try to resize the window size, components are out from border.
Will you please help me to resolve this issue? Here is my code:
CNameLabel=new JLabel("Customer Name");
CNameTextField = new JTextField (20); // create the Customer Name text field
CNameTextField.setEditable(true); // set editable text box
CIDLabel=new JLabel("Customer ID");
C_IDTextField = new JTextField (10);
C_IDTextField.setEditable(true); // set editable text box
// Creating and populating the Top Panel
The code below is for creating the panel, setting the border of the panel, and setting the flowlayout for the components:
topPanel=new JPanel();
topPanel.setLayout(new FlowLayout());
topPanel.setBorder(new TitledBorder(new EtchedBorder(), "Customer Data"));
topPanel.add(CNameLabel); topPanel.add(CNameTextField); topPanel.add(CIDLabel);
topPanel.add(C_IDTextField);
roomTypeLabel=new JLabel ("Room Type ");
//Create and populate Room type combo box
roomTypeCombo = new JComboBox();
roomTypeCombo.addItem( "Budget($50)" );
roomTypeCombo.addItem( "Standard($75)" );
roomTypeCombo.addItem( "Executive($200)" );
roomTypeCombo.addItem( "Luxury($400)" );
mealLabel=new JLabel ("Meal ");
//Create and populate Meal type combo box
mealCombo = new JComboBox();
mealCombo.addItem( "None" );
mealCombo.addItem( "Breakfast Only($10)" );
mealCombo.addItem( "Any Two($30)" );
mealCombo.addItem( "All Three($50)" );
daysLabel=new JLabel ("Days");
//Create and populate Days combo box
daysCombo = new JComboBox();
for(int i=0;i<31 ; i++)
{
daysCombo.addItem(i); // populate combobox with days
}
//Adding components to top panel
topPanel.add(roomTypeLabel);
topPanel.add(roomTypeCombo);
topPanel.add(mealLabel);
topPanel.add(mealCombo);
topPanel.add(daysLabel);
topPanel.add(daysCombo);
I have just skip the packages and declaration of the components. the program is running in fine condition
Thanks in advance.