private JSpinner gravitySpinner; private JPanel mainPanel = new JPanel(); mainPanel.setLayout(new BorderLayout()); draw = new DrawingArea(); mainPanel.add(draw, BorderLayout.CENTER); userInt = new JPanel(); mainPanel.add(userInt, BorderLayout.NORTH); b1 = new JButton("Start"); b2 = new JButton("aaa"); b1.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { SwingUtilities.invokeLater(new Runnable() { public void run() { JFrame window = new JFrame("Ball"); window.add(new StartingPoint().getMainPanel()); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.pack(); window.setLocationRelativeTo(null); window.setVisible(true);
final JFrame frame = new JFrame("Nested Layout Example"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); plafComponents.add(plafChooser); plafComponents.add(pack); plafInfos[index].getClassName() ); SwingUtilities.updateComponentTreeUI(frame); if (pack.isSelected()) { frame.pack(); frame.setMinimumSize(frame.getSize()); gui.add(plafComponents, BorderLayout.NORTH); new TitledBorder("GridLayout(0,2,3,3)") ); JButton addNew = new JButton("Add Another Label"); dynamicLabels.add( addNew, BorderLayout.NORTH ); addNew.addActionListener( new ActionListener(){ gui.add( splitPane, BorderLayout.CENTER ); frame.setContentPane(gui); frame.pack(); frame.setLocationRelativeTo(null);
rootPanel = new JPanel(); rootPanel.setLayout(new GridLayoutManager(9, 4, new Insets(5, 5, 0, 0), -1, -1)); final Spacer spacer1 = new Spacer(); rootPanel.add(spacer1, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); final JLabel label1 = new JLabel(); Font label1Font = this.$$$getFont$$$(null, Font.BOLD, 20, label1.getFont()); if (label1Font != null) label1.setFont(label1Font); label1.setText("Miscellaneous Settings"); rootPanel.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final Spacer spacer2 = new Spacer(); rootPanel.add(spacer2, new GridConstraints(0, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0, false)); resetCustomAssociationsButton = new JButton(); resetCustomAssociationsButton.setText("Reset custom associations"); rootPanel.add(resetCustomAssociationsButton, new GridConstraints(7, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false)); final Spacer spacer3 = new Spacer(); rootPanel.add(spacer10, new GridConstraints(6, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false)); alwaysSendRequestsCheckBox = new JCheckBox(); alwaysSendRequestsCheckBox.setMargin(new Insets(2, 2, 2, 2)); alwaysSendRequestsCheckBox.setText("Always send requests"); alwaysSendRequestsCheckBox.setToolTipText("Send requests even if a language plugin already supports it"); rootPanel.add(alwaysSendRequestsCheckBox, new GridConstraints(7, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 1, false));
public synchronized void syntheticUnbind() { boundButton.removePropertyChangeListener("model", this); boundButton.getModel().removeItemListener(this); boundButton = null; }
import java.util.Enumeration; import javax.swing.AbstractButton; import javax.swing.ButtonGroup; public class GroupButtonUtils { public String getSelectedButtonText(ButtonGroup buttonGroup) { for (Enumeration<AbstractButton> buttons = buttonGroup.getElements(); buttons.hasMoreElements();) { AbstractButton button = buttons.nextElement(); if (button.isSelected()) { return button.getText(); } } return null; } }
package experiments; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JOptionPane; public class CreateDialogFromOptionPane { public static void main(final String[] args) { final JFrame parent = new JFrame(); JButton button = new JButton(); button.setText("Click me to show dialog!"); parent.add(button); parent.pack(); parent.setVisible(true); button.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(java.awt.event.ActionEvent evt) { String name = JOptionPane.showInputDialog(parent, "What is your name?", null); } }); } }
JFrame testFrame = new JFrame(); testFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); final LinesComponent comp = new LinesComponent(); comp.setPreferredSize(new Dimension(320, 200)); testFrame.getContentPane().add(comp, BorderLayout.CENTER); JPanel buttonsPanel = new JPanel(); JButton newLineButton = new JButton("New Line"); JButton clearButton = new JButton("Clear"); buttonsPanel.add(newLineButton); buttonsPanel.add(clearButton); testFrame.getContentPane().add(buttonsPanel, BorderLayout.SOUTH); newLineButton.addActionListener(new ActionListener() { clearButton.addActionListener(new ActionListener() { testFrame.pack(); testFrame.setVisible(true);
table.setPreferredScrollableViewportSize(table.getPreferredSize()); restoreButton.addActionListener(new ActionListener() { hideButton.addActionListener(new ActionListener() { deleteButton.addActionListener(new ActionListener() { TableColumn colToDelete = table.getColumnModel().getColumn(table.getColumnCount() - 1); table.removeColumn(colToDelete); table.validate(); colDeleted.push(colToDelete); addButton.setEnabled(true); } else { deleteButton.setEnabled(false); addButton.addActionListener(new ActionListener() { table.validate(); deleteButton.setEnabled(true); } else { addButton.setEnabled(false); JPanel btnPanel = new JPanel(); btnPanel.add(hideButton); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
JFrame frame = new JFrame(); frame.setTitle("Welcome!"); frame.setSize(520, 480); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel heroShotPanel = new JPanel(); JLabel heroShot = new JLabel(heroShotImage); heroShotPanel.add(heroShot); JPanel submitPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); JButton start = new JButton("Start"); start.setToolTipText("Click to use library"); start.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { submitPanel.add(start); frame.getContentPane().add(heroShotPanel, BorderLayout.NORTH); frame.getContentPane().add(submitPanel, BorderLayout.SOUTH); frame.setVisible(true); frame.getRootPane().setDefaultButton(start); start.requestFocus();
JFrame frame = new JFrame("Layout Example"); frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); buttons[i] = new JButton(borderConstraints[i]); borderPanel.add(buttons[i], borderConstraints[i]); contentPane.add(borderPanel); flowPanel = new JPanel(new FlowLayout( buttons[i] = new JButton(Integer.toString(i)); flowPanel.add(buttons[i]); buttons[i] = new JButton(Integer.toString(i)); frame.setContentPane(contentPane); frame.pack(); frame.setLocationByPlatform(true); frame.setVisible(true); swapperButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent ae) {
{"etc", "34", "dir", "Jul 12", "drwxr-xr-x"},}; JTable table = new JTable(data, columnNames); table.setPreferredScrollableViewportSize(table.getPreferredSize()); JScrollPane scrollPane = new JScrollPane(table); final TableColumnHider hider = new TableColumnHider(table); JPanel checkBoxes = new JPanel(); for (int i = 0; i < columnNames.length; i++) { JCheckBox checkBox = new JCheckBox(columnNames[i]); checkBox.setSelected(true); checkBox.addActionListener(new ActionListener() { String columnName = cb.getText(); if (cb.isSelected()) { hider.show(columnName); } else { checkBoxes.add(checkBox); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(scrollPane); frame.getContentPane().add(checkBoxes, BorderLayout.SOUTH); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true);
setLayout(new BorderLayout()); this.panel = new JPanel(); this.panel.setLayout(new FlowLayout()); add(panel, BorderLayout.CENTER); JButton button = new JButton("CLICK HERE"); add(button, BorderLayout.SOUTH); button.addActionListener(this); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(500, 500); setVisible(true); this.panel.add(new JButton("Button")); this.panel.revalidate(); validate();
editorComponent = new JButton(); editorComponent.setBackground(Color.white); editorComponent.setBorderPainted(false); editorComponent.setContentAreaFilled( false ); popup.setLocation(p.x, p.y + editorComponent.getSize().height); popup.show(); fireEditingStopped(); editorComponent.setText( currentText ); return editorComponent; JButton cancel = new JButton("Cancel"); cancel.addActionListener( this ); JButton ok = new JButton("Ok"); ok.setPreferredSize( cancel.getPreferredSize() ); ok.addActionListener( this ); table.getColumnModel().getColumn(1).setCellEditor( popupEditor ); JFrame frame = new JFrame("Popup Editor Test"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add( scrollPane ); frame.pack();
private JButton m_multiplyBtn = new JButton("Multiply"); private JButton m_clearBtn = new JButton("Clear"); JPanel content = new JPanel(); content.setLayout(new FlowLayout()); content.add(new JLabel("Input")); content.add(m_userInputTf); content.add(m_multiplyBtn); content.add(new JLabel("Total")); this.setContentPane(content); this.pack(); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); m_multiplyBtn.addActionListener(mal); m_clearBtn.addActionListener(cal);
button.setText(enabledText); button.setEnabled(true); } else { button.setText(disabledText); button.setEnabled(false); JFrame frame = new JFrame("Convert"); frame.getContentPane().add(new ConvertGui()); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); class ConvertGui extends JPanel { public ConvertGui() { add(new JButton(new Convert("GO", "Working...")));
JPanel digitsPanel = new JPanel(); digitsPanel.setLayout(new GridLayout(4, 3)); int[] digitOrder = new int[] { 7,8,9,4,5,6,1,2,3,0 }; for (int digit : digitOrder) { JButton button = new JButton(Integer.toString(digit)); button.addActionListener(this); digitsPanel.add(button); window.add(digitsPanel, BorderLayout.CENTER); JPanel operatorsPanel = new JPanel(); operatorsPanel.setLayout(new GridLayout(5,1)); String[] operators = new String[] { "+","-","x","/","=" }; for (String operator : operators) { JButton button = new JButton(operator); button.addActionListener(this); operatorsPanel.add(button); window.add(operatorsPanel, BorderLayout.EAST); window.pack(); window.setVisible(true); public void actionPerformed(ActionEvent e) { if (e.getSource() instanceof JButton) { String buttonText = ((JButton)e.getSource()).getText(); if (Character.isDigit(buttonText.charAt(0))) { digitsEntered.append(buttonText.charAt(0));
Runnable r = new Runnable() { public void run() { final JFrame f = new JFrame("Test Screenshot"); InputEvent.CTRL_DOWN_MASK )); screenshot.addActionListener( new ActionListener(){ public void actionPerformed(ActionEvent ae) { BufferedImage img = getScreenShot( f.getContentPane() ); JOptionPane.showMessageDialog( null, JMenuBar mb = new JMenuBar(); mb.add(menu); f.setJMenuBar(mb); f.setContentPane( p ); f.pack(); f.setLocationRelativeTo(null); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.setVisible(true);
final JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel l = new JLabel(); new Thread(t).start(); final JButton b = new JButton("Stop"); b.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) f.getContentPane().setLayout(new BorderLayout()); f.getContentPane().add(l, BorderLayout.CENTER); f.getContentPane().add(b, BorderLayout.SOUTH); f.setLocation(100, 100); f.pack(); f.setVisible(true);
getEngineByExtension("js"); ui = new JPanel(new BorderLayout(2, 2)); controls = new ArrayList<JButton>(); io.setHorizontalAlignment(SwingConstants.TRAILING); io.setFocusable(false); text.add(io); JButton equals = new JButton("="); ui.setBorder(new EmptyBorder(5, 5, 5, 5)); JButton b = new JButton(text); b.setFont(f.deriveFont(f.getSize() * 1.5f)); b.addActionListener(this); b.addKeyListener(this); controls.add(b); String s = button.getText(); if (text.endsWith(s) || (s.equals("=") JButton b = getButton(s); if (b != null) { b.requestFocusInWindow(); b.doClick();
private JFrame frame = new JFrame("sssssssss"); private JButton tip1Null = new JButton(" test button "); final Border compound2; compound2 = BorderFactory.createCompoundBorder(empty, new OldRoundedBorderLine(crl2)); tip1Null.setFont(new Font("Serif", Font.BOLD, 14)); tip1Null.setForeground(Color.darkGray); tip1Null.setPreferredSize(new Dimension(50, 30)); tip1Null.addActionListener(new java.awt.event.ActionListener() { @Override public void actionPerformed(ActionEvent e) { tip1Null.setBorderPainted(true); tip1Null.setFocusPainted(false); tip1Null.setBorder(compound); tip1Null.setHorizontalTextPosition(SwingConstants.CENTER); tip1Null.setVerticalTextPosition(SwingConstants.BOTTOM); tip1Null.setUI(new ModifButtonUI()); tip1Null.getModel().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { paintText(g, b, b.getBounds(), b.getText()); g.setColor(Color.red.brighter()); g.fillRect(0, 0, b.getSize().width, b.getSize().height);