How to maintain the layout of components created by WindowBuilder in eclipse after compilation?

2

I created a JFrame using the Eclipse WindowBuilder plugin. Spacings, sizes and patterns were defined. However when compiling the project the standards are lost. Below the 2 photos for comparison.

Here is the JFrame Preview.

JFrameaftercompilation.

I would like to keep the layout and patterns of the first image. Could anyone help?

    
asked by anonymous 25.03.2015 / 13:20

1 answer

0

Add the following code into your main() :

        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Throwable e) {
            e.printStackTrace();
        }

For example, leaving this:

public class Tela extends JFrame {
    private static final long serialVersionUID = 1L;
    private JPanel contentPane;
    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        try {
            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        } catch (Throwable e) {
            e.printStackTrace();
        }
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    Tela frame = new Tela();
                    frame.setVisible(true); 
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }
    /**
     * Create the frame.
     */
    public Tela() {
        ...
    }
}

By adding the code in question, you are applying the Look and Feel of your system, otherwise the application will choose the default that is Metal.

  

CrossPlatformLookAndFeel-this is the "Java L & F" (also called "Metal") that looks the same on all platforms. It is part of the Java API (javax.swing.plaf.metal) and is the default that will be used if you do nothing in your code to set a different L & F.

Source: The Java Tutorials - How to Set the Look and Feel

    
25.03.2015 / 13:43