Posts

Showing posts from March, 2021

Java Swing How to - Create Submenu on the Main menu

Image
  Java Swing How to - Create Submenu on the Main menu Menus are unique in that, by convention, they aren't placed with the other components in the UI. Instead, a menu usually appears either in a  menu bar  or as a  popup menu . A menu bar contains one or more menus and has a customary, platform-dependent location — usually along the top of a window. A popup menu is a menu that is invisible until the user makes a platform-specific mouse action, such as pressing the right mouse button, over a popup-enabled component. The popup menu then appears under the cursor. import javax.swing.*; import java.awt.event.KeyEvent; public class SubMenuExample { public static void main( final String args[]) { JFrame frame = new JFrame( "MenuSample Example" ); frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE ); JMenuBar menuBar = new JMenuBar(); // File Menu, F - Mnemonic JMenu fileMenu = new JMenu( "File" ); fileMenu.setMnemon...

Check Box With Event Listener in java Swing

Image
CheckBox with EventListener in Java Swing For CheckBox the more Common usage should be Combining is with event listener with the event listener, the checkBox can Act Different Action.. package JavaSwing; import javax.swing.*; import java.awt.*; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; public class CheckBoxWithEventListener { // Create Differnt CheBox public static JCheckBox cbox1 = new JCheckBox( "Name 1" ); public static JCheckBox cbox2 = new JCheckBox( "Name 2" ); public static JCheckBox cbox3 = new JCheckBox( "Name 3" ); public static JCheckBox cbox4 = new JCheckBox( "Name 4" ); public static void main(String [] args) { //Create and set up a Frame window JFrame. setDefaultLookAndFeelDecorated ( true ); JFrame frame = new JFrame( "CheckBoxWithEventLisetner" ); frame.setDefaultCloseOperation(JFrame. EXIT_ON_CLOSE ); //Define the panel to hol...