开发者

borders in java

开发者 https://www.devze.com 2022-12-17 13:29 出处:网络
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

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

精彩评论

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