1个回答
展开全部
方法一:
combo.setPreferredSize(new Dimension(50, 20));//宽50,高20
方法二:
通过空白来占位.扩大宽度
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class JiaoCai9_8 {
public static void main(String[] args) {
Win win = new Win("简单计算器");
win.setBounds(100, 100, 300, 200);
win.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
win.setVisible(true);
}
}
class Win extends JFrame {
JTextField text1 = new JTextField(5);
JTextField text2 = new JTextField(5);
JComboBox<String> combo = new JComboBox<String>();//注意,这里是字符串类型
Win(String s) {
setTitle(s);
setLayout(new FlowLayout());
add(text1);
char[] ch = "+-*/".toCharArray();
for (int i = 0; i < ch.length; i++)
combo.addItem(" "+ch[i]+" ");
add(combo);
add(text2);
}
}
方法三:
使用设置字体的方式来实现
JComboBox<Character> combo = new JComboBox<Character>();
Win(String s) {
combo.setFont(new Font("宋体",Font.BOLD, 20));
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询