: Hey Zibadian
:
: Would you mind giving an example of the Riverlayout as the
: documentation looks confusing.... A clear example always helps me
: while writing Java Programs.....Can you please help me in this?
:
: Thanks
:
: Sriram
:
: : : I have a problem.The JPanel class titled p3 appears on the same line
: : : as that of the JPanle named p2...I wanted the JPanel p3 to appear
: : : columnwise and likewise for the remaining panels created... I tried
: : : the GridLayout class but that wasn't sufficient to move the labels
: : : and buttons of JPanel p3 to the next area below JPanel titled
: : : p2.....Can someone help me ASAP urgently? I have little experience
: : : with GUI programming in Java...
: : :
: : : Thanks
: : :
: : : Sriram
: : :
: : : ....Here is the sample code...
: : :
: : :
: : : // Panel p2 to hold buttons
: : : JPanel p2 = new JPanel(); //create a panel
: : : p2.setLayout(new GridLayout(3,1));
: : : p2.add(new JLabel("Customer "));
: : : p2.setLayout(new FlowLayout());
: : : p2.add(jbtAdd = new JButton("Add"));
: : : p2.add(jbtEdit = new JButton("Edit"));
: : : p2.add(jbtDelete = new JButton("Delete"));
: : : add(p2);
: : :
: : : JPanel p3 = new JPanel();
: : : p3.setLayout(new GridLayout(0,1));
: : : p3.add(new JLabel("Account "));
: : : p3.setLayout(new FlowLayout());
: : : p3.add(jbtadd1=new JButton("Add Account"));
: : : p3.add(jbtdel1=new JButton("Delete Account"));
: : : add(p3);
: : :
: : : JPanel p4 = new JPanel();
: : : p4.setLayout(new GridLayout(3,1));
: : : p4.add(new JLabel("Transaction "));
: : : p4.setLayout(new FlowLayout());
: : : p4.add(jbtdeposit = new JButton("Deposit"));
: : : p4.add(jbtWithdrawal = new JButton("Withdrawal"));
: : : p4.add(jbttransfer = new JButton("Transfer"));
: : : add(p4);
: : :
: : : //create a panel for radio buttons
: : : JPanel jreport = new JPanel();
: : : jreport.setLayout(new GridLayout(3,1));
: : :
: : :
: : : jreport.add(new JLabel("Report"));
: : : //create radio buttons
: : : jrCustomer= new JRadioButton("Customer Profile");
: : : jrAccount = new JRadioButton("Account Activity");
: : : jrSummary = new JRadioButton("Account Summary");
: : :
: : :
: : :
: : : //create radio button group and add radio buttons to it
: : : bgreport = new ButtonGroup();
: : : bgreport.add(jrCustomer);
: : : bgreport.add(jrAccount);
: : : bgreport.add(jrSummary);
: : :
: : :
: : : // //add buttons to panel - note that button group is not added
: : : jreport.add(jrCustomer);
: : : jreport.add(jrAccount);
: : : jreport.add(jrSummary);
: : :
: : Changing the layout while you're adding new objects to the GUI is
: : useless, because the layout is determined if the window is first
: : shown or is resized. Since the program doesn't remember the previous
: : layouts it always uses the last layout.
: : I was also unhappyt about the standard layout managers, so I looked
: : for other ones. I myself now use the RiverLayout. This allows you to
: : use html codes to handle line breaks, filling, etc. Just google for
: : it and you'll find it and its documentation.
:
:
Here's an example of a JLabel left of a row filling JTextField. Then follows a row of 2 centered buttons. I've left out the actual creation of the objects for readability, since those are layout independent.
add(myLabel, "br"); // start a new row
add(myEdit, "hfill"); // fill the rest of the row
add(myOK, "br center");
add(myCancel, "tab center"); // tab gives a space between the objects
If you resize the window, you'll notice that the label remains the same size, while the edit fills the entire row.