Thread: JRadioButton Question (Rep + Thanks)

Results 1 to 5 of 5
  1. #1 JRadioButton Question (Rep + Thanks) 
    Registered Member Lil Peep's Avatar
    Join Date
    Oct 2012
    Posts
    881
    Thanks given
    234
    Thanks received
    58
    Rep Power
    0
    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:
    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);
    My ButtonGroup code:
    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);
    Okay so currently it looks like this:



    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.
    Attached image Attached image Attached image Attached image Attached image
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    May 2012
    Posts
    286
    Thanks given
    7
    Thanks received
    49
    Rep Power
    25
    Quote Originally Posted by Matchbox 20 View 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:
    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);
    My ButtonGroup code:
    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);
    Okay so currently it looks like this:



    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
    Open Source 667 Divergent667
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Registered Member Lil Peep's Avatar
    Join Date
    Oct 2012
    Posts
    881
    Thanks given
    234
    Thanks received
    58
    Rep Power
    0
    Quote Originally Posted by juuuuu View Post
    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
    Attached image Attached image Attached image Attached image Attached image
    Reply With Quote  
     

  5. #4  
    Super Donator

    RSPSi's Avatar
    Join Date
    Mar 2011
    Posts
    169
    Thanks given
    70
    Thanks received
    173
    Rep Power
    328
    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.
    Reply With Quote  
     

  6. #5  
    Registered Member
    Join Date
    May 2012
    Posts
    286
    Thanks given
    7
    Thanks received
    49
    Rep Power
    25
    Quote Originally Posted by Matchbox 20 View 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
    Here's how you should be able to get it to work:
    (The code is rubish as such but works as an example)
    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);
        }
    }
    The result:

    Attached image
    Open Source 667 Divergent667
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Replies: 4
    Last Post: 12-25-2013, 02:00 PM
  2. Quest tab Questions (rep and thank)
    By Audax in forum Help
    Replies: 1
    Last Post: 12-22-2012, 11:51 AM
  3. General Java Question [Rep+Thanks]
    By relex lawl in forum Help
    Replies: 12
    Last Post: 04-08-2012, 06:50 AM
  4. Need Help Easy Question rep++
    By White. in forum Help
    Replies: 2
    Last Post: 05-04-2009, 04:02 PM
  5. 2 Questions rep+
    By Arvid in forum Help
    Replies: 0
    Last Post: 05-03-2009, 07:33 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •