Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

FlowLayout Horizontal gap setting NOT working

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).

reply
    Bookmark Topic Watch Topic
  • New Topic