JToolBar Look & Feel in Swing

感情迁移 提交于 2019-12-11 01:47:00

问题


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:


Two things:

  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):

decorateButton(AbstractButton)

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


来源:https://stackoverflow.com/questions/7846883/jtoolbar-look-feel-in-swing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!