2 回答

TA貢獻(xiàn)1806條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以簡(jiǎn)單地為組合框設(shè)置字體。是這樣的:
import java.awt.Dimension;
import java.awt.Font;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import javax.swing.WindowConstants;
import javax.swing.plaf.basic.BasicComboBoxRenderer;
/**
* <code>ComboTest</code>.
*/
public class ComboTest {
public static void main(String[] args) {
SwingUtilities.invokeLater(new ComboTest()::startUp);
}
private void startUp() {
JComboBox<String> combo = new JComboBox<>(new String[] {"A", "B", "C"});
combo.setFont(new Font("Serif", Font.BOLD, 30));
combo.setRenderer(new ComboRenderer());
JFrame frm = new JFrame("Combo test");
frm.add(combo);
frm.pack();
frm.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frm.setLocationRelativeTo(null);
frm.setVisible(true);
}
private static class ComboRenderer extends BasicComboBoxRenderer {
@Override
public Dimension getPreferredSize() {
return new Dimension(200, 80);
}
}
}
當(dāng)我的建議對(duì)您的情況沒(méi)有幫助時(shí),請(qǐng)創(chuàng)建一個(gè)小的可運(yùn)行示例,以便我們也可以啟動(dòng)和調(diào)試它。

TA貢獻(xiàn)1772條經(jīng)驗(yàn) 獲得超8個(gè)贊
您可以使用 combo.setFont(new FontUIResource("Roboto",Font.PLAIN,12); 為組合框設(shè)置字體。
添加回答
舉報(bào)