List of usage examples for javax.swing JButton setMnemonic
@BeanProperty(visualUpdate = true, description = "the keyboard character mnemonic") public void setMnemonic(int mnemonic)
From source file:SynthApplication.java
public Component createComponents() { JButton button = new JButton("I'm a Swing button!"); button.setMnemonic(KeyEvent.VK_I); button.addActionListener(this); label.setLabelFor(button);/* w w w. jav a 2s .co m*/ /* * An easy way to put space between a top-level container * and its contents is to put the contents in a JPanel * that has an "empty" border. */ JPanel pane = new JPanel(new GridLayout(0, 1)); pane.add(button); pane.add(label); pane.setBorder(BorderFactory.createEmptyBorder(30, //top 30, //left 10, //bottom 30) //right ); return pane; }
From source file:SimplelookandfeelExample.java
public SimplelookandfeelExample() { // Create the buttons. JButton button = new JButton("Hello, world"); button.setMnemonic('h'); //for looks only; button does nada metalButton = new JRadioButton(metal); metalButton.setMnemonic('o'); metalButton.setActionCommand(metalClassName); motifButton = new JRadioButton(motif); motifButton.setMnemonic('m'); motifButton.setActionCommand(motifClassName); windowsButton = new JRadioButton(windows); windowsButton.setMnemonic('w'); windowsButton.setActionCommand(windowsClassName); // Group the radio buttons. ButtonGroup group = new ButtonGroup(); group.add(metalButton);//from w w w. jav a 2s .c o m group.add(motifButton); group.add(windowsButton); // Register a listener for the radio buttons. RadioListener myListener = new RadioListener(); metalButton.addActionListener(myListener); motifButton.addActionListener(myListener); windowsButton.addActionListener(myListener); add(button); add(metalButton); add(motifButton); add(windowsButton); }
From source file:HtmlDemo.java
public HtmlDemo() { setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); String initialText = "<html>\n" + "Color and font test:\n" + "<ul>\n" + "<li><font color=red>red</font>\n" + "<li><font color=blue>blue</font>\n" + "<li><font color=green>green</font>\n" + "<li><font size=-2>small</font>\n" + "<li><font size=+2>large</font>\n" + "<li><i>italic</i>\n" + "<li><b>bold</b>\n" + "</ul>\n"; htmlTextArea = new JTextArea(10, 20); htmlTextArea.setText(initialText);/*w w w. j a va 2 s . com*/ JScrollPane scrollPane = new JScrollPane(htmlTextArea); JButton changeTheLabel = new JButton("Change the label"); changeTheLabel.setMnemonic(KeyEvent.VK_C); changeTheLabel.setAlignmentX(Component.CENTER_ALIGNMENT); changeTheLabel.addActionListener(this); theLabel = new JLabel(initialText) { public Dimension getPreferredSize() { return new Dimension(200, 200); } public Dimension getMinimumSize() { return new Dimension(200, 200); } public Dimension getMaximumSize() { return new Dimension(200, 200); } }; theLabel.setVerticalAlignment(SwingConstants.CENTER); theLabel.setHorizontalAlignment(SwingConstants.CENTER); JPanel leftPanel = new JPanel(); leftPanel.setLayout(new BoxLayout(leftPanel, BoxLayout.PAGE_AXIS)); leftPanel.setBorder(BorderFactory.createCompoundBorder( BorderFactory.createTitledBorder("Edit the HTML, then click the button"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); leftPanel.add(scrollPane); leftPanel.add(Box.createRigidArea(new Dimension(0, 10))); leftPanel.add(changeTheLabel); JPanel rightPanel = new JPanel(); rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.PAGE_AXIS)); rightPanel .setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder("A label with HTML"), BorderFactory.createEmptyBorder(10, 10, 10, 10))); rightPanel.add(theLabel); setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); add(leftPanel); add(Box.createRigidArea(new Dimension(10, 0))); add(rightPanel); }
From source file:SampleButton.java
public SampleButton() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); JButton b = new JButton("Test"); b.setHorizontalTextPosition(SwingConstants.LEFT); b.setIcon(new ImageIcon("r.gif")); b.setRolloverIcon(new ImageIcon("b.gif")); b.setRolloverEnabled(true);// w w w. j a v a 2s.c om b.setMnemonic('t'); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("Button pressed"); } }); p.add(b); getContentPane().add(p); pack(); }
From source file:de.atomfrede.tools.evalutation.ui.ExceptionDialog.java
@SuppressWarnings("serial") @Override// w w w.j a va2s . c om public ButtonPanel createButtonPanel() { ButtonPanel buttonPanel = new ButtonPanel(); JButton closeButton = new JButton(); JButton detailButton = new JButton(); detailButton.setMnemonic('D'); closeButton.setName(OK); buttonPanel.addButton(closeButton, ButtonPanel.AFFIRMATIVE_BUTTON); buttonPanel.addButton(detailButton, ButtonPanel.OTHER_BUTTON); closeButton.setAction(new AbstractAction("Close") { @Override public void actionPerformed(ActionEvent e) { setDialogResult(RESULT_AFFIRMED); setVisible(false); dispose(); } }); detailButton.setAction(new AbstractAction("Details >>") { @Override public void actionPerformed(ActionEvent e) { if (_detailsPanel.isVisible()) { _detailsPanel.setVisible(false); putValue(Action.NAME, "Details <<"); pack(); } else { _detailsPanel.setVisible(true); putValue(Action.NAME, "<< Details"); pack(); } } }); setDefaultCancelAction(closeButton.getAction()); setDefaultAction(closeButton.getAction()); getRootPane().setDefaultButton(closeButton); buttonPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); buttonPanel.setSizeConstraint(ButtonPanel.NO_LESS_THAN); return buttonPanel; }
From source file:LookAndFeelDemo.java
public Component createComponents() { JButton button = new JButton("I'm a Swing button!"); button.setMnemonic(KeyEvent.VK_I); button.addActionListener(this); label.setLabelFor(button);/* w w w . j av a2s . co m*/ /* * An easy way to put space between a top-level container and its contents * is to put the contents in a JPanel that has an "empty" border. */ JPanel pane = new JPanel(new GridLayout(0, 1)); pane.add(button); pane.add(label); pane.setBorder(BorderFactory.createEmptyBorder(30, // top 30, // left 10, // bottom 30) // right ); return pane; }
From source file:ButtonScroll.java
protected JButton createButton(String name, char mnemonics) { JButton btn = new JButton(name); btn.setToolTipText("Move " + name); btn.setBorderPainted(false);/* w w w . ja v a 2s. c o m*/ btn.setMargin(new Insets(0, 0, 0, 0)); btn.setContentAreaFilled(false); btn.setMnemonic(mnemonics); return btn; }
From source file:ExpenseReport.java
public ExpenseReport() { super("Expense Report"); setSize(570, 200);// w ww.jav a2 s .com m_data = new ExpenseReportData(this); m_table = new JTable(); m_table.setAutoCreateColumnsFromModel(false); m_table.setModel(m_data); m_table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); for (int k = 0; k < ExpenseReportData.m_columns.length; k++) { TableCellRenderer renderer; if (k == ExpenseReportData.COL_APPROVED) renderer = new CheckCellRenderer(); else { DefaultTableCellRenderer textRenderer = new DefaultTableCellRenderer(); textRenderer.setHorizontalAlignment(ExpenseReportData.m_columns[k].m_alignment); renderer = textRenderer; } TableCellEditor editor; if (k == ExpenseReportData.COL_CATEGORY) editor = new DefaultCellEditor(new JComboBox(ExpenseReportData.CATEGORIES)); else if (k == ExpenseReportData.COL_APPROVED) editor = new DefaultCellEditor(new JCheckBox()); else editor = new DefaultCellEditor(new JTextField()); TableColumn column = new TableColumn(k, ExpenseReportData.m_columns[k].m_width, renderer, editor); m_table.addColumn(column); } JTableHeader header = m_table.getTableHeader(); header.setUpdateTableInRealTime(false); JScrollPane ps = new JScrollPane(); ps.setSize(550, 150); ps.getViewport().add(m_table); getContentPane().add(ps, BorderLayout.CENTER); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); ImageIcon penny = new ImageIcon("penny.gif"); m_title = new JLabel("Total: $", penny, JButton.LEFT); m_title.setForeground(Color.black); m_title.setAlignmentY(0.5f); p.add(m_title); p.add(Box.createHorizontalGlue()); JButton bt = new JButton("Insert before"); bt.setMnemonic('b'); bt.setAlignmentY(0.5f); ActionListener lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row); m_table.tableChanged( new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Insert after"); bt.setMnemonic('a'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); m_data.insert(row + 1); m_table.tableChanged(new TableModelEvent(m_data, row + 1, row + 1, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); } }; bt.addActionListener(lst); p.add(bt); bt = new JButton("Delete row"); bt.setMnemonic('d'); bt.setAlignmentY(0.5f); lst = new ActionListener() { public void actionPerformed(ActionEvent e) { int row = m_table.getSelectedRow(); if (m_data.delete(row)) { m_table.tableChanged(new TableModelEvent(m_data, row, row, TableModelEvent.ALL_COLUMNS, TableModelEvent.INSERT)); m_table.repaint(); calcTotal(); } } }; bt.addActionListener(lst); p.add(bt); getContentPane().add(p, BorderLayout.SOUTH); calcTotal(); WindowListener wndCloser = new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }; addWindowListener(wndCloser); setVisible(true); }
From source file:org.obiba.onyx.jade.instrument.summitdoppler.VantageABIInstrumentRunner.java
/** * Build action buttons sub panel//w w w . j a v a 2s . co m */ protected JPanel buildActionButtonSubPanel() { // Add the action buttons sub panel. JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); JButton cancelButton = new JButton(resourceBundle.getString("Cancel")); cancelButton.setMnemonic('A'); cancelButton.setToolTipText(resourceBundle.getString("ToolTip.Cancel_measurement")); panel.add(Box.createHorizontalGlue()); panel.add(saveButton); panel.add(Box.createRigidArea(new Dimension(10, 0))); panel.add(cancelButton); // Save button listener. saveButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sendOutputToServer(); } }); // Cancel button listener. cancelButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { confirmOnExit(); } }); panel.setAlignmentX(Component.LEFT_ALIGNMENT); return (panel); }
From source file:org.obiba.onyx.jade.instrument.summitdoppler.VantageABIInstrumentRunner.java
protected JPanel buildFileSelectionSubPanel() { final JPanel panel = new JPanel(); panel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.add(Box.createVerticalGlue()); JButton openButton = new JButton(resourceBundle.getString("Select_file")); openButton.setMnemonic('O'); openButton.setToolTipText(resourceBundle.getString("ToolTip.Select_file")); panel.add(openButton);/*from w w w.ja v a2s. co m*/ panel.add(Box.createRigidArea(new Dimension(10, 10))); JLabel fileLabel = new ABIFileLabel(); panel.add(fileLabel); // Open button listener. openButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { int returnVal = fileChooser.showOpenDialog(appWindow); if (returnVal == JFileChooser.APPROVE_OPTION) { abiFile = fileChooser.getSelectedFile(); panel.repaint(); saveButton.setEnabled(true); } } }); panel.setAlignmentX(Component.LEFT_ALIGNMENT); return panel; }