2

我编写了以下示例代码:

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 setCollapsed(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;
        }
    }
}

我需要的是两件事:

  1. 如何更改标题的 bgcolor?我认为它是通过taskpane2.setUI(..)选项完成的,但我没有运气使用它。
  2. 如何将theJXTaskPane和the之间的边界设置Jpanel为零?
4

2 回答 2

4

最初,JXTaskPane 被设计为一种“固定属性”组件——它应该看起来与相应的本地组件(当时的 WinXP)完全一样:不支持自定义外观。因此,标题/边框的实现深深地隐藏在 XXTaskPaneUI 中——实际上,一切都归结为一个边框。

1)正如dogbane已经提到的,一些属性可以在每个应用程序的基础上进行更改。请注意:这些是可能会更改或不受具体 ui 实现支持的实现细节(Nimbus 始终是不尊重它们的好选择,即使我们的非真正合成器实现也可能不会,忘记了)

2)“gap”是contentPane的边框,可以自己设置。再次注意:可能无法在 updateUI 中存活(可能是 ui 代表无条件覆盖它们,如果是,请在 SwingX 问题跟踪器中提交问题)

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

顺便说一句:那些 panel.setSize 完全没有效果 - layoutManagers 规则;-)

于 2011-04-13T12:57:05.383 回答
3

要更改标题的 bgcolour,您可以尝试在 UIManager 中设置开始和结束背景渐变颜色:

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

我还为此找到了一个 open swingx jira 任务:SWINGX-731 Support to define the color to JXTaskPane header

于 2011-04-13T10:29:11.920 回答