如何在 Java 中為 JFrame 設定最小尺寸限制
使用 setMinimumSize() 方法為 JFrame 設定最小尺寸限制 -
JFrame frame = new JFrame(); frame.setMinimumSize(new Dimension(500, 300));
以下是一個為 JFrame 設定最小尺寸限制的示例 -
示例
import java.awt.Color;
import java.awt.Dimension;
import javax.swing.JButton;
import javax.swing.JFrame;
public class SwingDemo {
public static void main(String[] args) {
JFrame frame = new JFrame();
JButton button = new JButton("Close!");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(button);
button.addActionListener(e -> {
frame.dispose();
});
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setMinimumSize(new Dimension(500, 300));
frame.getContentPane().setBackground(Color.ORANGE);
frame.pack();
frame.setVisible(true);
}
}輸出

廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP