views:

48

answers:

2

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 jButtonAddActionPerformed(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

alt text

Broken

alt text

+4  A: 

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.

camickr
Using a JLabel instead of a JPanel fixed it.
JackN
+2  A: 

I'd suggest reading Mixing Heavyweight and Lightweight Components for more information.

Ishtar