Java Code Examples for javax.swing.JTextField#getPreferredSize()

The following examples show how to use javax.swing.JTextField#getPreferredSize() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: JSpinField.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * JSpinField constructor with given minimum and maximum vaues and initial
 * value 0.
 */
public JSpinField(int min, int max) {
	super();
	setName("JSpinField");
	this.min = min;
	if (max < min)
		max = min;
	this.max = max;
	value = 0;
	if (value < min)
		value = min;
	if (value > max)
		value = max;

	darkGreen = new Color(0, 150, 0);
	setLayout(new BorderLayout());
	textField = new JTextField();
	textField.addCaretListener(this);
	textField.addActionListener(this);
	textField.setHorizontalAlignment(SwingConstants.RIGHT);
	textField.setBorder(BorderFactory.createEmptyBorder());
	textField.setText(Integer.toString(value));
	textField.addFocusListener(this);
	spinner = new JSpinner() {
		private static final long serialVersionUID = -6287709243342021172L;
		private JTextField textField = new JTextField();

		public Dimension getPreferredSize() {
			Dimension size = super.getPreferredSize();
			return new Dimension(size.width, textField.getPreferredSize().height);
		}
	};
	spinner.setEditor(textField);
	spinner.addChangeListener(this);
	// spinner.setSize(spinner.getWidth(), textField.getHeight());
	add(spinner, BorderLayout.CENTER);
}
 
Example 2
Source File: JSpinField.java    From MeteoInfo with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void adjustWidthToMaximumValue() {
	JTextField testTextField = new JTextField(Integer.toString(max));
	int width = testTextField.getPreferredSize().width;
	int height = testTextField.getPreferredSize().height;
	textField.setPreferredSize(new Dimension(width, height));
	textField.revalidate();
}
 
Example 3
Source File: SheetPreferences.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private JTextField createTextField(String tooltip, String value) {
    JTextField field = new JTextField(value);
    field.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    field.getDocument().addDocumentListener(this);
    Dimension size    = field.getPreferredSize();
    Dimension maxSize = field.getMaximumSize();
    maxSize.height = size.height;
    field.setMaximumSize(maxSize);
    add(field);
    return field;
}
 
Example 4
Source File: OutputPreferences.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private JTextField createTextField(String tooltip, String value) {
    JTextField field = new JTextField(value);
    field.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    field.getDocument().addDocumentListener(this);
    Dimension size    = field.getPreferredSize();
    Dimension maxSize = field.getMaximumSize();
    maxSize.height = size.height;
    field.setMaximumSize(maxSize);
    add(field);
    return field;
}
 
Example 5
Source File: DisplayPreferences.java    From gcs with Mozilla Public License 2.0 5 votes vote down vote up
private JTextField createTextField(String tooltip, String value) {
    JTextField field = new JTextField(value);
    field.setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
    field.getDocument().addDocumentListener(this);
    Dimension size    = field.getPreferredSize();
    Dimension maxSize = field.getMaximumSize();
    maxSize.height = size.height;
    field.setMaximumSize(maxSize);
    add(field);
    return field;
}