You are looking for this I guess.
If you need further help just reply to this post
|
Hey, So I'm trying to remove that stupid little circle icon with JRadioButtons and I just can't seem to figure it out lol
I'll post my code in case that helps. I'm also using a button group for the buttons if that has to do with anything.
My JRadioButton Code:
My ButtonGroup code:Code:JRadioButton serverCentralAustraliaButton = new JRadioButton("Central Australia"); serverCentralAustraliaButton.setForeground(Color.DARK_GRAY); serverCentralAustraliaButton.setFont(new Font("Microsoft Tai Le", Font.BOLD, 25)); serverCentralAustraliaButton.setHorizontalAlignment(SwingConstants.CENTER); serverCentralAustraliaButton.setBackground(Color.GRAY); serverCentralAustraliaButton.setBounds(412, 436, 385, 63); serverMenu.add(serverCentralAustraliaButton);
Okay so currently it looks like this:Code:ButtonGroup group = new ButtonGroup(); group.add(serverCentralAustraliaButton); group.add(serverEuropeWestButton); group.add(serverEuropeSouthButton); group.add(serverEuropeNorthButton); group.add(serverEuropeEastButton); group.add(serverUSWestButton); group.add(serverUSSouthButton); group.add(serverUSEastButton); group.add(serverUSNorthButton); group.add(serverCentralCanadaButton);
But I want it to look like this:
So basically, I want to remove the selected/deselected icon for the default JRadioButton and add a custom selected of my own as shown.
And here's the selected icon I made for the button (Exact same dimensions as the Radio Buttons):
Rep+Thanks for whoever can help.
You are looking for this I guess.
If you need further help just reply to this post
LOL wow I'm such an idiot. I didn't know Toggle Buttons could be used within a ButtonGroup so I didn't think of this.
How stupid of me. Rep'd and Thanks given.
The only problem im having actually is drawing that icon. setSelectedIcon doesn't seem to work for some reason lol
You can extend the JToggleButton class and override the paint methods. You can either completely rewrite the painting, or just call super.paint(g); and then do your drawing of the highlight rectangle if the button is toggled.
Here's how you should be able to get it to work:
(The code is rubish as such but works as an example)
The result:Code:package com.rs.tools; import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; import java.awt.image.BufferedImage; import java.io.IOException; import java.net.URL; /** * Created by Peng on 26.11.2016 22:07. */ public class Test { public static void main(String[] args) { ImageIcon selectedIcon, deselectedIcon; try { selectedIcon = new ImageIcon(ImageIO.read(new URL("https://cdn3.iconfinder" + ".com/data/icons/simple-web-navigation/165/tick-512.png")).getScaledInstance(100, 100, BufferedImage.SCALE_FAST)); deselectedIcon = new ImageIcon(ImageIO.read(new URL("https://cdn3.iconfinder" + ".com/data/icons/flat-actions-icons-9/792/Close_Icon_Dark-128.png")).getScaledInstance(100, 100, BufferedImage.SCALE_FAST)); } catch (IOException e) { e.printStackTrace(); return; } JFrame frame = new JFrame("Test"); frame.setSize(400, 400); frame.setLayout(new FlowLayout()); JToggleButton button = new JToggleButton(); JToggleButton button2 = new JToggleButton(); button.setSelectedIcon(selectedIcon); button2.setSelectedIcon(selectedIcon); button.setIcon(deselectedIcon); button2.setIcon(deselectedIcon); button.setSelected(true); frame.add(button); frame.add(button2); frame.setVisible(true); frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } }
« Previous Thread | Next Thread » |
Thread Information |
Users Browsing this ThreadThere are currently 1 users browsing this thread. (0 members and 1 guests) |