/** * Create a button to go inside of the toolbar. By default this will load an image resource. The * image filename is relative to the classpath (including the '.' directory if its a part of the * classpath), and may either be in a JAR file or a separate file. * * @param key The key in the resource file to serve as the basis of lookups. */ protected JButton createToolbarButton(String key) { URL url = getResource(key + imageSuffix); JButton b = new JButton(new ImageIcon(url)) { @Override public float getAlignmentY() { return 0.5f; } }; b.setRequestFocusEnabled(false); b.setMargin(new Insets(1, 1, 1, 1)); String astr = getProperty(key + actionSuffix); if (astr == null) { astr = key; } Action a = getAction(astr); if (a != null) { b.setActionCommand(astr); b.addActionListener(a); } else { b.setEnabled(false); } String tip = getResourceString(key + tipSuffix); if (tip != null) { b.setToolTipText(tip); } return b; }
public MenuedButton(Icon icon, JPopupMenu menu) { JButton iconBut = new JButton(icon); iconBut.setMargin(new Insets(0, 0, 0, 0)); // iconBut. setMainButton(iconBut); setPopupMenu(menu); setShdPopupOnBtnClick(true); setPopupLocation(BELOW); }
public void setUseFlatUI(boolean b) { main.setContentAreaFilled(!b); main.setFocusPainted(!b); main.setBorderPainted(!b); main.setMargin(new Insets(1, 1, 1, 1)); popper.setContentAreaFilled(!b); popper.setFocusPainted(!b); popper.setBorderPainted(!b); popper.setMargin(new Insets(1, 1, 1, 1)); setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setOpaque(false); MouseAdapter ma = new MouseAdapter() { public void mouseEntered(MouseEvent e) { main.setContentAreaFilled(true); main.setBackground(new Color(216, 240, 254)); // m.getMainButton().setForeground( Color.black ); setBorder(new LineBorder(new Color(200, 200, 200), 1)); setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); popper.setBackground(new Color(242, 242, 242)); popper.setContentAreaFilled(true); popper.setBorder(menu.getBorder()); } public void mouseExited(MouseEvent e) { main.setContentAreaFilled(false); // c.setForeground( Color.black ); setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setCursor(Cursor.getDefaultCursor()); popper.setContentAreaFilled(false); popper.setBorder(null); } }; main.addMouseListener(ma); popper.addMouseListener(ma); }
public JButton createImageButton(Action a) { JButton b = new JButton(a); b.setMargin(new Insets(0, 0, 0, 0)); return b; }