List of usage examples for javax.swing JPopupMenu JPopupMenu
public JPopupMenu()
JPopupMenu
without an "invoker". From source file:Main.java
/** * Swing menus are looking pretty bad on Linux when the GTK LaF is used (See * bug #6925412). It will most likely never be fixed anytime soon so this * method provides a workaround for it. It uses reflection to change the GTK * style objects of Swing so popup menu borders have a minimum thickness of * 1 and menu separators have a minimum vertical thickness of 1. *//*from ww w. jav a2 s.c om*/ public static void installGtkPopupBugWorkaround() { // Get current look-and-feel implementation class LookAndFeel laf = UIManager.getLookAndFeel(); Class<?> lafClass = laf.getClass(); // Do nothing when not using the problematic LaF if (!lafClass.getName().equals("com.sun.java.swing.plaf.gtk.GTKLookAndFeel")) return; // We do reflection from here on. Failure is silently ignored. The // workaround is simply not installed when something goes wrong here try { // Access the GTK style factory Field field = lafClass.getDeclaredField("styleFactory"); boolean accessible = field.isAccessible(); field.setAccessible(true); Object styleFactory = field.get(laf); field.setAccessible(accessible); // Fix the horizontal and vertical thickness of popup menu style Object style = getGtkStyle(styleFactory, new JPopupMenu(), "POPUP_MENU"); fixGtkThickness(style, "yThickness"); fixGtkThickness(style, "xThickness"); // Fix the vertical thickness of the popup menu separator style style = getGtkStyle(styleFactory, new JSeparator(), "POPUP_MENU_SEPARATOR"); fixGtkThickness(style, "yThickness"); } catch (Exception e) { // Silently ignored. Workaround can't be applied. } }
From source file:MenuElementExample.java
public MenuElementExample() { popup = new JPopupMenu(); slider = new SliderMenuItem(); popup.add(slider);/*from w w w. j a v a 2s . co m*/ popup.add(new JSeparator()); JMenuItem ticks = new JCheckBoxMenuItem("Slider Tick Marks"); ticks.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { slider.setPaintTicks(!slider.getPaintTicks()); } }); JMenuItem labels = new JCheckBoxMenuItem("Slider Labels"); labels.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { slider.setPaintLabels(!slider.getPaintLabels()); } }); popup.add(ticks); popup.add(labels); popup.addPopupMenuListener(new PopupPrintListener()); addMouseListener(new MousePopupListener()); }
From source file:Main.java
protected void showMenu(int x, int y) { JPopupMenu popup = new JPopupMenu(); JMenuItem mi = new JMenuItem("Delete"); TreePath path = tree.getSelectionPath(); Object node = path.getLastPathComponent(); if (node == tree.getModel().getRoot()) { mi.setEnabled(false);//from ww w .j av a 2 s. c o m } popup.add(mi); mi.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { deleteSelectedItems(); } }); popup.show(tree, x, y); }
From source file:com.mirth.connect.client.ui.components.MirthIconTextField.java
public MirthIconTextField(ImageIcon icon) { setIcon(icon);//from www. j a va 2 s. c o m addMouseListener(new MouseAdapter() { @Override public void mouseClicked(MouseEvent evt) { if (isIconActive(evt) && iconPopupMenuComponent != null) { JPopupMenu iconPopupMenu = new JPopupMenu(); iconPopupMenu.insert(iconPopupMenuComponent, 0); iconPopupMenu.show(evt.getComponent(), evt.getX(), evt.getY()); } } }); addMouseMotionListener(new MouseMotionAdapter() { @Override public void mouseMoved(MouseEvent evt) { int cursorType = getCursor().getType(); if (isIconActive(evt)) { if (StringUtils.isNotBlank(alternateToolTipText)) { MirthIconTextField.super.setToolTipText(alternateToolTipText); } if (iconPopupMenuComponent != null) { if (cursorType != Cursor.HAND_CURSOR) { setCursor(new Cursor(Cursor.HAND_CURSOR)); } } else { if (cursorType != Cursor.DEFAULT_CURSOR) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); } } } else { if (StringUtils.isNotBlank(alternateToolTipText)) { MirthIconTextField.super.setToolTipText(originalToolTipText); } if (cursorType != Cursor.TEXT_CURSOR) { setCursor(new Cursor(Cursor.TEXT_CURSOR)); } } } }); }
From source file:Main.java
private void myPopupEvent(MouseEvent e) { int x = e.getX(); int y = e.getY(); JTree tree = (JTree) e.getSource(); TreePath path = tree.getPathForLocation(x, y); if (path == null) return;/* w ww . ja v a2s . c o m*/ DefaultMutableTreeNode rightClickedNode = (DefaultMutableTreeNode) path.getLastPathComponent(); TreePath[] selectionPaths = tree.getSelectionPaths(); boolean isSelected = false; if (selectionPaths != null) { for (TreePath selectionPath : selectionPaths) { if (selectionPath.equals(path)) { isSelected = true; } } } if (!isSelected) { tree.setSelectionPath(path); } if (rightClickedNode.isLeaf()) { JPopupMenu popup = new JPopupMenu(); final JMenuItem refreshMenuItem = new JMenuItem("refresh"); refreshMenuItem.addActionListener(ev -> System.out.println("refresh!")); popup.add(refreshMenuItem); popup.show(tree, x, y); } }
From source file:Interface.Teste.java
public void criacao() { DefaultCategoryDataset ds = new DefaultCategoryDataset(); ds.addValue(40.5, "maximo", "dia 1"); ds.addValue(38.2, "maximo", "dia 2"); ds.addValue(37.3, "maximo", "dia 3"); ds.addValue(31.5, "maximo", "dia 4"); ds.addValue(35.7, "maximo", "dia 5"); ds.addValue(42.5, "maximo", "dia 6"); // cria o grfico JFreeChart grafico = ChartFactory.createLineChart("Meu Grafico", "Dia", "Valor", ds, PlotOrientation.VERTICAL, true, true, false); try {/* w w w. j a v a 2 s. c o m*/ OutputStream arquivo = new FileOutputStream("grafico.png"); ChartUtilities.writeChartAsPNG(arquivo, grafico, 550, 400); arquivo.close(); } catch (Exception e) { e.printStackTrace(); } JPopupMenu pop = new JPopupMenu(); pop.add(new JMenuItem("1")); pop.add(new JMenuItem("2")); pop.add(new JMenuItem("3")); pop.add(new JMenuItem("4")); JPanel painel = new JPanel(); JButton botao = new JButton("teste"); JCalendar cal = new JCalendar(); botao.add(pop); painel.add(cal); painel.add(new ChartPanel(grafico)); //Calendar c = cal.getDate(); Date data = cal.getDate(); int dia = data.getDay(); System.out.println("" + dia); add(painel); }
From source file:coolmap.application.widget.impl.console.WidgetConsole.java
public WidgetConsole() { super("Console", W_DATA, L_DATAPORT, UI.getImageIcon("console"), "Displays console information"); getContentPane().setLayout(new BorderLayout()); getContentPane().add(_container, BorderLayout.CENTER); _container.setLayout(new BorderLayout()); _container.add(new JScrollPane(consolePane), BorderLayout.CENTER); ///*from ww w. j a va 2 s . c o m*/ consolePane.setFont(UI.fontMono.deriveFont(12f)); consolePane.setBackground(new Color(255, 255, 204)); // for (int i = 0; i < 100; i++) { // logError("abcdefgh\n"); // logInfo("ABCDEFGH\n"); // log("DEFGHIJKL\n"); // } JPopupMenu popupMenu = new JPopupMenu(); consolePane.setComponentPopupMenu(popupMenu); JMenuItem item = new JMenuItem("Clear", UI.getImageIcon("trashBin")); item.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { consolePane.setText(""); } }); popupMenu.add(item); }
From source file:grafix.telas.componentes.GrafixChartMouseListener.java
private void criarPopupMenu() { popup = new JPopupMenu(); JMenuItem menuItem;/*ww w. j ava 2 s .c o m*/ menuItem = new JMenuItem("Configurar janela..."); menuItem.setIcon(new javax.swing.ImageIcon(ConfiguracoesGrafix.PASTA_ICONES + "config.gif")); menuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { abrirFormConfiguracoes(-1); } }); popup.add(menuItem); menuItem = new JMenuItem("Configurar grfico..."); menuItem.setIcon(new javax.swing.ImageIcon(ConfiguracoesGrafix.PASTA_ICONES + "configurar3.gif")); menuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { abrirFormConfiguracoes(plotClicado); } }); popup.add(menuItem); menuItem = new JMenuItem("ndices..."); menuItem.setIcon(new javax.swing.ImageIcon(ConfiguracoesGrafix.PASTA_ICONES + "indices.gif")); menuItem.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { abrirFormIndices(plotClicado); } }); popup.add(menuItem); }
From source file:FileTree2.java
public FileTree2() { super("Directories Tree [Popup Menus]"); setSize(400, 300);//w w w.ja va 2s . c om DefaultMutableTreeNode top = new DefaultMutableTreeNode(new IconData(ICON_COMPUTER, null, "Computer")); DefaultMutableTreeNode node; File[] roots = File.listRoots(); for (int k = 0; k < roots.length; k++) { node = new DefaultMutableTreeNode(new IconData(ICON_DISK, null, new FileNode(roots[k]))); top.add(node); node.add(new DefaultMutableTreeNode(new Boolean(true))); } m_model = new DefaultTreeModel(top); m_tree = new JTree(m_model); m_tree.putClientProperty("JTree.lineStyle", "Angled"); TreeCellRenderer renderer = new IconCellRenderer(); m_tree.setCellRenderer(renderer); m_tree.addTreeExpansionListener(new DirExpansionListener()); m_tree.addTreeSelectionListener(new DirSelectionListener()); m_tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); m_tree.setShowsRootHandles(true); m_tree.setEditable(false); JScrollPane s = new JScrollPane(); s.getViewport().add(m_tree); getContentPane().add(s, BorderLayout.CENTER); m_display = new JTextField(); m_display.setEditable(false); getContentPane().add(m_display, BorderLayout.NORTH); // NEW m_popup = new JPopupMenu(); m_action = new AbstractAction() { public void actionPerformed(ActionEvent e) { if (m_clickedPath == null) return; if (m_tree.isExpanded(m_clickedPath)) m_tree.collapsePath(m_clickedPath); else m_tree.expandPath(m_clickedPath); } }; m_popup.add(m_action); m_popup.addSeparator(); Action a1 = new AbstractAction("Delete") { public void actionPerformed(ActionEvent e) { m_tree.repaint(); JOptionPane.showMessageDialog(FileTree2.this, "Delete option is not implemented", "Info", JOptionPane.INFORMATION_MESSAGE); } }; m_popup.add(a1); Action a2 = new AbstractAction("Rename") { public void actionPerformed(ActionEvent e) { m_tree.repaint(); JOptionPane.showMessageDialog(FileTree2.this, "Rename option is not implemented", "Info", JOptionPane.INFORMATION_MESSAGE); } }; m_popup.add(a2); m_tree.add(m_popup); m_tree.addMouseListener(new PopupTrigger()); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:net.sf.firemox.stack.EventManager.java
/** * Create an instance of MEventManager by reading a file * /*w ww .j ava 2 s .c o m*/ * @since 0.31 graphical representation of phases for both players */ public static void init() { MPhase.optionsMenu = new JPopupMenu(); JCheckBoxMenuItem item = new JCheckBoxMenuItem(LanguageManager.getString("breakpoint"), new javax.swing.ImageIcon(IdConst.IMAGES_DIR + "breakpoint.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("breakpoint.tooltip")); item.setMnemonic('b'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setBreakpoint(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhase"), UIHelper.getIcon("skipall1.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhase.tooltip")); item.setMnemonic('l'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipAll(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseOnce"), UIHelper.getIcon("skipall2.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseOnce.tooltip") + "<br><br>" + MagicUIComponents.HTML_ICON_TIP + LanguageManager.getString("skipPhaseOnceTTtip")); item.setMnemonic('o'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipAllTmp(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseMedium"), UIHelper.getIcon("skipallm2.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseMedium.tooltip") + "<br>" + MagicUIComponents.HTML_ICON_WARNING + LanguageManager.getString("skipPhaseAllTTwarn")); item.setMnemonic('m'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipMedium(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseMediumOnce"), UIHelper.getIcon("skipallm.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseMediumOnce.tooltip") + "<br>" + MagicUIComponents.HTML_ICON_WARNING + LanguageManager.getString("skipPhaseAllTTwarn")); item.setMnemonic('p'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipMediumTmp(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseAll"), UIHelper.getIcon("skipall3.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseAll.tooltip") + "<br>" + MagicUIComponents.HTML_ICON_WARNING + LanguageManager.getString("skipPhaseAllTTwarn")); item.setMnemonic('u'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipAllVery(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); item = new JCheckBoxMenuItem(LanguageManager.getString("skipPhaseAllOnce"), UIHelper.getIcon("skipall4.gif")); item.setFont(MToolKit.defaultFont); item.setToolTipText("<html>" + LanguageManager.getString("skipPhaseAllOnce.tooltip") + "<br>" + MagicUIComponents.HTML_ICON_WARNING + LanguageManager.getString("skipPhaseAllTTwarn")); item.setMnemonic('t'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { MPhase.triggerPhase.setSkipAllVeryTmp(((JCheckBoxMenuItem) evt.getSource()).isSelected()); MPhase.triggerPhase.repaint(); } }); MPhase.optionsMenu.add(item); }