Advertisement
Guest User

Adding a JMenuBar

a guest
Nov 4th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.01 KB | None | 0 0
  1. import java.awt.Dimension;
  2. import java.awt.event.ActionEvent;
  3. import java.awt.event.ActionListener;
  4. import java.awt.event.KeyEvent;
  5. import java.io.FileNotFoundException;
  6.  
  7. import javax.swing.*;
  8.  
  9. public class JavaAssignmentPanel {
  10.    
  11.     public static JMenuBar setupMenu() { // method modifiers where mising here
  12.  
  13.         JMenuBar menuBar = new JMenuBar(); // menubar
  14.         JMenu menu1 = new JMenu("Menu"); // menu
  15.         menuBar.add(menu1); // add menu to gui
  16.         JMenuItem menuItem1 = new JMenuItem("Item 1", KeyEvent.VK_1); // create
  17.                                                                         // drop
  18.                                                                         // down
  19.                                                                         // menu
  20.         menu1.add(menuItem1); // adds drop down menu to gui
  21.  
  22.         // execute code when selected
  23.         menuItem1.addActionListener(new ActionListener() {
  24.  
  25.             @Override
  26.             public void actionPerformed(ActionEvent e) {
  27.  
  28.                 // panel.showText("Example1 text - normally read from file");
  29.             }
  30.         });
  31.  
  32.         return menuBar;
  33.     }
  34.  
  35.     public static void main(String[] args) throws FileNotFoundException {
  36.  
  37.         window window = new window();
  38.  
  39.     }
  40.  
  41.     private static class window extends JFrame {
  42.  
  43.         public window() throws FileNotFoundException {
  44.  
  45.             JPanel leftScrollPane = new JPanel();
  46.             JPanel rightPane = new JPanel();
  47.             JSplitPane splitPane;
  48.  
  49.             this.setVisible(true);
  50.             this.setSize(400, 400);
  51.             this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  52.  
  53.             splitPane = new JSplitPane();
  54.             splitPane.setOrientation(JSplitPane.HORIZONTAL_SPLIT);
  55.             splitPane.setDividerSize(10);
  56.             splitPane.setDividerLocation(100);
  57.             splitPane.setLeftComponent(leftScrollPane);
  58.             splitPane.setRightComponent(rightPane);
  59.             splitPane.setOneTouchExpandable(true);
  60.             splitPane.setDividerLocation(200);
  61.  
  62.             Dimension minimumSize = new Dimension(100, 50);
  63.  
  64.             leftScrollPane.setSize(400, 400);
  65.            
  66.             this.setJMenuBar(setupMenu());
  67.             splitPane.setPreferredSize(new Dimension(400, 200));
  68.             splitPane.setLeftComponent(leftScrollPane);
  69.             splitPane.setRightComponent(rightPane);
  70.             this.add(splitPane);
  71.             this.setSize(1280, 720);
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement