I want to add a status bar into my Java application in netbeans.
I googled about it and I found this article:
How can I create a bar in the bottom of a Java app, like a status bar?
I did the same as in that article but I had an error.
This is the code I tried:
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);
}
and this is the error message for the line PersonelMainForm.add(statusPanel, BorderLayout.SOUTH);
:
non-static method
add(java.awt.Component,java.lang.Object)
cannot be referenced from a static context
and this is the error message for the line statusPanel.setPreferredSize(new Dimension(PersonelMainForm.getWidth(), 16));
:
Exception in thread "AWT-EventQueue-0"
java.lang.RuntimeException
: Uncompilable source code - non-static methodgetWidth()
cannot be referenced from a static context