[英]set width, height and center JPanel
我想要一個Jpanel我的Java應用程序在width和height 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);
}
}
此代碼不帶示例,適合我的項目並運行,但無法調整大小。
和屏幕的中心。
setSize (700.400);
setLocationRelativeTo(null);
setVisible(true);
UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
同樣,需要在創建任何組件之前執行以上語句。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.