Why isn't JMenu always on top?
The JMenu behaves normally until a JButton is used to update a JTable on the JFrame. Then the JMenu is mostly hidden by a JPanel (see images below). Shouldn't the JMenu always be on top when it is selected? Why has it been pushed to the back? The code that updates the table on jButtonAddActionPerformed is.
public class MyClass extends javax.swing.JFrame {
private void jButtonAddActio开发者_开发技巧nPerformed(java.awt.event.ActionEvent evt) {
DefaultTableModel model = (DefaultTableModel) jTable.getModel();
model.addRow(new Object[]{"", DEFAULT_ON, DEFAULT_OFF});
int lastRow = jTable.getRowCount() - 1;
jTable.setValueAt(lastRow + 1, lastRow, 0);
}
...
Expected
Broken
Probably because you are using a Canvas when you should be using a JPanel. Canvas is an AWT component and is painted on top of Swing components. Don't use AWT components in a Swing application.
Edit:
If you really need to use an AWT component then you need a current release of the JDK. See Mixing Heavy and Light Components.
I'd suggest reading Mixing Heavyweight and Lightweight Components for more information.
精彩评论