Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I want to customize the height and width of the JTextField objects. I have tried with the setSize method, passing width and height as dimensions and as int as well. But none of them seems to work. Am I missing something, like some mandatory method call on the panel or something so that the size customization would be effective? Please help. Thanks in advance.

EDIT: Here is a bit of the code:

public class WestPanel extends JPanel{
private JLabel dateL;
private JTextField date;
public WestPanel(){
setBackground(Color.white);
setLayout(new GridLayout(1,2,0,0));
dateL=new JLabel("Date: ");
date=new JTextField("dd/mm/yyyy");
date.setSize(60,10);
add(dateL);
add(date);
//....remaining code....//
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
484 views
Welcome To Ask or Share your Answers For Others

1 Answer

Let the layout manager take care of the dimensions of your Swing components, but if you absolutely must, use setPreferredSize in combination with a layout manager that respects that property.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...