java - 设置 JPanel 的宽度、高度和中心

标签 java swing miglayout

我想要一个 Jpanel 我的 java 应用程序位于宽度和高度 setSize (700.400); 和屏幕中心之外。但我一直没能得到:

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);
  }
}

此代码不作为示例,它适合我的项目并运行,但无法调整大小。

最佳答案

and the center of the screen.

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

此外,上述语句需要在创建任何组件之前执行。

关于java - 设置 JPanel 的宽度、高度和中心,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36630865/

相关文章:

java - 如何关闭弹出对话框?

java.lang.NoSuchFieldError 错误

Java 硬件加速

java - 动态 JPanel 错误

java - 使用 JOptionPane API 的自定义对话框不会被释放

java - 在 MiG 布局中将默认间隙设置为 0

java - 将映射转换为 java 8 流中更扁平的结构

Java:让其他线程知道 GUI 是否可以使用

java - 如何在 Eclipse Indigo 中使用(运行)MigLayout?

java - 如何更改实现 MigLayout 的 JDesktopPane 中显示的 JInternalFrame 的大小?