NETBEANS - How to make radio buttons match background image - java

I'm using a netbeans jFrame form, and i have inserted a Background image/ THe only problem i have is that i don't know how to get the color/theme of the radio button to be the same as my background image.
Any Tips ?

You can use this:
setOpaque(false);
This will prevent the background of the JRadioButton being drawn, thus revealing whatever is in the background.
JRadioButton rdb1 = new JRadioButton("RDB1");
rdb1.setOpaque(false);
I set the first radiobutton (RDB1) with rdb1.setOpaque(false) and this is what you will get.

Related

How do I change the color of a button, not just the border around it?

I want to change both the background and foreground color of my button. I used setBackground and setForeground and setOpaque(true), and it worked for the foreground, but not for the background of the button. There is kind of like a black border around the button, but I want the button itself to be black. How do I fix it?
this.closeButton = new JButton ("Close");
this.closeButton.setBackground(Color.BLACK);
this.closeButton.setForeground(Color.PINK);
this.closeButton.setOpaque(true);
The "border" is provided by the look and feel delegate. You can "disable" it by calling button.setBorderPainted
This may or may not meet your expecations
JButton button = new JButton("Close");
button.setBackground(Color.BLACK);
button.setForeground(Color.PINK);
button.setBorderPainted(false);
button.setOpaque(true);
You can possibly do: this.closeButton.setTextColor(Color.PINK);
uncomment line : this.closeButton.setForeground(Color.PINK) ;

How do i get rid of a blue border surrounding my button? For Java GUI

Because it wont let me add an image - new account
This is utilizing the Java GUI
The above image is an image pasted onto a button, I've tried to make the button transparent so that the user can't see it but I can't seem to get rid of this blue border.
Code I have so far
boss2 = new JButton(); //declared the static button earlier on in the code
boss2.setSize(300, 300);
boss2.setLocation(315, 200);
boss2.setIcon(new ImageIcon("dragon.gif"));
boss2.setRolloverIcon(new ImageIcon("dragon.gif"));
boss2.setOpaque(false);
boss2.setContentAreaFilled(false);
boss2.setBorder(null);
Is there a way to get rid of the blue border surrounding my image?
edit - sorry for the earlier mishap, uploaded the wrong file
I would suggest that what you are seeing is the focus rectangle, used to "highlight" the button as having keyboard focus.
You can use boss2.setFocusPainted(false); to stop it from been painted.
To not have a boarder drawn for a JButton (assuming that you are using javax.swing.JButton) you can simply do:
boss2.setBorderPainted(false);

Adding an Icon to a JCheckBox causes the checkbox not to be displayed [duplicate]

I have a swing application in which I want to use a JCheckbox with an icon. I constructed the icon as follows:
JCheckBox unsubmit = new JCheckBox("Unsubmit",applet.undo);
When I do this, the label and the icon appear in my GUI but the box itself is no where to be found. If I construct the JCheckBox without the icon, the box comes back. I've tried adjusting the buttons's preferred size but it had no effect.
Anyone know what's going on here?
Thanks,
Elliott
The Icon is being used in place of the box. Consider creating a JCheckBox and a JLabel placed immediately next to each other, and have the JLabel hold the ImageIcon.

How to Remove an icon on a JButton?

I'm trying to make a memory matching game, and I have icon images that I place onto a JButton when it is clicked. My question is, is there a way to remove the Icon from the JButton? I want to make so when a user clicks, the image is displayed, and if the second button the user clicks does not have the same image as the first button, then it disappears...any ideas?
Simple, Set the icon to null. It doesn't have an icon, so it removes it.
button.setIcon(null);
Use the following code:
JButton button = new JButton();
button.setIcon(null);
The best way to do it, is to replace the existing icon with a transparent icon of the same size. This will ensure the button does not change size, and potentially disturb the placement of other GUI elements that occur after it in the layout. E.G.
BufferedImage ourIcon = ...
BufferedImage invisibleIcon = new BufferedImage(
ourIcon.getWidth(), ourIcon.getHeight(), BufferedImage.TYPE_INT_ARGB);
Then, simply:
// use a JToggleButton instead of a JButton - it will remain pressed
JToggleButton button = new JToggleButton(new ImageIcon(ourIcon));
button.setPressedIcon(new ImageIcon(invisibleIcon));
// start a timer to change the state back, if required..

Moving an image icon within a JToggleButton?

Here's a picture of part of my interface. The image is circular with a transparent background but it doesn't center properly within the button. I was wondering if I could manually move it into position.
All you have to do is create a JToggleButton and then set the icon of the button to the image you are using
JToggleButton button = new JToggleButton(new ImageIcon("path to image"));
that should create the button, and put the image into the center of the button.
Hope that helps!

Categories