Ho dei JButton con icona in una JToolbar. Vorrei che il button non avesse background in modo che si veda solo l'icona, un po' come fa Netbeans:
![]()
Il codice con cui creo i bottoni e' questo:
Pensavo che con il setOpaque e il setBackground con un alpha 0 avrei ottenuto che il bottone e' trasparente e si vede solo la sua icona, invece no:codice:private JButton buildButton (String altText, String imageName, String tooltip, String actionCommand, boolean hasText, int iconWidth, int iconHeight, ActionListener alistener) { JButton button = new JButton(); if (imageName == null) { button.setFont (new Font(Font.SANS_SERIF, Font.PLAIN, 9)); button.setText (altText); } else { try { button.setIcon(new ImageIcon (Utilities.getScaledIcon (ImageIO.read (this.getClass().getResourceAsStream("/" + imageName)), iconWidth, iconHeight))); } catch (Exception ex) { button.setFont (new Font(Font.SANS_SERIF, Font.PLAIN, 9)); button.setText (altText); } } if (hasText) { button.setFont (new Font(Font.SANS_SERIF, Font.PLAIN, 9)); button.setText (altText); } button.setOpaque (false); button.setBackground (new Color (0.5f, 0.5f, 0.5f, 0.0f)); button.setToolTipText (tooltip); button.addActionListener (alistener); button.setActionCommand (actionCommand); return button; }
![]()
Cosa mi sono perso?

Rispondi quotando
