我编写了以下示例代码:

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


我需要做两件事:


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

最佳答案

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

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


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

关于java - Java Swing JXTaskPane:如何设置背景和边框?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/5647522/

10-12 03:06