box.setPreferredSize(new Dimension(x,y))//设置下拉菜单的尺寸
方法一:
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))
}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)