我已經編寫了一個小程序,同時閱讀了一本關於swing的書,它在兩個標籤之間創建了一個JSplitPane。 問題是幾乎看不到JSplitPane(至少在我的操作系統 - MAC OS Lion中)並且設置它的某些屬性(如前景色)似乎不起作用。如何更改JSplitPane的顏色
下面是代碼:
//Demonstrate a simple JSplitPane
package swingexample4_6;
import javax.swing.*;
import java.awt.*;
public class SplitPaneDemo {
//constructor
public SplitPaneDemo()
{
//Create a new JFrame container.
//Use the default border layout
JFrame jfrm = new JFrame("Split Pane Demo");
//Give the frame an initial size
jfrm.setSize(380, 150);
//Terminate the program when the user closes the application
jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//--Make two labels to show the split pane
JLabel jlab = new JLabel(" Left side: ABCDEFGHIJKLMNOPQRSTUVWXYZ");
JLabel jlab2 = new JLabel(" Right side: ABCDEFGHIJKLMNOPQRSTUVWXYZ");
//Set the minimum size for each label
//This step is not technically needed to use a split pane,
//but it enables the split pane resizing features to be
//used to their maximum extent
jlab.setMinimumSize(new Dimension(90, 30));
jlab2.setMinimumSize(new Dimension(90, 30));
//--Create a split pane
JSplitPane jsp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, true, jlab, jlab2);
//Code to get a list of component names in the console
Component[] listComponents = jsp.getComponents();
String theList;
for (Component myComponent: listComponents)
{
theList = myComponent.toString();
System.out.println(theList);
}
//Add the split pane to the content pane
jfrm.getContentPane().add(jsp);
//Display the frame
jfrm.setVisible(true);
}
public static void main(String[] args) {
//Create the frame on the event dispatching thread
SwingUtilities.invokeLater(new Runnable(){
@Override
public void run() {
new SplitPaneDemo();
}
});
}
}
有沒有什麼辦法可以改變它的顏色,這樣才能夠真正脫穎而出? 謝謝。
尼斯源:總之,重要的是,清楚地格式化和顯示問題(圖形)。 +1 – 2012-04-11 16:38:36