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

Asked

Viewed 676 times

2

I created a Jframe using the Eclipse Windowbuilder plugin. Spacing, sizes and patterns have been defined. However while compiling the project the patterns are lost. Below the 2 photos for comparison.

Here is the Jframe Preview.

inserir a descrição da imagem aqui

Jframe after compilation. inserir a descrição da imagem aqui

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

1 answer

0


Add the following code inside your main():

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

For example leaving so:

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 standard 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

  • Thanks @Math. Solved in parts my problem. The look and Feel components have been changed. However the problem of spacing still continues. :/

  • Spacing between the components? Could [Edit] your question and put a print to understand how it looks? 'Cause I can’t see that difference running my own project.

  • Take a look at figure 1, the buttons below "clean", "save" and "save and exit" are aligned, already in figure 2 after compilation these spacings are lost.

  • Oh yes, now I noticed this. Which Layout Manager is using in the footer? For example, Borderlayout, Gridbaglayout, Miglayout, etc..

  • 1

    I solved it. Just pay a little more attention on the grid! Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.