0

Recently, I have decided to use WindowBuilder to create an interface. Thanks to the preview function, I am able to see how my application will look like. But when I'm compiling my program, here's what it looks like:

At the top, the desired result, at the bottom, the result obtained enter image description here

I don't understand what my problem is. Why every components react like this. Originally, I had put a FormLayout to solve the same problem, but I don't have the impression that this is what will solve it. Here is my code:

package IHM;

import java.awt.EventQueue;

import javax.swing.JFrame;
import com.jgoodies.forms.layout.FormLayout;
import com.jgoodies.forms.layout.ColumnSpec;
import com.jgoodies.forms.layout.RowSpec;
import com.jgoodies.forms.layout.FormSpecs;
import javax.swing.JTextField;
import javax.swing.JButton;
public class Test {

    private JFrame frame;
    private JTextField textField;
    private JTextField textField_1;
    private JTextField textField_2;
    private JButton btnSelection;
    private JTextField textField_3;
    private JButton btnCommencer;
    private JTextField textField_4;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Test window = new Test();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the application.
     */
    public Test() {
        initialize();
    }

    /**
     * Initialize the contents of the frame.
     */
    private void initialize() {
        frame = new JFrame();
        frame.setResizable(false);
        frame.setBounds(100, 100, 600, 350);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.getContentPane().setLayout(new FormLayout(new ColumnSpec[] {
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),
                ColumnSpec.decode("default:grow"),},
            new RowSpec[] {
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,
                FormSpecs.DEFAULT_ROWSPEC,}));

        textField = new JTextField();
        frame.getContentPane().add(textField, "3, 6, 3, 1, fill, default");
        textField.setColumns(10);

        textField_1 = new JTextField();
        frame.getContentPane().add(textField_1, "8, 6, 3, 1, fill, default");
        textField_1.setColumns(10);

        textField_2 = new JTextField();
        frame.getContentPane().add(textField_2, "13, 6, 3, 1, fill, default");
        textField_2.setColumns(10);

        JButton btnNewButton = new JButton("Selection");
        frame.getContentPane().add(btnNewButton, "4, 7");

        JButton btnNewButton_2 = new JButton("Selection");
        frame.getContentPane().add(btnNewButton_2, "9, 7");

        JButton btnNewButton_1 = new JButton("Selection");
        frame.getContentPane().add(btnNewButton_1, "14, 7");

        textField_3 = new JTextField();
        frame.getContentPane().add(textField_3, "3, 11, 9, 1, fill, default");
        textField_3.setColumns(10);

        btnSelection = new JButton("Selection");
        frame.getContentPane().add(btnSelection, "14, 11");

        btnCommencer = new JButton("Commencer");
        frame.getContentPane().add(btnCommencer, "9, 13");

        textField_4 = new JTextField();
        frame.getContentPane().add(textField_4, "6, 14, 7, 1, fill, default");
        textField_4.setColumns(10);

    }

}

Can someone help me please?

Draken
  • 3,134
  • 13
  • 34
  • 54
Piko
  • 11
  • 4

1 Answers1

0

You have to fiddle with the swing theme [1]. The WB preview uses a different them than the one you use when you run the program. At runtime there is probably no theme set.

[1] Java eclipse WindowBuilder, change look and feel

Yaza
  • 543
  • 3
  • 9