I am trying to create an
applet using class FlowLayout to display: 2 - JCheckBoxes (stacked) on the LEFT, 2 - JLabels/JTextFields(stacked) in the MIDDLE and 3 - JButtons(stacked) on the right.
I am having trouble aligning the JCheckBoxes so they align left. I know FlowLayout arranges components in a left-to-right flow but my Check Boxes do not line up. I have reviewed the API but can't figure this out.
I have tried the GridLayout to no avail.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Excercise1208 extends JFrame {
private JTextField t;
private JCheckBox snap, show;
private JLabel label1, label2;
private JTextField text1, text2;
private JButton okButton, cancelButton, helpButton;
private FlowLayout layout;
public Excercise1208()
{
super( "Align" );
Container c = getContentPane();
c.setLayout(new FlowLayout());
snap = new JCheckBox( "Snap To Grid" );
c.add(snap);
label1 = new JLabel( "X: " );
label1.setToolTipText( "This is label1" );
c.add( label1 );
text1 = new JTextField( 3 );
c.add( text1 );
okButton = new JButton( "Ok" );
c.add( okButton );
show = new JCheckBox( "Show Grid" );
c.add(show );
label2 = new JLabel( "Y: " );
c.add( label2 );
text2 = new JTextField( 3 );
c.add( text2 );
cancelButton = new JButton( "Cancel" );
c.add( cancelButton );
helpButton = new JButton( "Help" );
c.add( helpButton );
setSize( 300, 125 );
show();
}
public static void main(
String args[] )
{
Excercise1208 app = new Excercise1208();
app.addWindowListener(
new WindowAdapter() {
public void windowClosing( WindowEvent e )
{
System.exit( 0 );
}
}
);
}
}