java调整框大小_java – 调整JDialog框的大小

基本问题是TitledBorder不会将组件扩展到足以显示整个文本的位置.相反,它只会截断文本.

解决方案是确保组件足够大,以便显示文本.我在这里通过扩展文本字段的大小以及在“缩短的”标题的位置添加“全长”标签来展示这一点.

import java.awt.*;

import javax.swing.*;

import javax.swing.border.*;

class TestSizeOfGui {

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

JTextField account = new JTextField(10);

JPanel accountPanel = new JPanel(new GridLayout());

accountPanel.add(account);

accountPanel.setBorder(new TitledBorder("Account"));

String[] firstDigitList = {

"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

JLabel firstDigitListLabel = new JLabel("Leading Digit Change");

JPanel firstDigitListPanel = new JPanel(new BorderLayout(4,2));

firstDigitListPanel.add(firstDigitListLabel, BorderLayout.WEST);

JComboBox firstDigitCombo = new JComboBox(firstDigitList);

firstDigitListPanel.add(firstDigitCombo);

firstDigitCombo.setSelectedIndex(0);

firstDigitListPanel.setBorder(new TitledBorder("LDC"));

JPanel panel = new JPanel();

panel.add(accountPanel);

panel.add(firstDigitListPanel);

int result = JOptionPane.showConfirmDialog(

null,

panel,

"Please Enter Values",

JOptionPane.OK_CANCEL_OPTION);

}

});

}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值