GroupLayout-import javax.swing.GroupLayout;

2013-03-19
2013-04-30
  • Omer Yasar Can
    Omer Yasar Can
    2013-03-19

    It seem that I can not use he Grouplayoutmanager with easy eclipse.

    import javax.swing.GroupLayout; gives me an errror.
    With Eclipse I get no error-message entering code with Grouplayout, just when compiling.

    Here is a simple project which I compile with eg bluej, but not with either eclipse or
    easy eclipse:

    package simplegrouplayout;

    //public class Simplegrouplayoutcre {
    //}

    import javax.swing.GroupLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;

    public class Simplegrouplayoutcre {
      public static void main(String args) {
        JFrame frame = new JFrame();
        JPanel panel = new JPanel();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        GroupLayout layout = new GroupLayout(panel);
        panel.setLayout(layout);

        JButton buttonD = new JButton("D");
        JButton buttonR = new JButton("R");
        JButton buttonY = new JButton("Y");
        JButton buttonO = new JButton("O");
        JButton buttonT = new JButton("T");

        GroupLayout.SequentialGroup leftToRight = layout.createSequentialGroup();

        leftToRight.addComponent(buttonD);
        GroupLayout.ParallelGroup columnMiddle = layout.createParallelGroup();
        columnMiddle.addComponent(buttonR);
        columnMiddle.addComponent(buttonO);
        columnMiddle.addComponent(buttonT);
        leftToRight.addGroup(columnMiddle);
        leftToRight.addComponent(buttonY);

        GroupLayout.SequentialGroup topToBottom = layout.createSequentialGroup();
        GroupLayout.ParallelGroup rowTop = layout.createParallelGroup();
        rowTop.addComponent(buttonD);
        rowTop.addComponent(buttonR);
        rowTop.addComponent(buttonY);
        topToBottom.addGroup(rowTop);
        topToBottom.addComponent(buttonO);
        topToBottom.addComponent(buttonT);

        layout.setHorizontalGroup(leftToRight);
        layout.setVerticalGroup(topToBottom);

        frame.add(panel);
        frame.pack();
        frame.setVisible(true);
      }
    }

    The code comes from
    http://www.java2s.com/Tutorial/Java/0240__Swing/AFramewithaGroupLayout.htm

    How to solve this?

    Thanks