salve a tutti.
ho creato un jbutton contenente una jlabel che a sua volta contiene un'immagine.
il mio problema è che non riesco a spostare la label all'interno del jButton nonostante abbia cambiato le coordinate della proprietà setBuonds dell'immagine.
posto il codice
codice:
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.WindowConstants;
public class provaimmagine extends javax.swing.JPanel {
private JLabel newIcon;
private JButton newButton;
/**
* Auto-generated main method to display this JPanel inside a new JFrame.
*/
public static void main(String[] args) {
JFrame frame = new JFrame();
frame.getContentPane().add(new provaimmagine());
frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
frame.pack();
frame.setVisible(true);
}
public provaimmagine() {
super();
initGUI();
}
private void initGUI() {
try {
this.setPreferredSize(new java.awt.Dimension(796, 94));
this.setMaximumSize(new java.awt.Dimension(796, 94));
this.setMinimumSize(new java.awt.Dimension(796, 94));
this.setLayout(null);
this.setSize(796, 94);
this.setBackground(new java.awt.Color(255, 0, 0));
this.add(getNewButton());
} catch (Exception e) {
e.printStackTrace();
}
}
private JLabel getNewIcon() {
if (newIcon == null)
try {
newIcon = new JLabel();
newIcon.setName("newIcon");
newIcon.setOpaque(true);
newIcon.setText("");
ImageIcon icon = (ImageIcon) (new Func()).getImageFromJar(
"newIcon.png", true);
newIcon.setIcon(icon);
newIcon.setMaximumSize(new java.awt.Dimension(50, 50));
newIcon.setMinimumSize(new java.awt.Dimension(50, 50));
} catch (Throwable e) {
e.printStackTrace();
}
return newIcon;
}
private JButton getNewButton() {
if (newButton == null) {
try {
newButton = new JButton();
newButton.setBounds(36, 10, 90, 74);
newButton.setText("");
newButton.add(getNewIcon());
} catch (Exception e) {
e.printStackTrace();
}
}
return newButton;
}
}
grazie mille per l'aiuto