【发布时间】:2019-11-17 14:58:21
【问题描述】:
到目前为止:
- 我尝试了不同的 IDE——IntelliJ、VS Code 和 Net Bean——尽管我认为这不是问题所在。
- 我尝试将构造函数
TFDemo公开。 - 我尝试编译后通过终端运行。
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class SwingDemo {
SwingDemo() {
// Create a new JFrame container
JFrame jfrm = new JFrame("A Simple Swing Application");
// Gives the frame an initial size
jfrm.setSize(275, 100);
// Terminate the program when the user closes the application
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Create a text-based label
JLabel jlab = new JLabel(" GUI programming with Swing.");
// Add the label to the content pane
jfrm.add(jlab);
// Display the frame
jfrm.setVisible(true);
}
public static void main(String[] args) {
// Create the frame on the event dispatching thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
}
});
}
}
【问题讨论】:
-
// Gives the frame an initial size如果读取为// Gives the frame a totally guessed, and probably wrong(1) size会更准确。在这种情况下,将EmptyBorder添加到JLabel并添加后,pack()JFrame。然后框架将是显示标签和边框所需的最小尺寸。 1) 此外,根据每个操作系统中使用的“框架装饰”,它的大小会有所不同。
标签: java swing user-interface