JToolBar 外观感觉在摇摆 [英] JToolBar Look & Feel in Swing

查看:25
本文介绍了JToolBar 外观感觉在摇摆的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个基于 Swing 的应用程序,我想在其中添加 JToolBarJButton 中的图像,但它看起来不太好.JToolBar 在开始部分有一些点.

I'm developing a Swing based application in which I want to add JToolBar with images in JButton but it's not looking good. JToolBar is having some dots at the starting part.

我怎样才能摆脱这些点?

How can I get rid of the dots?

推荐答案

两件事:

  1. 点"您描述的可能是由于 JToolbar 默认情况下是可浮动的.如果您想禁用此功能,您可以调用 setFloatable(false).
  2. 这是我在将 JButton 添加到 JToolBar(或 JPanel 等)之前用来装饰它们的实用方法:
  1. The "dots" you describe are probably due to the JToolbar being floatable by default. If you wish to disable this you can call setFloatable(false).
  2. Here's a utility method I use to decorate JButtons prior to adding them to JToolBars (or JPanels, etc):

装饰按钮(抽象按钮)

public static void decorateButton(final AbstractButton button) {
    button.putClientProperty("hideActionText", Boolean.TRUE);
    button.setBorder(BorderFactory.createEmptyBorder());
    button.setBackground(null);
    button.setOpaque(true);
    button.setPreferredSize(BUTTON_SIZE);
    button.setMaximumSize(BUTTON_SIZE);
    button.setMinimumSize(BUTTON_SIZE);
    button.addMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            button.setBackground(COLOR_BUTTON_MOUSEOVER);
        }

        @Override
        public void mousePressed(MouseEvent e) {
            button.setBackground(COLOR_BUTTON_PRESSED);
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            button.setBorder(button.isEnabled() ? BORDER_BUTTON_MOUSEOVER_ENABLED : BORDER_BUTTON_MOUSEOVER_DISABLED);
            button.setBackground(COLOR_BUTTON_MOUSEOVER);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            button.setBorder(BorderFactory.createEmptyBorder());
            button.setBackground(null);
        }
    });
}

这篇关于JToolBar 外观感觉在摇摆的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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