简体   繁体   中英

set width, height and center JPanel

I want a Jpanel my java application outside a width and height setSize (700.400); and the center of the screen. But I have not been able to get:

public class MainView extends JFrame {
private static final long serialVersionUID = -3698259040339973565L;

private JPanel _main;
private JPanel _log;
private CardLayout _cl = new CardLayout();

/**
 * 
 */
public MainView() {
    JPanel main = new JPanel();
    main.setLayout(new MigLayout("fill, gapy 2lp, insets 0", "", "[grow 90, 90%][grow 10, 10%]"));

    _main = new JPanel();
    _main.setLayout(_cl);
    _log = new JPanel();

    main.setBackground(Color.decode(Config.Config.COLOR_BACKGROUND));

    main.add(_main,     "grow, align center, wrap");
    main.add(_log,      "grow, hmin 80lp, hmax 80lp");

    this.setUndecorated(true);
    this.add(main);

    this.setTitle("Fotofinisher");
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setVisible(true);

    try {
        UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
    } catch (Exception e) {
        e.printStackTrace();
    }
    this.setFocusable(true);
  }
}

This code not take an example, it suits my project and run but can not resize.

and the center of the screen.

setSize (700.400); 
setLocationRelativeTo(null);
setVisible(true);
 UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() ); 

Also, the above statement needs to be executed BEFORE any component is created.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM