简体   繁体   English

设置宽度,高度和中心JPanel

[英]set width, height and center JPanel

I want a Jpanel my java application outside a width and height setSize (700.400); 我想要一个Jpanel我的Java应用程序在width和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. 同样,需要在创建任何组件之前执行以上语句。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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