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;
}
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;
}
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);
}
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");
}
}
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();
}
}
Aggregations