我想更改 jTabbed Pane 标题(选项卡标题)的颜色,并且我想删除分隔选项卡标题及其正文的线。我还喜欢选项卡式 Pane 的圆边。如何在 Swing 中进行所有这些定制?是否有任何外部 jar 可以使用这种内置的 gui 功能。我不想使用任何外观来执行此操作,因为其中许多也无法根据我的需要进行定制。由于我对java很陌生,请给我详细的答案。提前致谢。
最佳答案
对于更复杂的外观和感觉更改,您应该考虑编写自己的外观和感觉,就像已经提到的glad3r一样。 This post also is a great example .
对于一些基本的事情,您可能只想更改一些 UIManager 值,请参阅下面的示例并尝试一下这些值。
import java.awt.BorderLayout;
import java.awt.Color;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.UIManager;
import javax.swing.border.LineBorder;
import javax.swing.plaf.BorderUIResource;
import javax.swing.plaf.ColorUIResource;
import javax.swing.plaf.InsetsUIResource;
@SuppressWarnings("serial")
public class TabbedPaneTest extends JTabbedPane {
public static void main(String[] args) {
JFrame frame = new JFrame("TabbedPane");
frame.setSize(800, 600);
frame.setLocationRelativeTo(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setBackground(Color.RED);
frame.getContentPane().add(new TabbedPaneTest());
frame.setVisible(true);
}
public TabbedPaneTest() {
UIManager.put("TabbedPane.contentBorderInsets", new InsetsUIResource(1, 0, 0, 0));
UIManager.put("TabbedPane.contentAreaColor", new ColorUIResource(Color.GREEN));
UIManager.put("TabbedPane.focus", new ColorUIResource(Color.ORANGE));
UIManager.put("TabbedPane.selected", new ColorUIResource(Color.YELLOW));
UIManager.put("TabbedPane.darkShadow", new ColorUIResource(Color.DARK_GRAY));
UIManager.put("TabbedPane.borderHightlightColor", new ColorUIResource(Color.LIGHT_GRAY));
UIManager.put("TabbedPane.light", new ColorUIResource(Color.WHITE));
UIManager.put("TabbedPane.tabAreaBackground", new ColorUIResource(Color.CYAN));
UIManager.put("ToolTip.background", Color.WHITE);
UIManager.put("ToolTip.border", new BorderUIResource(new LineBorder(Color.BLACK)));
this.updateUI();
this.setBackground(Color.BLUE);
JPanel testPanel = new JPanel();
testPanel.setLayout(new BorderLayout());
testPanel.add(new JLabel("Hello World"), BorderLayout.NORTH);
testPanel.add(new JTextArea("Looks nice out there :)"), BorderLayout.CENTER);
JPanel testPanel2 = new JPanel();
testPanel2.setLayout(new BorderLayout());
testPanel2.add(new JLabel("Good Bye World"), BorderLayout.NORTH);
testPanel2.add(new JTextArea("AAAAAnnnnnd... I'm gone"), BorderLayout.CENTER);
this.addTab("Hello World", testPanel);
this.addTab("BB World", testPanel2);
}
}
关于java - 如何更改 jTabbed Pane 标题的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24577267/