我想在 netbeans 中的 Java 应用程序中添加一个状态栏。
我用谷歌搜索了一下,发现了这篇文章:
我在那篇文章中做了同样的事情,但我有一个错误。
这是我试过的代码:
public void run() {
PersonelMainForm personelMainForm = new PersonelMainForm();
personelMainForm.setExtendedState(
personelMainForm.getExtendedState()|JFrame.MAXIMIZED_BOTH );
// create the status bar panel and shove it down the bottom of the frame
statusPanel = new JPanel();
statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
PersonelMainForm.add(statusPanel, BorderLayout.SOUTH);
statusPanel.setPreferredSize(new Dimension(PersonelMainForm.getWidth(), 16));
statusPanel.setLayout(new BoxLayout(statusPanel, BoxLayout.X_AXIS));
JLabel statusLabel = new JLabel("status");
statusLabel.setHorizontalAlignment(SwingConstants.LEFT);
statusPanel.add(statusLabel);
personelMainForm.setVisible(true);
}
这是该行的错误消息PersonelMainForm.add(statusPanel, BorderLayout.SOUTH);
:
add(java.awt.Component,java.lang.Object)
不能从静态上下文中引用非静态方法
这是该行的错误消息statusPanel.setPreferredSize(new Dimension(PersonelMainForm.getWidth(), 16));
:
线程“AWT-EventQueue-0”中的异常:无法编译的源代码 -无法从静态上下文引用
java.lang.RuntimeException
非静态方法getWidth()