List of usage examples for javax.swing JMenuItem setText
@BeanProperty(preferred = true, visualUpdate = true, description = "The button's text.") public void setText(String text)
From source file:com.projity.menu.MenuManager.java
public void setText(String id, String text) { Collection buttons = toolBarFactory.getButtonsFromId(id); if (buttons != null) { Iterator i = buttons.iterator(); while (i.hasNext()) { AbstractButton button = (AbstractButton) i.next(); if (button != null) button.setToolTipText(text); }//from ww w .j a v a2 s .c o m } JMenuItem menuItem = menuFactory.getMenuItemFromId(id); if (menuItem != null) menuItem.setText(text); }
From source file:cz.lidinsky.editor.Menu.java
protected void setLabel(final JMenuItem menuItem, final String label) { if (label != null) { int mnemonicIndex = label.indexOf('_'); if (mnemonicIndex >= 0) { String text = StringUtils.remove(label, '_'); int key = text.codePointAt(mnemonicIndex); menuItem.setText(text); menuItem.setMnemonic(key);//from w ww . j a va2s .co m } else { menuItem.setText(label); } } }
From source file:com.jidesoft.spring.richclient.docking.JideApplicationLifecycleAdvisor.java
@Override public void onPostStartup() { initializeRepaintManager();//from w w w . j a v a 2 s. c o m if (devOption == false) { JMenuBar menuBar = Application.instance().getActiveWindow().getControl().getJMenuBar(); for (int i = 0; i < menuBar.getMenuCount(); i++) { //TODO:I18N if (menuBar.getMenu(i).getText().equals("Admin")) { menuBar.getMenu(i).setVisible(false); } } } JMenuBar menuBar = Application.instance().getActiveWindow().getControl().getJMenuBar(); for (int i = 0; i < menuBar.getMenuCount(); i++) { // recent games //TODO: I18N if (menuBar.getMenu(i).getText().equals("Game")) { for (int j = 0; j < menuBar.getMenu(i).getItemCount(); j++) { if (menuBar.getMenu(i).getItem(j) != null && menuBar.getMenu(i).getItem(j).getText() != null && menuBar.getMenu(i).getItem(j).getText().equals("Recent Games")) { JMenu menu = (JMenu) menuBar.getMenu(i).getItem(j); RecentGames rg = new RecentGames(); ArrayList<RecentGames.RecentGameInfo> rgis = rg.getRecentGameInfo(); for (RecentGameInfo rgi : rgis) { final RecentGameInfo frgi = rgi; JMenuItem mu = new JMenuItem(); mu.setText("Game " + String.valueOf(rgi.getNumber())); mu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { LoadGame loadGame = new LoadGame(frgi.getFile()); loadGame.execute(); } }); menu.add(mu); } } } } // user guide //TODO:I18N if (menuBar.getMenu(i).getText().equals("Help")) { try { final File f = new File("JOverseerUserGuide.pdf"); if (f.exists()) { //TODO:I18N JMenuItem mi = new JMenuItem("User's Guide"); mi.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { try { Runtime.getRuntime() .exec("rundll32 url.dll,FileProtocolHandler " + f.getAbsolutePath()); } catch (Exception exc) { // do nothing } } }); menuBar.getMenu(i).add(new JSeparator()); menuBar.getMenu(i).add(mi); } } catch (Exception exc) { // do nothing } } } if (JOverseerJIDEClient.cmdLineArgs != null && JOverseerJIDEClient.cmdLineArgs.length == 1 && JOverseerJIDEClient.cmdLineArgs[0].endsWith(".jov")) { String fname = JOverseerJIDEClient.cmdLineArgs[0]; File f = new File(fname); if (f.exists()) { LoadGame lg = new LoadGame(fname); lg.loadGame(); } } }
From source file:gtu._work.etc.GoogleContactUI.java
void googleTableMouseClicked(MouseEvent evt) { try {/*from w w w . j a v a 2 s . c o m*/ JPopupMenuUtil popupUtil = JPopupMenuUtil.newInstance(googleTable).applyEvent(evt); //CHANGE ENCODE popupUtil.addJMenuItem("set encode", new ActionListener() { public void actionPerformed(ActionEvent e) { try { String code = StringUtils.defaultString(JOptionPaneUtil.newInstance().iconPlainMessage() .showInputDialog("input file encode", "ENCODE"), "UTF8"); encode = Charset.forName(code).displayName(); } catch (Exception ex) { JCommonUtil.handleException(ex); } System.err.println("encode : " + encode); } }); //SIMPLE LOAD GOOGLE CSV FILE popupUtil.addJMenuItem("open Google CSV file", new ActionListener() { public void actionPerformed(ActionEvent e) { File file = JFileChooserUtil.newInstance().selectFileOnly().addAcceptFile("csv", ".csv") .showOpenDialog().getApproveSelectedFile(); if (file == null) { errorMessage("file is not correct!"); return; } try { if (file.getName().endsWith(".csv")) { DefaultTableModel model = (DefaultTableModel) googleTable.getModel(); LineNumberReader reader = new LineNumberReader( new InputStreamReader(new FileInputStream(file), GOOGLE_CVS_ENCODE)); for (String line = null; (line = reader.readLine()) != null;) { if (reader.getLineNumber() == 1) { continue; } model.addRow(line.split(",")); } reader.close(); googleTable.setModel(model); JTableUtil.newInstance(googleTable).hiddenAllEmptyColumn(); } } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); //SAVE CSV FILE FOR GOOGLE popupUtil.addJMenuItem("save to Google CVS file", new ActionListener() { public void actionPerformed(ActionEvent e) { File file = JFileChooserUtil.newInstance().selectFileOnly().addAcceptFile(".csv", ".csv") .showSaveDialog().getApproveSelectedFile(); if (file == null) { errorMessage("file is not correct!"); return; } file = FileUtil.getIndicateFileExtension(file, ".csv"); try { BufferedWriter writer = new BufferedWriter( new OutputStreamWriter(new FileOutputStream(file), GOOGLE_CVS_ENCODE)); StringBuilder sb = new StringBuilder(); for (Object title : googleColumns) { sb.append(title + ","); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb); writer.write(sb.toString()); writer.newLine(); DefaultTableModel model = (DefaultTableModel) googleTable.getModel(); for (int row = 0; row < model.getRowCount(); row++) { sb = new StringBuilder(); for (int col = 0; col < model.getColumnCount(); col++) { String colVal = StringUtils.defaultString((String) model.getValueAt(row, col), ""); if (colVal.equalsIgnoreCase("null")) { colVal = ""; } sb.append(colVal + ","); } sb.deleteCharAt(sb.length() - 1); System.out.println(sb); writer.write(sb.toString()); writer.newLine(); } writer.flush(); writer.close(); } catch (Exception ex) { JCommonUtil.handleException(ex); } } }); //PASTE CLIPBOARD popupUtil.addJMenuItem("paste clipboard", new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { JTableUtil.newInstance(googleTable).pasteFromClipboard_multiRowData(true); } }); popupUtil.addJMenuItem("paste clipboard to selected cell", new ActionListener() { public void actionPerformed(ActionEvent paramActionEvent) { JTableUtil.newInstance(googleTable).pasteFromClipboard_singleValueToSelectedCell(); } }); JMenuItem addEmptyRowItem = JTableUtil.newInstance(googleTable).jMenuItem_addRow(false, "add row count?"); addEmptyRowItem.setText("add row"); JMenuItem removeColumnItem = JTableUtil.newInstance(googleTable).jMenuItem_removeColumn(null); removeColumnItem.setText("remove column"); JMenuItem removeRowItem = JTableUtil.newInstance(googleTable).jMenuItem_removeRow(null); removeRowItem.setText("remove row"); JMenuItem removeAllRowItem = JTableUtil.newInstance(googleTable) .jMenuItem_removeAllRow("remove all row?"); removeAllRowItem.setText("remove all row"); JMenuItem clearSelectedCellItem = JTableUtil.newInstance(googleTable) .jMenuItem_clearSelectedCell("are you sure clear selected area?"); clearSelectedCellItem.setText("clear selected area"); popupUtil.addJMenuItem(addEmptyRowItem, removeColumnItem, removeRowItem, removeAllRowItem, clearSelectedCellItem); popupUtil.show(); } catch (Exception ex) { JCommonUtil.handleException(ex); } }
From source file:TextCutPaste.java
/** * Create an Edit menu to support cut/copy/paste. *///from w w w. j a v a 2s . c om 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:DragColorTextFieldDemo.java
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);//from w w w .j a v a 2 s . c o m 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:biz.wolschon.finance.jgnucash.panels.WritableTransactionsPanel.java
/** * @return the context-menu for the transactionTable. * @see #getTransactionTable()/*w ww . j av a 2s . c o m*/ */ private Component getTransactionTableContextMenu() { if (myContextMenu == null) { myContextMenu = new JPopupMenu(); PluginManager manager = getPluginManager(); // if we are configured for the plugin-api if (manager != null) { ExtensionPoint toolExtPoint = manager.getRegistry().getExtensionPoint(getPluginDescriptor().getId(), "TransactionMenuAction"); for (Iterator<Extension> it = toolExtPoint.getConnectedExtensions().iterator(); it.hasNext();) { Extension ext = it.next(); String pluginName = "unknown"; try { pluginName = ext.getParameter("name").valueAsString(); JMenuItem newMenuItem = new JMenuItem(); newMenuItem.putClientProperty("extension", ext); newMenuItem.setText(pluginName); newMenuItem.addActionListener(new TransactionMenuActionMenuAction(ext, pluginName)); myContextMenu.add(newMenuItem); } catch (Exception e) { LOG.log(Level.SEVERE, "cannot load TransactionMenuAction-Plugin '" + pluginName + "'", e); JOptionPane.showMessageDialog(this, "Error", "Cannot load TransactionMenuAction-Plugin '" + pluginName + "'", JOptionPane.ERROR_MESSAGE); } } } } return myContextMenu; }
From source file:gg.pistol.sweeper.gui.component.DecoratedPanel.java
/** * Helper method to add a contextual menu on a text component that will allow for Copy & Select All text actions. *//* w w w. ja va 2 s .c om*/ protected void addCopyMenu(final JTextComponent component) { Preconditions.checkNotNull(component); if (!component.isEditable()) { component.setCursor(new Cursor(Cursor.TEXT_CURSOR)); } final JPopupMenu contextMenu = new JPopupMenu(); JMenuItem copy = new JMenuItem(component.getActionMap().get(DefaultEditorKit.copyAction)); copy.setText(i18n.getString(I18n.TEXT_COPY_ID)); contextMenu.add(copy); contextMenu.addSeparator(); JMenuItem selectAll = new JMenuItem(component.getActionMap().get(DefaultEditorKit.selectAllAction)); selectAll.setText(i18n.getString(I18n.TEXT_SELECT_ALL_ID)); contextMenu.add(selectAll); component.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { if (e.getButton() == MouseEvent.BUTTON3) { contextMenu.show(component, e.getX(), e.getY()); } } }); }
From source file:gtu._work.ui.SaveFileToPropertiesUI.java
private void initGUI() { try {// ww w. j av a2 s. co m BorderLayout thisLayout = new BorderLayout(); setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); getContentPane().setLayout(thisLayout); this.setTitle("save file to properties"); { jTabbedPane1 = new JTabbedPane(); getContentPane().add(jTabbedPane1, BorderLayout.CENTER); { jPanel1 = new JPanel(); BorderLayout jPanel1Layout = new BorderLayout(); jPanel1.setLayout(jPanel1Layout); jTabbedPane1.addTab("load", null, jPanel1, null); { jScrollPane2 = new JScrollPane(); jPanel1.add(jScrollPane2, BorderLayout.CENTER); { textArea = new JTextArea(); jScrollPane2.setViewportView(textArea); } } { jPanel2 = new JPanel(); jPanel1.add(jPanel2, BorderLayout.NORTH); jPanel2.setPreferredSize(new java.awt.Dimension(400, 40)); { addPropsFile = new JButton(); jPanel2.add(addPropsFile); addPropsFile.setText("load properties from file"); addPropsFile.setPreferredSize(new java.awt.Dimension(234, 30)); addPropsFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { props.load(new InputStreamReader(new FileInputStream(file), (String) openUnknowFilecharSet.getSelectedItem())); reloadPropertiesTable(); } catch (Exception e) { JCommonUtil.handleException(e); } } }); } { openFile = new JButton(); jPanel2.add(openFile); openFile.setText("open unknow file"); openFile.setPreferredSize(new java.awt.Dimension(204, 30)); openFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showOpenDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { String encode = (String) openUnknowFilecharSet.getSelectedItem(); BufferedReader reader = new BufferedReader( new InputStreamReader(new FileInputStream(file), encode)); StringBuilder sb = new StringBuilder(); for (String line = null; (line = reader.readLine()) != null;) { sb.append(line + "\n"); } reader.close(); textArea.setText(textArea.getText() + "\n" + sb); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } { ComboBoxModel openUnknowFilecharSetModel = new DefaultComboBoxModel( new String[] { "BIG5", "UTF8" }); openUnknowFilecharSet = new JComboBox(); jPanel2.add(openUnknowFilecharSet); openUnknowFilecharSet.setModel(openUnknowFilecharSetModel); openUnknowFilecharSet.setPreferredSize(new java.awt.Dimension(73, 24)); } { appendTextAreaToProps = new JButton(); jPanel2.add(appendTextAreaToProps); appendTextAreaToProps.setText("append textarea to properties"); appendTextAreaToProps.setPreferredSize(new java.awt.Dimension(227, 30)); appendTextAreaToProps.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { if (StringUtils.isBlank(textArea.getText())) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("textArea is empty", "ERROR"); return; } try { BufferedReader reader = new BufferedReader( new StringReader(textArea.getText())); int pos = -1; String key = null; String value = null; for (String line = null; (line = reader.readLine()) != null;) { if ((pos = line.lastIndexOf("=")) != -1) { key = line.substring(0, pos); value = line.substring(pos + 1); props.put(key, value); } } reader.close(); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("append success!", "SUCCESS"); reloadPropertiesTable(); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } } } { jPanel3 = new JPanel(); BorderLayout jPanel3Layout = new BorderLayout(); jPanel3.setLayout(jPanel3Layout); jTabbedPane1.addTab("props edit", null, jPanel3, null); { jScrollPane1 = new JScrollPane(); jPanel3.add(jScrollPane1, BorderLayout.CENTER); jScrollPane1.setPreferredSize(new java.awt.Dimension(629, 361)); { TableModel propsTableModel = new DefaultTableModel(); propsTable = new JTable(); jScrollPane1.setViewportView(propsTable); propsTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent evt) { if (propsTable.getRowCount() == 0) { return; } int rowPos = JTableUtil.newInstance(propsTable).getSelectedRow(); Object key = propsTable.getValueAt(rowPos, 0); Object value = propsTable.getValueAt(rowPos, 1); JMenuItem insertRowItem = JTableUtil.newInstance(propsTable) .jMenuItem_addRow(false, null); insertRowItem.setText("inert row..."); String rowInfo = "delete row : [" + key + "] = [" + value + "]"; JMenuItem delRowItem = JTableUtil.newInstance(propsTable) .jMenuItem_removeRow("are you sure remove row : \n" + rowInfo); delRowItem.setText(rowInfo); JPopupMenuUtil.newInstance(propsTable).applyEvent(evt) .addJMenuItem(insertRowItem, delRowItem).show(); } }); propsTable.setModel(propsTableModel); JTableUtil.defaultSetting(propsTable); } } { jPanel4 = new JPanel(); jPanel3.add(jPanel4, BorderLayout.SOUTH); jPanel4.setPreferredSize(new java.awt.Dimension(629, 45)); { clearProps = new JButton(); jPanel4.add(clearProps); clearProps.setText("clear properties"); clearProps.setPreferredSize(new java.awt.Dimension(182, 36)); clearProps.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { props.clear(); reloadPropertiesTable(); } }); } { savePropsToFile = new JButton(); jPanel4.add(savePropsToFile); savePropsToFile.setText("save properties to file"); savePropsToFile.setPreferredSize(new java.awt.Dimension(182, 36)); savePropsToFile.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { File file = JFileChooserUtil.newInstance().selectFileOnly().showSaveDialog() .getApproveSelectedFile(); if (file == null) { JOptionPaneUtil.newInstance().iconErrorMessage() .showMessageDialog("file is not correct!", "ERROR"); return; } try { props.clear(); DefaultTableModel model = (DefaultTableModel) propsTable.getModel(); Object key = null; Object value = null; for (int ii = 0; ii < model.getRowCount(); ii++) { key = model.getValueAt(ii, 0); value = model.getValueAt(ii, 1); props.put(key, value); } props.store(new FileOutputStream(file), SaveFileToPropertiesUI.class.getSimpleName()); JOptionPaneUtil.newInstance().iconInformationMessage() .showMessageDialog("save completed!\n" + file, "SUCCESS"); } catch (IOException e) { JCommonUtil.handleException(e); } } }); } } } } pack(); this.setSize(798, 505); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.sbml.bargraph.MainWindow.java
/** * Set up menus when running under Windows. *//*from www . ja v a 2 s . c o m*/ public void registerForEvents() { Log.note("Setting up the Windows menus."); JMenuItem fileExitItem = new JMenuItem(); fileExitItem .setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_W, shortcutKeyMask)); fileExitItem.setMnemonic(java.awt.event.KeyEvent.VK_C); fileExitItem.setText("Exit"); fileExitItem.setToolTipText("Exit application"); fileExitItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { quit(); } }); fileMenu.addSeparator(); fileMenu.add(fileExitItem); JMenu helpMenu = new JMenu(); helpMenu.setText("Help"); JMenuItem aboutMenuItem = new JMenuItem(); aboutMenuItem.setText("About " + Config.APP_NAME); aboutMenuItem.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { about(); } }); helpMenu.add(aboutMenuItem); menuBar.add(helpMenu); }