Here is the program... I want the buttons to be laid of in this fashion.. Prev|Next Cancel Help. import javax.swing.*; import java.awt.*; import java.awt.event.*; class FlowLayoutTest extends JFrame { JButton prev, next, cancel, help;
FlowLayoutTest() { //create Bottom Panel FlowLayout fLayout = new FlowLayout(FlowLayout.RIGHT, 0, 5); System.out.println(fLayout.getHgap()); JPanel bottomPanel = new JPanel(fLayout); prev = new JButton("PREVIOUS"); bottomPanel.add( prev );
next = new JButton("NEXT"); bottomPanel.add( next );
fLayout.setHgap(20); cancel = new JButton("CANCEL"); bottomPanel.add( cancel );
fLayout.setHgap(5); help = new JButton("HELP"); bottomPanel.add( help ); getContentPane().add( bottomPanel, BorderLayout.SOUTH ); setBounds(300, 300, 400, 400); setVisible(true); }
static void main(String []args) { new FlowLayoutTest(); } } Running this program always has 5 pixel size of Horizontal gap irrespective of your settings.. can somebody explain me.. Is it a bug> Suren
Helmut Lerch
Ranch Hand
Joined: Feb 11, 2001
Posts: 48
posted
0
Hi,
Originally posted by Suren Babu: Here is the program... I want the buttons to be laid of in this fashion.. Prev|Next Cancel Help.
as I know FlowLayout uses one hGap for all gaps between Components. So since your last hGap setting is 5 it uses 5. It looks like you have to use GridBagLayout or use a panel in panel solution (i.e. a Panel with a GridLayout 1 row 3 columns, in the first column a Panel with a FlowLayout for Prev/Next, in the second an third column cancel and help).