[英]How to change the colour of the jTabbed Pane header
我想更改jTabbed Pane標頭(標簽標頭)的顏色,並且要擺脫將標簽標頭及其主體分開的那一行。 我也喜歡選項卡式窗格的圓邊。 如何進行所有這些自定義? 這種內置的gui功能是否有可用的外部jar。 我不想使用任何外觀,因為其中許多也無法根據我的需要進行自定義。 由於我是Java的新手,請給我詳細的答案。 提前致謝。
對於更復雜的外觀更改,您應該像編寫的glad3r一樣編寫自己的外觀。 這個帖子也是一個很好的例子 。
對於一些基本的事情,您可能只想更改一些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);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.