Example usage for javax.swing JTextField setPreferredSize

List of usage examples for javax.swing JTextField setPreferredSize

Introduction

In this page you can find the example usage for javax.swing JTextField setPreferredSize.

Prototype

@BeanProperty(preferred = true, description = "The preferred size of the component.")
public void setPreferredSize(Dimension preferredSize) 

Source Link

Document

Sets the preferred size of this component.

Usage

From source file:Main.java

public static void main(String[] args) {
    JTextField tf = new JTextField("mm");
    tf.setPreferredSize(tf.getPreferredSize());
    tf.setText("");

    JPanel pHacked = new JPanel();
    pHacked.add(tf);/*from w  w w  . j  a v  a 2  s.c o m*/

    JPanel pStock = new JPanel();
    pStock.add(new JTextField(2));

    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLayout(new java.awt.GridLayout(0, 1));
    frame.add(pHacked);
    frame.add(pStock);
    frame.setSize(150, 150);
    frame.setVisible(true);
    tf.requestFocus();
}

From source file:Main.java

public static JTextField createTextField(Dimension preferredSize, KeyAdapter keyListener, boolean enabled) {
    JTextField textField = new JTextField();
    textField.setPreferredSize(preferredSize);
    textField.addKeyListener(keyListener);
    textField.setEnabled(enabled);//from  w w w.j a  v  a  2  s  . c  o m
    return textField;
}

From source file:Main.java

/**
 * Default textfield design.//from  ww w  .java  2  s  .co  m
 * 
 * @param requireMinWidth Whether the textfield should have a default min. width set.
 * @param contents Initial contents.
 * @return
 */
public static JTextField defaultTextField(boolean requireMinWidth, String contents) {
    JTextField jtf = new JTextField(contents);

    if (requireMinWidth)
        jtf.setPreferredSize(new Dimension(400, jtf.getPreferredSize().height));

    jtf.setBorder(BorderFactory.createCompoundBorder(defaultLineBorder(),
            BorderFactory.createEmptyBorder(0, 5, 0, 0)));
    return jtf;
}

From source file:com.opendoorlogistics.speedregions.excelshp.app.FileBrowserPanel.java

public static JComponent[] createBrowserComponents(String label, String initialFilename,
        final Consumer<String> filenameChangeListener, final boolean directoriesOnly,
        final String browserApproveButtonText, final FileFilter... fileFilters) {
    ArrayList<JComponent> ret = new ArrayList<JComponent>();
    if (label != null) {
        ret.add(new JLabel(label));
    }/*  ww  w  . j  av a2 s .  c o  m*/
    JTextField textField = createTextField(initialFilename, filenameChangeListener);
    ret.add(textField);
    textField.setPreferredSize(new Dimension(200, 28));

    ret.add(createBrowseButton(directoriesOnly, browserApproveButtonText, textField, fileFilters));
    return ret.toArray(new JComponent[ret.size()]);
}

From source file:com.opendoorlogistics.core.utils.ui.FileBrowserPanel.java

public static JComponent[] createComponents(String label, String initialFilename,
        final FilenameChangeListener filenameChangeListener, final boolean directoriesOnly,
        final String browserApproveButtonText, final FileFilter... fileFilters) {
    ArrayList<JComponent> ret = new ArrayList<JComponent>();
    if (label != null) {
        ret.add(new JLabel(label));
    }/*w w w  .  j a  v a 2s. c  o  m*/
    JTextField textField = createTextField(initialFilename, filenameChangeListener);
    ret.add(textField);
    textField.setPreferredSize(new Dimension(200, 28));

    ret.add(createBrowseButton(directoriesOnly, browserApproveButtonText, textField, fileFilters));
    return ret.toArray(new JComponent[ret.size()]);
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java

public static void adjustSize(JTextField textField) {
    textField.setPreferredSize(new Dimension(0, FIELD_HEIGHT));
}

From source file:MainClass.java

MainClass() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel p = new JPanel();
    p.setPreferredSize(new Dimension(300, 50));
    JTextField jtf = new JTextField(20);
    jtf.setPreferredSize(new Dimension(100, 20));
    p.add(jtf);//from   ww w.ja va2  s  . co m

    getContentPane().add(p);

    pack();
    setVisible(true);
}

From source file:Main.java

public Main() throws HeadlessException {
    setSize(200, 200);/*from  ww w.  j  a v  a2  s.c  o m*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new FlowLayout(FlowLayout.LEFT));

    DocumentFilter filter = new UppercaseDocumentFilter();

    JTextField firstName = new JTextField();
    firstName.setPreferredSize(new Dimension(100, 20));
    ((AbstractDocument) firstName.getDocument()).setDocumentFilter(filter);

    JTextField lastName = new JTextField();
    lastName.setPreferredSize(new Dimension(100, 20));
    ((AbstractDocument) lastName.getDocument()).setDocumentFilter(filter);

    add(firstName);
    add(lastName);
}

From source file:Main.java

public Main() throws HeadlessException {
    setSize(200, 200);/*from w  w w . j a  va 2 s .  c  o m*/
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setLayout(new FlowLayout(FlowLayout.LEFT));

    JLabel usernameLabel = new JLabel("Username: ");
    JTextField usernameTextField = new JTextField();
    usernameTextField.setPreferredSize(new Dimension(100, 20));
    add(usernameLabel);
    add(usernameTextField);

    usernameTextField.addKeyListener(new KeyAdapter() {
        public void keyReleased(KeyEvent e) {
            JTextField textField = (JTextField) e.getSource();
            String text = textField.getText();
            textField.setText(text.toUpperCase());
        }

        public void keyTyped(KeyEvent e) {
        }

        public void keyPressed(KeyEvent e) {
        }
    });
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopTextField.java

@Override
protected JTextField createTextComponentImpl() {
    JTextField field = new FlushableTextField();

    int height = (int) field.getPreferredSize().getHeight();
    field.setPreferredSize(new Dimension(150, height));
    return field;
}