如何在 Java 中更改 JTabbedPane 选项卡的默认字体?
要显示选项卡的默认字体,您需要使用 Font 类。假设我们用 Java 中创建了一个 JTabbedPane -
JTabbedPane tabbedPane = new JTabbedPane();
现在,使用字体样式、样式和字体大小设置字体 -
Font font = new Font("Arial", Font.CENTER_BASELINE, 20); tabbedPane.setFont(font);
这是一个用于更改 JTabbedPane 选项卡默认字体的示例 -
package my; import javax.swing.*; import java.awt.*; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Technologies"); JTabbedPane tabbedPane = new JTabbedPane(); JPanel panel1, panel2, panel3, panel4, panel5; panel1 = new JPanel(); panel2 = new JPanel(); panel3 = new JPanel(); panel4 = new JPanel(); panel5 = new JPanel(); tabbedPane.addTab("Blockchain", panel1); tabbedPane.addTab("Salesforce", panel2); tabbedPane.addTab("SAS", panel3); tabbedPane.addTab("Matlab ", panel4); tabbedPane.addTab("Servlet", panel5); tabbedPane.setBackground(Color.blue); tabbedPane.setForeground(Color.white); Font font = new Font("Arial", Font.CENTER_BASELINE, 20); tabbedPane.setFont(font); frame.add(tabbedPane); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(660,350); frame.setVisible(true); } }
输出
广告