下面列出了javax.swing.JFormattedTextField#setColumns ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* Constructs a new <code>DatePickerParameterComponent</code>.
*/
public DateCellEditor( final Class dateType ) {
this.listeners = new EventListenerList();
this.dateType = dateType;
if ( this.dateType.isArray() ) {
this.dateType = this.dateType.getComponentType();
}
setLayout( new BorderLayout() );
dateField = new JFormattedTextField();
dateField.setColumns( 20 );
dateField.setEditable( true );
pickDateButton = new EllipsisButton( new PickDateListener() );
add( dateField, BorderLayout.CENTER );
add( pickDateButton, BorderLayout.EAST );
}
/**
* Constructor.
*/
public SpinnerRangeDouble(double defValue, double minValue, double maxValue, double incValue, String format) {
super();
this.defValue = defValue;
this.minValue = minValue;
this.maxValue = maxValue;
this.incValue = incValue;
Double def = new Double(defValue);
Double min = new Double(minValue);
Double max = new Double(maxValue);
Double inc = new Double(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
setEditor(new JSpinner.NumberEditor(this, format));
JFormattedTextField tf = ((JSpinner.DefaultEditor) getEditor()).getTextField();
tf.setColumns(7);
}
/**
* Constructor.
*/
public SpinnerRangeDouble(double defValue, double minValue, double maxValue, double incValue, int visibleChars) {
super();
this.defValue = defValue;
this.minValue = minValue;
this.maxValue = maxValue;
this.incValue = incValue;
Double def = new Double(defValue);
Double min = new Double(minValue);
Double max = new Double(maxValue);
Double inc = new Double(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
JFormattedTextField tf = ((JSpinner.DefaultEditor) getEditor()).getTextField();
tf.setColumns(visibleChars);
}
/**
* Constructor.
*/
public SpinnerRangeFloat(float defValue, float minValue, float maxValue, float incValue) {
super();
this.defValue = defValue;
this.minValue = minValue;
this.maxValue = maxValue;
this.incValue = incValue;
Float def = new Float(defValue);
Float min = new Float(minValue);
Float max = new Float(maxValue);
Float inc = new Float(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
JFormattedTextField tf = ((JSpinner.DefaultEditor) getEditor()).getTextField();
tf.setColumns(7);
}
/**
* Constructor.
*/
public SpinnerRangeFloat(float defValue, float minValue, float maxValue, float incValue, String format) {
super();
this.defValue = defValue;
this.minValue = minValue;
this.maxValue = maxValue;
this.incValue = incValue;
Double def = new Double(defValue);
Double min = new Double(minValue);
Double max = new Double(maxValue);
Double inc = new Double(incValue);
this.model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
setEditor(new JSpinner.NumberEditor(this, format));
JFormattedTextField tf = ((JSpinner.DefaultEditor) getEditor()).getTextField();
tf.setColumns(7);
}
/**
* Constructor.
*/
public SpinnerRangeFloat(float defValue, float minValue, float maxValue, float incValue, int visibleChars) {
super();
this.defValue = defValue;
this.minValue = minValue;
this.maxValue = maxValue;
this.incValue = incValue;
Float def = new Float(defValue);
Float min = new Float(minValue);
Float max = new Float(maxValue);
Float inc = new Float(incValue);
model = new SpinnerNumberModel(def, min, max, inc);
setModel(model);
JFormattedTextField tf = ((JSpinner.DefaultEditor) getEditor()).getTextField();
tf.setColumns(visibleChars);
}
/**
* Creates a dialog to change the grid size.
* @param settings are the {@link GameSettings} that will receive the new grid size.
*/
public GridSizeDialog(GameSettings settings) {
this.settings = settings;
widthInput = new JFormattedTextField(createNumberFormatter());
widthInput.setColumns(TEXT_FIELD_COLUMNS);
heightInput = new JFormattedTextField(createNumberFormatter());
heightInput.setColumns(TEXT_FIELD_COLUMNS);
setLayout(new BorderLayout());
add(new JLabel(MESSAGE), BorderLayout.NORTH);
JPanel subPanel = new JPanel();
subPanel.add(new JLabel(WIDTH));
subPanel.add(widthInput);
subPanel.add(Box.createHorizontalStrut(SPACE)); // a spacer
subPanel.add(new JLabel(HEIGHT));
subPanel.add(heightInput);
add(subPanel, BorderLayout.SOUTH);
}
private JSpinner createSpinner(int value)
{
SpinnerModel model = new SpinnerNumberModel(value, Integer.MIN_VALUE, Integer.MAX_VALUE, 1);
JSpinner spinner = new JSpinner(model);
Component editor = spinner.getEditor();
JFormattedTextField spinnerTextField = ((JSpinner.DefaultEditor) editor).getTextField();
spinnerTextField.setColumns(4);
return spinner;
}
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
private void editSliderSample(MouseEvent evt, final int sliderIndex) {
final PropertyContainer vc = new PropertyContainer();
vc.addProperty(Property.create("sample", getSliderSample(sliderIndex)));
vc.getDescriptor("sample").setDisplayName("sample");
vc.getDescriptor("sample").setUnit(getModel().getParameterUnit());
final ValueRange valueRange;
if (sliderIndex == 0) {
valueRange = new ValueRange(Double.NEGATIVE_INFINITY, round(getMaxSliderSample(sliderIndex)));
} else if (sliderIndex == getSliderCount() - 1) {
valueRange = new ValueRange(round(getMinSliderSample(sliderIndex)), Double.POSITIVE_INFINITY);
} else {
valueRange = new ValueRange(round(getMinSliderSample(sliderIndex)), round(getMaxSliderSample(sliderIndex)));
}
vc.getDescriptor("sample").setValueRange(valueRange);
final BindingContext ctx = new BindingContext(vc);
final NumberFormatter formatter = new NumberFormatter(new DecimalFormat("#0.0#"));
formatter.setValueClass(Double.class); // to ensure that double values are returned
final JFormattedTextField field = new JFormattedTextField(formatter);
field.setColumns(11);
field.setHorizontalAlignment(JFormattedTextField.RIGHT);
ctx.bind("sample", field);
showPopup(evt, field);
ctx.addPropertyChangeListener("sample", pce -> {
hidePopup();
setSliderSample(sliderIndex, (Double) ctx.getBinding("sample").getPropertyValue());
computeZoomInToSliderLimits();
applyChanges();
});
}
public static JFormattedTextField createIntegerFieldTrackingValue(@Nonnull InspectionProfileEntry owner,
@Nonnull String property,
int integerFieldColumns) {
JFormattedTextField valueField = new JFormattedTextField();
valueField.setColumns(integerFieldColumns);
setupIntegerFieldTrackingValue(valueField, owner, property);
return valueField;
}
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
static void init(int length, boolean hex, JFormattedTextField text) {
ValueFormatter formatter = new ValueFormatter(length, hex);
text.setColumns(length);
text.setFormatterFactory(new DefaultFormatterFactory(formatter));
text.setHorizontalAlignment(SwingConstants.RIGHT);
text.setMinimumSize(text.getPreferredSize());
text.addFocusListener(formatter);
}
public SnifferControl() {
super();
setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
_hostIpTextField = new JTextField(17);
_hostIpTextField.setText(Resources.getLabel("sniffer.host.tooltip"));
final FirstInputListener listener = new FirstInputListener(_hostIpTextField);
_hostIpTextField.addMouseListener(listener);
_hostIpTextField.addKeyListener(listener);
_hostIpTextField.setToolTipText(Resources.getLabel("sniffer.host.tooltip"));
add(_hostIpTextField);
final JLabel protocolLabel = new JLabel(Resources.getLabel("protocol.label"));
protocolLabel.setToolTipText(Resources.getLabel("protocol.desc"));
add(protocolLabel);
for (final Protocol type : Protocol.values()) {
if (type == Protocol.OTHER) {
continue;
}
final JCheckBox check = new JCheckBox(type.name(), type == Protocol.TCP);
_packets.put(type, check);
add(check);
}
final JLabel portLabel = new JLabel(Resources.getLabel("port.label"));
portLabel.setToolTipText(Resources.getLabel("port.desc"));
_allPortCheck = new JCheckBox(Resources.getLabel("all.port.label"));
_allPortCheck.setToolTipText(Resources.getLabel("all.port.desc"));
_allPortCheck.setSelected(false);
add(_allPortCheck);
_portTF = new JFormattedTextField();
_portTF.setText("80,443");
_portTF.setColumns(15);
// _portTF.setMaximumSize(new Dimension(30, _portTF.getPreferredSize().height));
add(portLabel);
add(_portTF);
_portTF.setEnabled(true);
_allPortCheck.addChangeListener(e -> _portTF.setEnabled(!_allPortCheck.isSelected()));
_filterPacketLengthCheck = new JCheckBox(Resources.getLabel("filter.length"));
_filterPacketLengthCheck.setToolTipText(Resources.getLabel("filter.length.desc"));
_filterPacketLengthCheck.setSelected(false);
add(_filterPacketLengthCheck);
_filterLengthTF = new JFormattedTextField(new NumberFormatterFactory());
_filterLengthTF.setText("128");
_filterLengthTF.setColumns(5);
add(_filterLengthTF);
_filterPacketLengthCheck.addChangeListener(e -> _filterLengthTF.setEnabled(_filterPacketLengthCheck.isEnabled() && _filterPacketLengthCheck.isSelected()));
_capturePeriod = new JFormattedTextField(new NumberFormatterFactory());
_capturePeriod.setText("0");
_capturePeriod.setColumns(5);
add(new JLabel(Resources.getLabel("capture.period")));
add(_capturePeriod);
_captureButton = new JButton(GO_IMG);
_captureButton.setToolTipText(Resources.getLabel("capture.packet.start"));
add(_captureButton);
_captureButton.addActionListener(arg0 -> start());
}