I have a menu that displays say
- Item1
- Item2
- Item3
etc. Clicking on Item1 should display me a Table with 2 columns.
I tried something below with displaying just a label. But the label gets displayed somewhere in the screen where as I am expecting it to be a submenu under menuitem1.
JMenu mainMenu = new JMenu("MainMenuHeader");
JMenu menuItem1 = new JMenu(new SomeClassExtendingAbstractAction("menuItem1"));
public class SomeClassExtendingAbstractAction extends AbstractAction {
public SomeClassExtendingAbstractAction(String displayText) {
super(displayText);
}
public void actionPerformed(ActionEvent event) {
try {
SubMenuDialog.showDialog(parent);
} catch (Throwable e) {
}
}
}
public class SubMenuDialog extends JDialog {
public SubMenuDialog(JFrame parent) {
super();
initialize();
}
private void initialize() {
JLabel label = new JLabel();
label.setText("This is test submenu");
getContentPane().add(label);
}
public static void showDialog(JFrame parent) {
SubMenuDialog subMenuDialog = new SubMenuDialog(parent);
subMenuDialog.pack();
subMenuDialog.setVisible(true);
}
}