Java GUI question

Discussion in 'OT Technology' started by morgue, Oct 2, 2006.

  1. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
    I need to make this:
    [​IMG]

    look like this:
    [​IMG]

    But I don't know how to...
    Here's the code, can you give me a hand?

    Code:
    
    import java.awt.GridLayout;
    import java.awt.Container;
    import java.awt.Font;
    import java.awt.event.ItemListener;
    import java.awt.event.ItemEvent;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    import javax.swing.JCheckBox;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    
    public class Align extends JFrame 
    {
       private JTextField textField; // text field
       private JTextField textField2;
       
       private JCheckBox snapToGrid; 
       private JCheckBox showGrid; 
       private JLabel label1;
       private JLabel label2;
       
       private JButton button1;
       private JButton button2;
       private JButton button3;
    
       private GridLayout gridLayout1;
       private Container container;
       
       private GridLayout gridLayout2;
       private Container container2;
       
       // CheckBoxFrame constructor adds JCheckBoxes to JFrame
       public Align()
       {
          super( "Align" );
          gridLayout1 = new GridLayout( 3, 3, 5, 5 );
          container = getContentPane(); 
          
          setLayout( gridLayout1 ); // set frame layout
    
          snapToGrid = new JCheckBox( "Snap to Grid" ); 
          showGrid = new JCheckBox( "Show Grid" ); 
          add( snapToGrid ); 
          
          label1 = new JLabel( "X:" );
          add ( label1 );
          
          // set up JTextField and set its font
          textField = new JTextField( " ", 3 );
          textField.setFont( new Font( "Serif", Font.PLAIN, 14 ) );
          add( textField ); // add textField to JFrame
    
    
          add( showGrid ); 
    
          label2 = new JLabel( "Y:" );
          add ( label2 );
          
          // set up JTextField and set its font
          textField2 = new JTextField( " ", 3 );
          textField2.setFont( new Font( "Serif", Font.PLAIN, 14 ) );
          add( textField2 ); // add textField to JFrame
          
    
          button1 = new JButton( "OK" );
          add (button1);       
          
          button2 = new JButton( "Cancel" );
          add (button2); 
          
          button3 = new JButton( "Help" );
          add (button3); 
    
    
       } // end constructor
    
    
    } // end class
    
    and

    Code:
    
    import javax.swing.JFrame;
    
    public class Align_Test
    {
       public static void main( String args[] )
       { 
          Align align = new Align(); 
          align.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
          align.setSize( 275, 140 ); // set frame size
          align.setVisible( true ); // display frame
       } // end main
    } // end class
    
     
  2. mobbarley

    mobbarley Active Member

    Joined:
    Mar 4, 2005
    Messages:
    9,256
    Likes Received:
    2
    Location:
    Sydney
  3. morgue

    morgue New Member

    Joined:
    Jul 10, 2004
    Messages:
    8,278
    Likes Received:
    0
  4. ///M Pilot

    ///M Pilot New Member

    Joined:
    Mar 16, 2006
    Messages:
    405
    Likes Received:
    0
    Location:
    Fort Liquordale, FL
    You get to learn about layouts and containers!!

    Look up GridBagLayout. It's going to be the most useful in completing your desired layout.
     

Share This Page