List of usage examples for javax.swing JMenu add
public JMenuItem add(Action a)
From source file:DataExchangeTest.java
public DataExchangeFrame() { setTitle("DataExchangeTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); // construct a File menu JMenuBar mbar = new JMenuBar(); setJMenuBar(mbar);//from w ww .j a v a 2 s.c om JMenu fileMenu = new JMenu("File"); mbar.add(fileMenu); // add Connect and Exit menu items JMenuItem connectItem = new JMenuItem("Connect"); connectItem.addActionListener(new ConnectAction()); fileMenu.add(connectItem); // The Exit item exits the program JMenuItem exitItem = new JMenuItem("Exit"); exitItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { System.exit(0); } }); fileMenu.add(exitItem); textArea = new JTextArea(); add(new JScrollPane(textArea), BorderLayout.CENTER); }
From source file:MessageDigestTest.java
public MessageDigestFrame() { setTitle("MessageDigestTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); JPanel panel = new JPanel(); ButtonGroup group = new ButtonGroup(); addRadioButton(panel, "SHA-1", group); addRadioButton(panel, "MD5", group); add(panel, BorderLayout.NORTH); add(new JScrollPane(message), BorderLayout.CENTER); add(digest, BorderLayout.SOUTH); digest.setFont(new Font("Monospaced", Font.PLAIN, 12)); setAlgorithm("SHA-1"); JMenuBar menuBar = new JMenuBar(); JMenu menu = new JMenu("File"); JMenuItem fileDigestItem = new JMenuItem("File digest"); fileDigestItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { loadFile();//www .j av a 2 s . co m } }); menu.add(fileDigestItem); JMenuItem textDigestItem = new JMenuItem("Text area digest"); textDigestItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { String m = message.getText(); computeDigest(m.getBytes()); } }); menu.add(textDigestItem); menuBar.add(menu); setJMenuBar(menuBar); }
From source file:MainClass.java
public MainClass() { JFrame frame = new JFrame(); JTextPane textPane = new JTextPane(); JScrollPane scrollPane = new JScrollPane(textPane); JPanel north = new JPanel(); JMenuBar menu = new JMenuBar(); JMenu styleMenu = new JMenu(); styleMenu.setText("Style"); Action boldAction = new BoldAction(); boldAction.putValue(Action.NAME, "Bold"); styleMenu.add(boldAction); Action italicAction = new ItalicAction(); italicAction.putValue(Action.NAME, "Italic"); styleMenu.add(italicAction);// w w w . j ava 2s. co m Action foregroundAction = new ForegroundAction(); foregroundAction.putValue(Action.NAME, "Color"); styleMenu.add(foregroundAction); Action formatTextAction = new FontAndSizeAction(); formatTextAction.putValue(Action.NAME, "Font and Size"); styleMenu.add(formatTextAction); menu.add(styleMenu); north.add(menu); frame.getContentPane().setLayout(new BorderLayout()); frame.getContentPane().add(north, BorderLayout.NORTH); frame.getContentPane().add(scrollPane, BorderLayout.CENTER); frame.setSize(800, 500); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); }
From source file:FillViewportHeightDemo.java
public FillViewportHeightDemo() { super("Empty Table DnD Demo"); tableModel = getDefaultTableModel(); table = new JTable(tableModel); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDropMode(DropMode.INSERT_ROWS); table.setTransferHandler(new TransferHandler() { public boolean canImport(TransferSupport support) { // for the demo, we'll only support drops (not clipboard paste) if (!support.isDrop()) { return false; }//from w w w. j a v a 2 s . c om // we only import Strings if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } return true; } public boolean importData(TransferSupport support) { // if we can't handle the import, say so if (!canImport(support)) { return false; } // fetch the drop location JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation(); int row = dl.getRow(); // fetch the data and bail if this fails String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException e) { return false; } catch (IOException e) { return false; } String[] rowData = data.split(","); tableModel.insertRow(row, rowData); Rectangle rect = table.getCellRect(row, 0, false); if (rect != null) { table.scrollRectToVisible(rect); } // demo stuff - remove for blog model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); // end demo stuff return true; } }); JList dragFrom = new JList(model); dragFrom.setFocusable(false); dragFrom.setPrototypeCellValue(getNextString(100)); model.insertElementAt(getNextString(count++), 0); dragFrom.setDragEnabled(true); dragFrom.setBorder(BorderFactory.createLoweredBevelBorder()); dragFrom.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) { String text = (String) model.getElementAt(0); String[] rowData = text.split(","); tableModel.insertRow(table.getRowCount(), rowData); model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); } } }); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); JPanel wrap = new JPanel(); wrap.add(new JLabel("Drag from here:")); wrap.add(dragFrom); p.add(Box.createHorizontalStrut(4)); p.add(Box.createGlue()); p.add(wrap); p.add(Box.createGlue()); p.add(Box.createHorizontalStrut(4)); getContentPane().add(p, BorderLayout.NORTH); JScrollPane sp = new JScrollPane(table); getContentPane().add(sp, BorderLayout.CENTER); fillBox = new JCheckBoxMenuItem("Fill Viewport Height"); fillBox.addActionListener(this); JMenuBar mb = new JMenuBar(); JMenu options = new JMenu("Options"); mb.add(options); setJMenuBar(mb); JMenuItem clear = new JMenuItem("Reset"); clear.addActionListener(this); options.add(clear); options.add(fillBox); getContentPane().setPreferredSize(new Dimension(260, 180)); }
From source file:Main.java
public JMenuBar createMenuBar() { JMenuBar top_menu_bar = new JMenuBar(); JMenu main_menu = new JMenu("Menu"); main_menu.setMnemonic(KeyEvent.VK_M); top_menu_bar.add(main_menu);/*from ww w .jav a2 s . c o m*/ JMenuItem menu_item; menu_item = new JMenuItem("Add New"); menu_item.setMnemonic(KeyEvent.VK_N); menu_item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.ALT_MASK)); menu_item.setActionCommand("new"); menu_item.addActionListener(e -> createThumb()); main_menu.add(menu_item); return top_menu_bar; }
From source file:TextCutPaste.java
/** * Create an Edit menu to support cut/copy/paste. */// w ww .j a v a2 s .c o m public JMenuBar createMenuBar() { JMenuItem menuItem = null; JMenuBar menuBar = new JMenuBar(); JMenu mainMenu = new JMenu("Edit"); mainMenu.setMnemonic(KeyEvent.VK_E); menuItem = new JMenuItem(new DefaultEditorKit.CutAction()); menuItem.setText("Cut"); menuItem.setMnemonic(KeyEvent.VK_T); mainMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.CopyAction()); menuItem.setText("Copy"); menuItem.setMnemonic(KeyEvent.VK_C); mainMenu.add(menuItem); menuItem = new JMenuItem(new DefaultEditorKit.PasteAction()); menuItem.setText("Paste"); menuItem.setMnemonic(KeyEvent.VK_P); mainMenu.add(menuItem); menuBar.add(mainMenu); return menuBar; }
From source file:com.haskins.cloudtrailviewer.sidebar.AbstractChart.java
private void addTopMenu() { JRadioButtonMenuItem mnuTop5 = new JRadioButtonMenuItem("Top 5"); JRadioButtonMenuItem mnuTop10 = new JRadioButtonMenuItem("Top 10"); mnuTop5.setActionCommand("top.5"); mnuTop5.addActionListener(this); mnuTop5.setSelected(true);/* www .jav a2 s .c om*/ mnuTop10.setActionCommand("top.10"); mnuTop10.addActionListener(this); topGroup.add(mnuTop5); topGroup.add(mnuTop10); JMenu menuTop = new JMenu("Top"); menuTop.add(mnuTop5); menuTop.add(mnuTop10); menu.add(menuTop); }
From source file:com.projity.pm.graphic.network.NetworkPopupMenu.java
/** * Because the styles may change, rebuild the menu each time * *//*from w ww.j a v a2s .c o m*/ protected void init() { removeAll(); final JMenu bars = new JMenu(Messages.getString("Network.Popup.barStylesMenu")); CollectionUtils.forAllDo(interactor.getGraph().getBarStyles().getRows(), new Closure() { public void execute(Object arg0) { BarStyle barStyle = (BarStyle) arg0; BarMenuAction menuAction = new BarMenuAction(barStyle); bars.add(menuAction); } }); add(bars); }
From source file:test.integ.be.fedict.performance.util.PerformanceResultDialog.java
public PerformanceResultDialog(PerformanceResultsData data) { super((Frame) null, "Performance test results"); setSize(1000, 800);//ww w . j a v a 2 s . c o m JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu fileMenu = new JMenu("File"); menuBar.add(fileMenu); JMenuItem savePerformanceMenuItem = new JMenuItem("Save Performance"); fileMenu.add(savePerformanceMenuItem); savePerformanceMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save as PNG..."); int result = fileChooser.showSaveDialog(PerformanceResultDialog.this); if (JFileChooser.APPROVE_OPTION == result) { File file = fileChooser.getSelectedFile(); try { ChartUtilities.saveChartAsPNG(file, performanceChart, 1024, 768); } catch (IOException e) { JOptionPane.showMessageDialog(null, "error saving to file: " + e.getMessage()); } } } }); JMenuItem saveMemoryMenuItem = new JMenuItem("Save Memory"); fileMenu.add(saveMemoryMenuItem); saveMemoryMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { JFileChooser fileChooser = new JFileChooser(); fileChooser.setDialogTitle("Save as PNG..."); int result = fileChooser.showSaveDialog(PerformanceResultDialog.this); if (JFileChooser.APPROVE_OPTION == result) { File file = fileChooser.getSelectedFile(); try { ChartUtilities.saveChartAsPNG(file, memoryChart, 1024, 768); } catch (IOException e) { JOptionPane.showMessageDialog(null, "error saving to file: " + e.getMessage()); } } } }); // memory chart memoryChart = getMemoryChart(data.getIntervalSize(), data.getMemory()); // performance chart performanceChart = getPerformanceChart(data.getIntervalSize(), data.getPerformance(), data.getExpectedRevokedCount()); Container container = getContentPane(); JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); if (null != performanceChart) { splitPane.setTopComponent(new ChartPanel(performanceChart)); } if (null != memoryChart) { splitPane.setBottomComponent(new ChartPanel(memoryChart)); } splitPane.setDividerLocation(getHeight() / 2); splitPane.setDividerSize(1); container.add(splitPane); setVisible(true); }
From source file:edu.ku.brc.af.core.SchemaI18NService.java
/** * Create a Locale menu with all the language locales (no Country or variant). * @return//w w w . jav a 2s . c o m */ public JMenu createLocaleMenu(final ActionListener al) { JMenu menu = new JMenu("Locale"); //$NON-NLS-1$ JMenuItem m = new JMenuItem("Choose Locale"); //$NON-NLS-1$ m.addActionListener(al); menu.add(m); return menu; }