JTextField: setPreferredSize(Dimension preferredSize) : JTextField « javax.swing « Java by API






JTextField: setPreferredSize(Dimension preferredSize)

 


import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextField;

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

    JPanel pHacked = new JPanel();
    pHacked.add(tf);

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

   
  








Related examples in the same category

1.JTextField.LEFT
2.JTextField.LEADING
3.JTextField.TRAILING
4.new JTextField(String text)
5.new JTextField(String text, int columns)
6.JTextField: addActionListener(ActionListener s)
7.JTextField: addFocusListener(FocusListener l)
8.JTextField: addKeyListener(KeyListener l)
9.JTextField: copy()
10.JTextField: cut()
11.JTextField: getActions()
12.JTextField: getCaretPosition()
13.JTextField: getDocument()
14.JTextField: getHorizontalVisibility()
15.JTextField: getHorizontalVisibility() (2)
16.JTextField: getInputMap()
17.JTextField: getKeymap()
18.JTextField: getScrollOffset()
19.JTextField: paste()
20.JTextField: registerKeyboardAction(ActionListener anAction,String aCommand,KeyStroke aKeyStroke,int aCondition)
21.JTextField: requestFocus()
22.JTextField: modelToView(int pos)
23.JTextField: read(Reader in, Object desc)
24.JTextField: setDocument(Document doc)
25.JTextField: setFocusAccelerator(char aKey)
26.JTextField: setHorizontalAlignment(int alignment)
27.JTextField: setInputVerifier(InputVerifier input)
28.JTextField: setNavigationFilter(NavigationFilter filter)
29.JTextField: setTransferHandler(TransferHandler newHandler)
30.JTextField: write(Writer out)