0
I wanted to make it possible to open a screen, perform any action and so by clicking on an icon.
I wanted to put different formats, so I don’t use one JButton
. Because when passing the image to him, he remained "rectangular". Furthermore, in case there is any component that can take the form of an image or even make with Jbutton, it is also valid.
Example click on a small circle:
package pacote01;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
public class NovoClass extends JFrame
{
private JPanel painel = new JPanel();
public NovoClass()
{
setSize(200, 150);
ImageIcon image = new ImageIcon(getClass().getResource("/imagens/icone.png"));
JLabel imagelabel = new JLabel(image);
painel.add(imagelabel);
add(painel);
setVisible(true);
setLocationRelativeTo(null);
setDefaultCloseOperation(EXIT_ON_CLOSE);
}
public static void main(String[] args) {
NovoClass novo = new NovoClass();
}
}
first thank you ! Just for "knowledge", you can tell me if a Jbutton or other component takes the form of an icon ?
– JavaTech
Not really, as close as you can get to putting an icon inside
JButton
by the methodsetIcon
in this way:jbutton.setIcon(image);
. But it’s just a button with a centered icon– brow-joe
Right, it’s just that I wanted to change the mouse pointer, plus, from what I just read, it looks like it’s just overwriting a certain method, when I go over the icone.
– JavaTech
Cool, in reality you can change the mouse cursor when passing over a
JLabel
, you can use the methodsetCursor
and add the desired cursor to jLabel in this way:imagelabel.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
, this example it leaves the cursor in Jlabel with a little hand (Cursor.HAND_CURSOR
), further into theCursor
you can select another template from the ones that are already preset– brow-joe
thank you, I’ll try !
– JavaTech