无法理解为什么在为java应用程序应用setLookAndFeel时,tabbedPane会丢失我之前设置的backgorunf。
在应用setLookAndFeel之前:
应用setLookAndFeel后:
这是我的代码:
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.io.File;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextPane;
import javax.swing.UIManager;
public class CoocHelpPanel {
private JFrame frame;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
//UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
CoocHelpPanel window = new CoocHelpPanel();
window.frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the application.
*/
public CoocHelpPanel() {
initialize();
frame.setVisible(true);
}
/**
* Initialize the contents of the frame.
*/
private void initialize() {
frame = new JFrame();
frame.setTitle("TEST TAB COLOR");
frame.setResizable(false);
frame.getContentPane().setBackground(Color.WHITE);
frame.setBounds(100, 100, 200, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(null);
JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
tabbedPane.setBounds(10, 10, 965, 855);
frame.getContentPane().add(tabbedPane);
JPanel panel = new JPanel();
tabbedPane.addTab("TAB 1 - AAAA", null, panel, null);
tabbedPane.setBackgroundAt(0, Color.red);
panel.setLayout(null);
JPanel panel_1 = new JPanel();
tabbedPane.addTab("TAB 2 - BBBB", null, panel_1, null);
tabbedPane.setBackgroundAt(1, Color.red);
panel_1.setLayout(null);
}
}
答案 0 :(得分:1)
如果你看一下setBackgroundAt的javadoc,你会看到:
尊重这个属性取决于外观和感觉,有些人可能会选择忽略它。
WindowsLookAndFeel不支持,默认值(金属?)支持。这就是原因。