Domanda

Io sto usando un JToolBar personalizzato utilizzando il seguente codice:

public class GeneralToolbar extends JToolBar{

  public GeneralToolbar() {
    super();
    setBackground(Color.white);
    setOpaque(true);
    setPreferredSize(new Dimension(54,54));
    setMinimumSize(new Dimension(54,54));
    setMaximumSize(new Dimension(54,54));
    setSize(new Dimension(54,54));
  }

  public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Dimension size = this.getSize();
    ImageIcon image = DefaultAction.createImageIcon("/com/aaa/resources/tabback");
    g.drawImage(image.getImage(), 0,0, size.width, size.height, this);
  }
}

Ora l'immagine è vista. Ma ho un rettangolo opaco intorno ai miei pulsanti. Ho cercato di impostare il pulsante opaca a false, ma non ho aggiunto alcun effetto. Grazie per il sostegno

È stato utile?

Soluzione

Forse è necessario utilizzare:

button.setBorderPainted( false );
button.setContentAreaFilled( false );

Naturalmente quando si sbarazzarsi del confine, allora non si vede l'effetto del clic sul pulsante.

Se avete bisogno di più Aiuto Inserisci SSCCE che mostra il problema.

Altri suggerimenti

public GeneralToolbar() {
    super();
    setBackground(Color.white);
    setOpaque(true);
    setPreferredSize(new Dimension(54,54));
    setMinimumSize(new Dimension(54,54));
    setMaximumSize(new Dimension(54,54));
    setSize(new Dimension(54,54));
}
public void paintComponent(Graphics g) {
    super.paintComponent(g);
   Dimension size = this.getSize();
   ImageIcon image = DefaultAction.createImageIcon("/com/aaa/resources/tabback");
   g.drawImage(image.getImage(), 0,0, size.width, size.height, this);
 }
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top