netbeans の Java アプリケーションにステータス バーを追加したいと考えています。
私はそれについてググって、この記事を見つけました:
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()
は静的コンテキストから参照できません