Java Swing JToolBar

2024-01-19

我创造了JToolBar(Java 摇摆)。我在框架上设置了一个背景图像,其中包含JToolBar。我想要我的JToolBar是透明的,以便保持在框架上的图像应该是可见的。我在用setOpaque(false)但它对我的工具栏没有任何影响。以前有人处理过这个问题吗?我的代码如下

import javax.swing.ImageIcon;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

public class NewJFrame extends javax.swing.JFrame {
    static NewJFrame dialog = null;

    /** Creates new form NewJFrame */
    public NewJFrame() {
        initComponents();
        jToolBar1.setOpaque(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jToolBar1 = new javax.swing.JToolBar();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jToolBar1.setRollover(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(275, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {



            public void run() {

                try {
                    try {
                        // Set cross-platform Java L&F (also called "Metal")
                        UIManager.setLookAndFeel(UIManager.
                                getSystemLookAndFeelClassName());

                    } catch (UnsupportedLookAndFeelException ex) {
                        ex.printStackTrace();
                    }
                } catch (ClassNotFoundException e) {
                    e.printStackTrace();
                } catch (InstantiationException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
                ImagePanel panel = new ImagePanel(new ImageIcon("image").getImage());
                dialog = new NewJFrame();
                dialog.getContentPane().add(panel);
                dialog.setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify
    private javax.swing.JToolBar jToolBar1;
    // End of variables declaration

}

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

例如:

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

Note:YMMV 取决于所使用的 LAF。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Java Swing JToolBar 的相关文章

随机推荐

  • ReactJS 组件 PropTypes - 使用一组参数指定函数类型

    我在react 版本0 13 3 组件中指定所需的函数proptype var MyComponent React createClass propTypes onClick React PropTypes func isRequired
  • Flutter - 使用 Google API 发送电子邮件

    经过大量研究和修复问题 我到达了我的以下位置 github https github com rafaelcb21 gmail api flutter 但我不知道我是否正确安装了 json 由于出现以下错误 error errors dom
  • 如何验证类属性?

    背景 我有一个 CSV 文件 我需要准备并验证每行中的每个元素 并创建一个具有有效数据的类的集合 IE CSV 文件如下所示 EmpID FirstName LastName Salary 1 James Help 100000 2 Jan
  • 动态改变约束

    我有一个 dijit form NumberTextBox 输入字段 以这些参数开头 new dijit form NumberTextBox id din1 style width 60px constraints places 0 pa
  • Jquery:如何将TD移动到另一个TR?

    我已经生成了 html 我需要使用 Jquery 重构 html 如下所示 原来的 table tr td Col 1 Value td tr tr td Col 2 Value td tr tr td Col 3 Value td tr
  • 从 EmberJS 中的路线观察服务上的属性

    我想我不理解这里的概念 据我所知有任何Ember object可以观察另一个人的属性Ember object 所以 我有一个服务 一个路由器和一个组件 我需要组件和路由器能够观察服务的属性 我完全有可能只是以错误的方式构建解决方案 我将在最
  • 向停靠且具有自动滚动功能的面板添加填充

    我的表单底部有一个面板 该面板设置为 自动滚动 以便在需要时出现滚动条 我有一个动态添加到此面板的图像 一切看起来都很好 除了最后一张图像 因为这里表单的最边缘是一个图像 例如 有谁知道如何在面板的右侧添加填充 是的 我确实尝试设置面板右侧
  • Thymeleaf + Spring(非 Boot)-如何显示来自 messageSource 的消息

    我在使用 Thymeleaf 设置 Spring MVC 不使用 Boot 因为我在发现 Spring Initializr 之前启动了它 以显示来自我的资源包的消息时遇到了问题 该应用程序的主要配置类是 Configuration Ena
  • 在 C++ std::vector 和 C 数组之间进行转换而不进行复制

    我希望能够在 std vector 及其底层 C 数组 int 之间进行转换 而无需显式复制数据 std vector 是否提供对底层 C 数组的访问 我正在寻找这样的东西 vector
  • App Store 必须使用 iOS 15 SDK 或更高版本构建,包含在 Xcode 13 或更高版本中

    错误 ITMS 90725 SDK 版本问题 此应用程序是使用 iOS 14 4 SDK 构建的 提交到 App Store 的所有 iOS 应用程序都必须使用 iOS 15 SDK 或更高版本构建 包含在 Xcode 13 或更高版本中
  • R 中带有加权数据的频率表

    我需要按年龄和婚姻状况计算个人的频率 所以通常我会使用 table age marital status 然而 每个人在数据采样后都有不同的权重 如何将其合并到我的频率表中 您可以使用函数svytable从包装中survey or wtd
  • 访问属性“H”的权限被拒绝

    我编写了下面的代码来使用java脚本捕获网页的整个屏幕截图 我在用着 火狐版本 49 0 1 铬版本 54 0 2840 59 m硒版本 3 0 0 OS Win10 64位Java 1 8 import java io File impo
  • 使用 Tor + Privoxy 抓取谷歌购物结果:如何避免被阻止?

    我已经安装了Tor Privoxy在我的服务器上 它们工作正常 已测试 但现在当我尝试使用urllib2 python 当然 使用代理来抓取谷歌购物结果 我总是被谷歌阻止 有时是503错误 有时是403错误 那么任何人有任何解决方案可以帮助
  • 使用socket.io/node.js在网页上显示流式twitter

    我正在尝试使用 node js socket io 和 twit 构建 Twitter 流式 Web 应用程序 var express require express app express http require http server
  • 用 X"" 测试空字符串[重复]

    这个问题在这里已经有答案了 我知道我可以在 Bash 中测试空字符串 z像这样 if z myvar then do stuff fi 但我看到很多代码都是这样写的 if X X myvar then do stuff fi 这种方法更便携
  • VS2008如何从Web Developer更改为C# Developer设置

    我刚刚重新安装了 vs2008 第一次运行时不小心选择了 Web Developer 而不是 C Developer 现在我习惯的所有键绑定都是错误的 如何将其更改为 C Developer 我尝试了 devenv resetsetting
  • URL Selenium 超出最大重试次数 [重复]

    这个问题在这里已经有答案了 因此 我希望遍历 URL 数组并打开不同的 URL 以使用 Selenium 进行网页抓取 问题是 一旦我点击第二个 browser get url 我就会收到 URL 超出最大重试次数 和 无法建立连接 因为目
  • Symfony2,原则 2:getResult 对象

    posts em gt find Application BlogBundle Entity Post 1 print r posts 为什么我得到了 Barii BlogBundle Entity Post Object id Barii
  • 欧拉计划#29

    嗯 解决了这个问题之后通过天真 的STL集 我正在阅读论坛条目 在那里我找到了这个条目 include
  • Java Swing JToolBar

    我创造了JToolBar Java 摇摆 我在框架上设置了一个背景图像 其中包含JToolBar 我想要我的JToolBar是透明的 以便保持在框架上的图像应该是可见的 我在用setOpaque false 但它对我的工具栏没有任何影响 以