且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Java Swing JToolBar

更新时间:2023-01-14 13:51:05

JToolBar 创建 JButton 以包含您在其上设置的操作.默认情况下,JButton 是不透明的.要获得您所描述的效果,您需要覆盖 JToolBar.createActionComponent.

JToolBar creates JButtons to contain the actions you set on it. By default, JButtons are opaque. To get the effect you're describing, you need to override JToolBar.createActionComponent.

例如:

    jToolBar1 = new javax.swing.JToolBar() {
        @Override
        protected JButton createActionComponent(Action a) {
            JButton jb = super.createActionComponent(a);
            jb.setOpaque(false);
            return jb;
        }
    };

注意: YMMV 取决于使用的 LAF.

Note: YMMV depending on the LAF in use.