如何更改JSplitPane的颜色 [英] How to change the color of a JSplitPane

查看:183
本文介绍了如何更改JSplitPane的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个小程序,在读一本关于swing的书时,在两个标签之间创建了一个JSplitPane。
问题是JSplitPane几乎看不到(至少在我的操作系统中 - MAC OS Lion)并且在它上面设置一些属性(比如前景色)似乎不起作用。

I have written a small program, while reading a book about swing, that creates a JSplitPane between two labels. The problem is that the JSplitPane can barely be seen (at least in my operating system - MAC OS Lion) and setting some properties on it (like foreground color) does not seem to work.

以下是代码:

//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();
            }

        });
    }
}

我有什么方法可以改变它的颜色,所以它真的能脱颖而出吗?
谢谢。

Is there any way I can change its color , so that it can really stand out? Thank you.

推荐答案

JLabel 默认为 NON_Opaque ,简单透明,你可以

JLabel is by default NON_Opaque, simple is transparent, you can


  • 更改 JLabels JComponent JPanel 可能更好

通过更改不透明度JLabel #setOpaque(true)

这篇关于如何更改JSplitPane的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆