Skip to content

Instantly share code, notes, and snippets.

@Bios-Marcel
Created April 17, 2018 12:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Bios-Marcel/4b4c38c00c259e711f4757c12d4dc7c1 to your computer and use it in GitHub Desktop.
Save Bios-Marcel/4b4c38c00c259e711f4757c12d4dc7c1 to your computer and use it in GitHub Desktop.
Test disabling a JMenu in Swing
package com.mcs.testdisablejmenu
import javax.swing.JFrame
import javax.swing.JMenuBar
import javax.swing.JMenu
import javax.swing.JMenuItem
fun main(args: Array<String>) {
val menuBar = JMenuBar()
val menu = JMenu("Disable me")
menu.add(JMenuItem("Hello world"))
menuBar.add(menu)
//This call seems to have no effect on the enabled state of its contained components
//menuBar.setEnabled(false)
//This call leads to the JMenu ending up disabled (grayed out & unusable)
menu.setEnabled(false)
val frame = JFrame("Test disable JMenu")
frame.setJMenuBar(menuBar)
frame.pack()
frame.setLocation(300, 300)
frame.setVisible(true)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment