开发者

Java Swing JXTaskPane: how to set bg and border?

I have written the following example code:

import org.jdesktop.swingx.*;
import javax.swing.*;
import java.awt.*;

public class TaskPaneExample{
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new TaskPaneExample();
            }});
        }

        public TaskPaneExample() {
            JFrame frame = new JFrame("TaskPane Example 1");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(doInit(), BorderLayout.CENTER);
            frame.setLocationRelativeTo(null);
            frame.pack();
            frame.setVisible(true);
        }

        private Component doInit() {
            JXTaskPaneContainer taskpanecontainer = new JXTaskPaneContainer();
            taskpanecontainer.setLayout(new VerticalLayout(2));

            final JXTaskPane taskpane1 = new JXTaskPane(){
                public void setCollapsed(boolean w){
                    super.setCollapsed(w);
                }};
            taskpane1.setTitle("First TaskPane");
            JPanel panel1 = new JPanel();
            panel1.setBackground(Color.red);
            panel1.setSize(100,100);
            taskpane1.add(panel1);
            taskpanecontainer.add(taskpane1);

            JXTaskPane taskpane2 = new JXTaskPane(){
                public void setC开发者_StackOverflow社区ollapsed(boolean w){
                    super.setCollapsed(w);
                }};
            taskpane2.setTitle("My Tasks");
            JPanel panel2 = new JPanel();
            panel2.setBackground(Color.blue); 
            panel2.setSize(100,100);
            taskpane2.add(panel2);
            taskpanecontainer.add(taskpane2);
            taskpanecontainer.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));

            return taskpanecontainer;
        }
    }
}

What I need are two things:

  1. how do I change the bgcolor of the title? I think it is done with the taskpane2.setUI(..) option but I had no luck working with it.
  2. how to set the border between the JXTaskPane and the Jpanel to zero?


Originally, the JXTaskPane was designed as a kind of "fixed-properties" component - it should look exactly like the corresponding native component (then of WinXP): custom appearance wasn't meant to be supported. As a consequence, the implementation of the title/border is deeply hidden in the XXTaskPaneUI - actually, everything boils down to be a Border.

1) as dogbane already mentioned, some of the properties can be changed on a per-application basis. Just beware: those are implementation details which might change or not be supported by concrete ui implementations (Nimbus is always a good candidate to not respecting them, even our not-really-synth implementation might not, forgot)

2) the "gap" is the border of the contentPane, you can set your own. Again a beware: might not survive an updateUI (could be that the ui delegates override them unconditionally, if so, please file an issue in the SwingX issuetracker)

((JComponent) taskpane2.getContentPane()).setBorder(BorderFactory.createEmptyBorder());

BTW: those panel.setSize have exactly no effect - layoutManagers rule ;-)


To change the bgcolour of the title, you can try setting the start and end background gradient colours in the UIManager:

UIManager.put("TaskPane.titleBackgroundGradientStart", Colors.White.color());
UIManager.put("TaskPane.titleBackgroundGradientEnd", Color.GREEN);

I also found an open swingx jira task for this: SWINGX-731 Support to define the color to JXTaskPane header.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜