|
How to make a Text Field two columns wide |
|
|
This Java Swing tip illustrates a method of implementing a text field
that is two columns wide. The tip uses two panels and add them into a
grid layout.
import javax.swing.*;
public class WidthHack {
public static void main(String[] args) {
JTextField tf = new JTextField("mm");
tf.setPreferredSize( tf.getPreferredSize() );
tf.setText(""); // Empty the field.
JPanel pHacked = new JPanel();
pHacked.setBorder(new javax.swing.border.TitledBorder("hacked 2 columns"));
pHacked.add(tf);
JPanel pStock = new JPanel();
pStock.setBorder(new javax.swing.border.TitledBorder("stock 2 columns"));
pStock.add( new JTextField(2) );
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new java.awt.GridLayout(0, 1));
frame.getContentPane().add(pHacked);
frame.getContentPane().add(pStock);
frame.setSize(150, 150);
frame.setVisible(true);
tf.requestFocus();
}
}
|
Related Tips
|
Page 1 of 0 ( 0 comments )
You can share your information about this topic using the form below!
Please do not post your questions with this form! Thanks.