Search in sources :

Example 46 with JFormattedTextField

use of javax.swing.JFormattedTextField in project pcgen by PCGen.

the class Utils method buildIntegerFieldWithSlider.

/**
	 *
	 * <p>
	 * Builds a formatted text field with specified min and max, and attaches
	 * the slider to it via listeners. The text field gets it's min and max from
	 * the slider.
	 * </p>
	 *
	 * @param matchingSlider
	 * @return JFormattedTextField
	 */
public static JFormattedTextField buildIntegerFieldWithSlider(final JSlider matchingSlider) {
    final JFormattedTextField returnValue = buildIntegerField(matchingSlider.getMinimum(), matchingSlider.getMaximum());
    returnValue.addPropertyChangeListener(new PropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if ("value".equals(evt.getPropertyName())) {
                Number value = (Number) evt.getNewValue();
                if (value != null) {
                    matchingSlider.setValue(value.intValue());
                }
            }
        }
    });
    matchingSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            int value = source.getValue();
            if (!source.getValueIsAdjusting()) {
                //done adjusting
                //update ftf value
                returnValue.setValue(value);
            } else {
                //value is adjusting; just set the text
                returnValue.setText(String.valueOf(value));
            }
        }
    });
    return returnValue;
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeEvent(javax.swing.event.ChangeEvent) PropertyChangeEvent(java.beans.PropertyChangeEvent) JFormattedTextField(javax.swing.JFormattedTextField) JSlider(javax.swing.JSlider) PropertyChangeListener(java.beans.PropertyChangeListener) ChangeListener(javax.swing.event.ChangeListener)

Example 47 with JFormattedTextField

use of javax.swing.JFormattedTextField in project pcgen by PCGen.

the class IntegerEditor method getTableCellEditorComponent.

//Override to invoke setValue on the formatted text field.
@Override
public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
    JFormattedTextField textField = (JFormattedTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column);
    textField.setValue(value);
    return textField;
}
Also used : JFormattedTextField(javax.swing.JFormattedTextField)

Example 48 with JFormattedTextField

use of javax.swing.JFormattedTextField in project pcgen by PCGen.

the class CheckDialog method initDC.

/**
	 * <p>
	 * Initializes the DC value
	 * </p>
	 *
	 */
private void initDC() {
    NumberFormatter formatter = new NumberFormatter(new DecimalFormat("##"));
    formatter.setValueClass(Integer.class);
    m_dc = new JFormattedTextField(formatter);
    m_dc.setFocusLostBehavior(JFormattedTextField.COMMIT_OR_REVERT);
    m_dc.setValue(m_defaultDC);
    JLabel label = new JLabel("DC:");
    label.setAlignmentX(Component.RIGHT_ALIGNMENT);
    addComponent(m_dc, label);
}
Also used : DecimalFormat(java.text.DecimalFormat) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) NumberFormatter(javax.swing.text.NumberFormatter)

Example 49 with JFormattedTextField

use of javax.swing.JFormattedTextField in project jdk8u_jdk by JetBrains.

the class InsetsEncapsulation method run.

@Override
public void run() {
    runTest(new JLabel("hi"));
    runTest(new JMenu());
    runTest(new JTree());
    runTest(new JTable());
    runTest(new JMenuItem());
    runTest(new JCheckBoxMenuItem());
    runTest(new JToggleButton());
    runTest(new JSpinner());
    runTest(new JSlider());
    runTest(Box.createVerticalBox());
    runTest(Box.createHorizontalBox());
    runTest(new JTextField());
    runTest(new JTextArea());
    runTest(new JTextPane());
    runTest(new JPasswordField());
    runTest(new JFormattedTextField());
    runTest(new JEditorPane());
    runTest(new JButton());
    runTest(new JColorChooser());
    runTest(new JFileChooser());
    runTest(new JCheckBox());
    runTest(new JInternalFrame());
    runTest(new JDesktopPane());
    runTest(new JTableHeader());
    runTest(new JLayeredPane());
    runTest(new JRootPane());
    runTest(new JMenuBar());
    runTest(new JOptionPane());
    runTest(new JRadioButton());
    runTest(new JRadioButtonMenuItem());
    runTest(new JPopupMenu());
    runTest(new JScrollBar());
    runTest(new JScrollPane());
    runTest(new JViewport());
    runTest(new JSplitPane());
    runTest(new JTabbedPane());
    runTest(new JToolBar());
    runTest(new JSeparator());
    runTest(new JProgressBar());
    if (!failures.isEmpty()) {
        System.out.println("These classes failed");
        for (final Component failure : failures) {
            System.out.println(failure.getClass());
        }
        throw new RuntimeException("Test failed");
    }
}
Also used : JDesktopPane(javax.swing.JDesktopPane) JTextArea(javax.swing.JTextArea) JRadioButton(javax.swing.JRadioButton) JLayeredPane(javax.swing.JLayeredPane) JTabbedPane(javax.swing.JTabbedPane) JButton(javax.swing.JButton) JProgressBar(javax.swing.JProgressBar) JTableHeader(javax.swing.table.JTableHeader) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) JScrollBar(javax.swing.JScrollBar) JTextPane(javax.swing.JTextPane) JToggleButton(javax.swing.JToggleButton) JSlider(javax.swing.JSlider) JMenuItem(javax.swing.JMenuItem) JComponent(javax.swing.JComponent) Component(java.awt.Component) JScrollPane(javax.swing.JScrollPane) JViewport(javax.swing.JViewport) JFormattedTextField(javax.swing.JFormattedTextField) JLabel(javax.swing.JLabel) JRadioButtonMenuItem(javax.swing.JRadioButtonMenuItem) JToolBar(javax.swing.JToolBar) JOptionPane(javax.swing.JOptionPane) JCheckBoxMenuItem(javax.swing.JCheckBoxMenuItem) JPopupMenu(javax.swing.JPopupMenu) JCheckBox(javax.swing.JCheckBox) JTree(javax.swing.JTree) JFileChooser(javax.swing.JFileChooser) JPasswordField(javax.swing.JPasswordField) JTable(javax.swing.JTable) JEditorPane(javax.swing.JEditorPane) JSpinner(javax.swing.JSpinner) JRootPane(javax.swing.JRootPane) JSplitPane(javax.swing.JSplitPane) JColorChooser(javax.swing.JColorChooser) JInternalFrame(javax.swing.JInternalFrame) JMenu(javax.swing.JMenu) JMenuBar(javax.swing.JMenuBar)

Example 50 with JFormattedTextField

use of javax.swing.JFormattedTextField in project knime-core by knime.

the class DBSorterNodeDialogPanel method update.

/**
 * Updates this panel based on the DataTableSpec, the list of columns to include and the corresponding sorting
 * order.
 *
 * @param spec the DataTableSpec
 * @param incl the list to include
 * @param sortOrder the sorting order
 * @param nrsortitems the inital number of sortitems to be shown
 */
void update(final DataTableSpec spec, final List<String> incl, final boolean[] sortOrder, final int nrsortitems) {
    m_spec = spec;
    super.removeAll();
    m_components.removeAllElements();
    int interncounter = 0;
    if (spec != null) {
        Vector<DataColumnSpec> values = new Vector<DataColumnSpec>();
        values.add(NOSORT);
        for (int j = 0; j < spec.getNumColumns(); j++) {
            values.add(spec.getColumnSpec(j));
        }
        if ((incl == null) || (sortOrder == null)) {
            for (int i = 0; i < nrsortitems && i < spec.getNumColumns(); i++) {
                DataColumnSpec selected = (i == 0) ? values.get(i + 1) : values.get(0);
                DBSortItem temp = new DBSortItem(i, values, selected, true);
                super.add(temp);
                m_components.add(temp);
            }
        } else {
            for (int i = 0; i < incl.size(); i++) {
                String includeString = incl.get(i);
                int columnIndex = spec.findColumnIndex(includeString);
                if (columnIndex != -1) {
                    DataColumnSpec colspec = spec.getColumnSpec(columnIndex);
                    DBSortItem temp = new DBSortItem(interncounter, values, colspec, sortOrder[interncounter]);
                    super.add(temp);
                    m_components.add(temp);
                    interncounter++;
                } else if (includeString.equals(NOSORT.getName())) {
                    DBSortItem temp = new DBSortItem(interncounter, values, NOSORT, sortOrder[interncounter]);
                    super.add(temp);
                    m_components.add(temp);
                    interncounter++;
                } else if (columnIndex == -1) {
                    DBSortItem temp = new DBSortItem(interncounter, values, includeString, sortOrder[interncounter]);
                    super.add(temp);
                    m_components.add(temp);
                    interncounter++;
                }
            }
        }
        Box buttonbox = Box.createHorizontalBox();
        Border addColumnBorder = BorderFactory.createTitledBorder("Add columns");
        buttonbox.setBorder(addColumnBorder);
        int maxCols = m_spec.getNumColumns() - m_components.size();
        JButton addSortItemButton = new JButton("new columns");
        final JSpinner spinner = new JSpinner();
        SpinnerNumberModel snm;
        if (maxCols == 0) {
            snm = new SpinnerNumberModel(0, 0, maxCols, 1);
            spinner.setEnabled(false);
            addSortItemButton.setEnabled(false);
        } else {
            snm = new SpinnerNumberModel(1, 1, maxCols, 1);
        }
        spinner.setModel(snm);
        spinner.setMaximumSize(new Dimension(50, 25));
        spinner.setPreferredSize(new Dimension(50, 25));
        NumberEditor ne = (NumberEditor) spinner.getEditor();
        final JFormattedTextField spinnertextfield = ne.getTextField();
        // workaround to ensure same background color
        Color backColor = spinnertextfield.getBackground();
        // when spinner's text field is editable false
        spinnertextfield.setEditable(false);
        spinnertextfield.setBackground(backColor);
        addSortItemButton.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(final ActionEvent ae) {
                ArrayList<String> newlist = new ArrayList<String>();
                for (int i = 0; i < m_components.size(); i++) {
                    DBSortItem temp = m_components.get(i);
                    newlist.add(temp.getColumnText());
                }
                int oldsize = m_components.size();
                String temp = spinner.getValue().toString();
                int newsize = Integer.parseInt(temp);
                for (int n = oldsize; n < oldsize + newsize; n++) {
                    newlist.add(NOSORT.getName());
                }
                boolean[] oldbool = new boolean[oldsize];
                boolean[] newbool = new boolean[oldsize + newsize];
                // copy old values
                for (int i = 0; i < m_components.size(); i++) {
                    DBSortItem temp2 = m_components.get(i);
                    newbool[i] = temp2.getSortOrder();
                }
                // create new values
                for (int i = oldbool.length; i < newbool.length; i++) {
                    newbool[i] = true;
                }
                update(m_spec, newlist, newbool, (oldsize + newsize));
            }
        });
        buttonbox.add(spinner);
        buttonbox.add(Box.createHorizontalStrut(10));
        buttonbox.add(addSortItemButton);
        super.add(buttonbox);
        revalidate();
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) Color(java.awt.Color) JButton(javax.swing.JButton) JFormattedTextField(javax.swing.JFormattedTextField) ArrayList(java.util.ArrayList) Box(javax.swing.Box) Dimension(java.awt.Dimension) SpinnerNumberModel(javax.swing.SpinnerNumberModel) DataColumnSpec(org.knime.core.data.DataColumnSpec) ActionListener(java.awt.event.ActionListener) JSpinner(javax.swing.JSpinner) Vector(java.util.Vector) Border(javax.swing.border.Border) NumberEditor(javax.swing.JSpinner.NumberEditor)

Aggregations

JFormattedTextField (javax.swing.JFormattedTextField)55 JLabel (javax.swing.JLabel)17 JPanel (javax.swing.JPanel)16 ParseException (java.text.ParseException)10 DecimalFormat (java.text.DecimalFormat)9 JButton (javax.swing.JButton)9 ActionListener (java.awt.event.ActionListener)8 NumberFormatter (javax.swing.text.NumberFormatter)8 ActionEvent (java.awt.event.ActionEvent)7 PropertyChangeEvent (java.beans.PropertyChangeEvent)7 JComboBox (javax.swing.JComboBox)7 Dimension (java.awt.Dimension)6 PropertyChangeListener (java.beans.PropertyChangeListener)6 GroupLayout (javax.swing.GroupLayout)6 Component (java.awt.Component)5 GridBagConstraints (java.awt.GridBagConstraints)5 GridBagLayout (java.awt.GridBagLayout)5 JCheckBox (javax.swing.JCheckBox)5 JScrollPane (javax.swing.JScrollPane)5 JSpinner (javax.swing.JSpinner)5