开发者

borders in java

I want to set single title border to group of textfields how can i do this in java / swing.

i have tried below cod开发者_StackOverflow社区e but text fields are compressing inside panel

// Create panel and add some components to it.
JPanel pnl = new JPanel(new FlowLayout(FlowLayout.LEFT));

pnl.add(new JLabel("Name"));
pnl.add(new JTextField());

// Add titled border to panel, which will therefore surround
// all child components placed on the panel.
pnl.setBorder(BorderFactory.createTitledBorder("It's Friday!"));


Here's an example using Swing:

// Create panel and add some components to it.
JPanel pnl = new JPanel(new FlowLayout(FlowLayout.LEFT));

pnl.add(new JLabel("Name"));
pnl.add(new JTextField());

// Add titled border to panel, which will therefore surround
// all child components placed on the panel.
pnl.setBorder(BorderFactory.createTitledBorder("It's Friday!"));


That is because the text fields have no size set yet. It's quickest to set a size by using the setColumns(int) method. You could also use the setPreferredSize(Dimension).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜