Again with the JTable having a Radio Button

I have an issue with a project I am working on. The client "insists" on having radio buttons in a JTable. Without going into all the philosophical discussions about this, I need an answer as to how I can make my radio buttons behave like radio buttons (i.e. be in a button group and select/deselect appropriately).
I have a working code sample for the application as well as the renderer and editor I have. Can someone help me?
Thanks in advance!
The Main application
* Main.java
* Created on July 12, 2006, 12:31 PM
package sampletest;
import java.awt.Dimension;
import javax.swing.ButtonGroup;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableColumn;
public class Main extends JFrame {
    private JTable table = null;
    /** Creates a new instance of Main */
    public Main() {
        super();
        this.setPreferredSize(new Dimension(400,400));
        JPanel p = new JPanel();
        createTable();
        p.add(table);
        this.add(p);
        pack();
        this.setVisible(true);
    private void createTable() {
        table = new JTable();
        DefaultTableModel model = (DefaultTableModel)table.getModel();
        model.setColumnCount(3);
        model.setRowCount(3);
        TableColumn column = table.getColumnModel().getColumn(0);
        column.setCellRenderer(new RadioButtonRenderer());
        column.setCellEditor(new RadioButtonEditor(new JCheckBox()));        
        for(int row=0; row<3; row++) {
            for(int col=0; col<3; col++) {
                model.setValueAt(new Boolean(false), row, col);
     * @param args the command line arguments
    public static void main(String[] args) {
        Main main = new Main();
}The renderer
* RadioButtonRenderer.java
* Created on July 12, 2006, 12:38 PM
package sampletest;
import java.awt.Component;
import javax.swing.JRadioButton;
import javax.swing.JTable;
import javax.swing.table.TableCellRenderer;
class RadioButtonRenderer implements TableCellRenderer {
    public JRadioButton btn = new JRadioButton();
    public Component getTableCellRendererComponent(JTable table, Object
        value,boolean isSelected, boolean hasFocus, int row, int column) {
        if (value==null)
            return null;
        if(((Boolean)value).booleanValue())
            btn.setSelected(true);
        else
            btn.setSelected(false);
        if (isSelected) {
            btn.setForeground(table.getSelectionForeground());
            btn.setBackground(table.getSelectionBackground());
        } else {
            btn.setForeground(table.getForeground());
            btn.setBackground(table.getBackground());
        return btn;
}The editor
package sampletest;
* RadioButtonEditor.java
* Created on July 12, 2006, 12:31 PM
import java.awt.Component;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.ButtonGroup;
import javax.swing.DefaultCellEditor;
import javax.swing.JCheckBox;
import javax.swing.JRadioButton;
import javax.swing.JTable;
public class RadioButtonEditor extends DefaultCellEditor implements ItemListener {
    public JRadioButton btn = new JRadioButton();
    public RadioButtonEditor(JCheckBox checkBox) {
        super(checkBox);
    public Component getTableCellEditorComponent(JTable table, Object
        value, boolean isSelected, int row, int column) {
        if (value==null) return null;
            btn.addItemListener(this);
        if ( ( (Boolean) value).booleanValue())
            btn.setSelected(true);
        else
            btn.setSelected(false);
        return btn;
    public Object getCellEditorValue() {
        if(btn.isSelected() == true)
            return new Boolean(true);
        else
            return new Boolean(false);
    public void itemStateChanged(ItemEvent e) {
        super.fireEditingStopped();
}

     public class MyTableModel extends DefaultTableModel{
          public void setValueAt(Object aValue,
                int row,
                int column){
               if (column == 0){
                    if (aValue instanceof Boolean){
                         boolean val = ((Boolean)aValue).booleanValue();
                         super.setValueAt(aValue, row, column);
                         if (val){
                              for (int i=0; i<getRowCount(); i++){
                                   if (i != row){
                                        super.setValueAt(false, i, column);
               else{
                    super.setValueAt(aValue, row, column);
     }

Similar Messages

  • How to modify file name with the press of a radio button

    Hello,
    I have a simple task that I am having some trouble completing. This is what my program is doing:
    My VI takes 3 angles between -180 and 180 and computes the XYZ coordinate using a mathscript node. Then every time I press Trigger, the current 3 angles and their corresponding XYZ coordinate are written to a spreadsheet file.
    I need to tweak the VI some more to accomplish the following:
    The first time I select the radio button Point (or Line), I would like the spreadsheet file name to be "Point001" (or "Line001"). Then I want to press the Trigger 10 times, write to that file just created, "Point001" (or "Line001"), and after the 10th Trigger, I would like the radio button Point (or Line) to become automatically unselected.
    The next time I select the radio button Point (or Line), I would like the spreadsheet file name to now be "Point002" (or "Line002"). Then I want to press the Trigger again for 10 times, write to that file just created, "Point002" (or "Line002"), and after the 10th Trigger, I would like the radio button Point (or Line) to become automatically unselected, again.
    And so on...
    Basically, I am trying to increment the filename Pointxxx each time I select the radio button. I want to write to that file 10 times, at which point the radio button Point automatically becomes unselected.
    I hope it is clear to what I am trying to do. Any help would be appreciated.
    r15
    Attachments:
    Untitled 1.vi ‏67 KB

    I attached my working VI.
    Now, the problem is that Trigger is saving to a different file each time as opposed to having the 10 Triggers save to one file.
    This is what is happening now:
    When I have the radio button Point (or Line) selected:
    Trigger (1st time) saves to "point1" (or "line1")
    Trigger (2nd time) saves to "point2" (or "line2")
    Trigger (3rd time) saves to "point3" (or "line3")
    Trigger (10th time) saves to "point10" (or "line10")
    Then, Point (or Line) is deselected.
    What I need is the following:
    When the radio button Point (or Line) is selected
    Trigger (1st time) saves to "point1" (or "line1")
     Trigger (2nd time) ALSO saves to "point1" (or "line1")
    Trigger (3rd time) ALSO saves to "point1" (or "line1")
    Trigger (10th time) saves to "point1" (or "line1")
    Then, the radio button Point (or Line) is deselected.
    Next time I select Point, I want the Triggers to write to "point2".
    Can you fix this for me?
    Thank you
    r15 
    Attachments:
    Test.vi ‏71 KB

  • Disable an Input field with the help of a radio button selection.

    Hi Guys,
    I know it is a very basic question and also has many threads for the mentioned query. None of the threads gave me a real clue about the problem. It is as follows:
    Simply, I have an input field and there are two more radio buttons on the screen, say rd1, and rd2.
    Initially Rb_gtgr is active and input field is blank and disabled, and when i select Rb_selgr, input field should be active and mandatory. It means when i try to execute the code with out entering any value after it is enabled, an error message should appear. For this the code is as follows:
    AT SELECTION-SCREEN OUTPUT.
      PERFORM screen_grace_on.
    AT SELECTION-SCREEN ON p_grace.
      PERFORM check_grace_days.
    FORM screen_grace_on .
      DATA: l_v_grace TYPE char2.
      CONSTANTS: l_c_grace TYPE char7 VALUE 'P_GRACE'.
    l_v_grace = p_grace.
    CLEAR p_grace.
      IF rb_selgr EQ c_x.
        LOOP AT SCREEN.
          IF screen-group1 = 'ABC'.
            screen-required = 1.
           screen-active = 1.
          ENDIF.
          MODIFY SCREEN.
        ENDLOOP.
      ELSE.
        LOOP AT SCREEN.
          IF screen-group1 = 'ABC'.
            screen-input = 0.
            screen-active = 1.
          ENDIF.
          MODIFY SCREEN.
        ENDLOOP.
      ENDIF.
    ENDFORM.                    " SCREEN_GRACE_ON
    FORM check_grace_days.
      IF rb_selgr EQ c_x AND  p_grace EQ 0.
        PERFORM screen_grace_on.
        MESSAGE e492(/ams/ramfcmess1).          " Enter the number of Grace days
      ELSEIF rb_selgr EQ c_x AND p_grace GE 0.
        PERFORM screen_grace_on.
      ENDIF.
    ENDFORM.
    Ideally this code should work since in the PBO i.e., At selection screen output i am enabling the fields, and also when i select the second radio button i am also checking for the value too..
    I am working on 4.7 version of SAP. The Most interesting observation is it works fine for few variants, and not with others.
    Thank you

    Hi,
    Go through this following code,
    selection-screen begin of block B2 with frame title TEXT-005.
    selection-screen begin of line.
    parameters:     P_BIRPT type C radiobutton group RAD1 default 'X' user-command UCOMM.
    selection-screen comment 3(20) TEXT-002 for field P_BIRPT.
    selection-screen end of line.
    selection-screen begin of line.
    parameters:     P_COLRPT type C radiobutton group RAD1.
    selection-screen comment 3(20) TEXT-003 for field P_COLRPT.
    selection-screen end of line.
    selection-screen begin of line.
    parameters:     P_PAYRPT type C radiobutton group RAD1.
    selection-screen comment 3(20) TEXT-004 for field P_PAYRPT.
    selection-screen end of line.
    selection-screen end   of block B2.
    selection-screen begin of block B1 with frame title TEXT-001.
    select-options: SO_KTOKD for  KNA1-KTOKD modif id M4,
              SO_BLART for  BSIS-BLART modif id M2.
    parameters:     P_PAID   type ZCLEAR     modif id M3 as listbox visible length 20.
    selection-screen end   of block B1.
    at selection-screen output.
      loop at screen.
        if P_BIRPT eq 'X'.
          if SCREEN-GROUP1   = 'M2' or SCREEN-GROUP1 = 'M3' .
            SCREEN-INVISIBLE = '1'.
            SCREEN-ACTIVE    = '0'.
            modify screen.
          endif.
        elseif P_COLRPT eq 'X'.
          if SCREEN-GROUP1   = 'M3'.
            SCREEN-INVISIBLE = '1'.
            SCREEN-ACTIVE    = '0'.
            modify screen.
          endif.
        elseif P_PAYRPT eq 'X'.
          if SCREEN-GROUP1   = 'M2'.
            SCREEN-INVISIBLE = '1'.
            SCREEN-ACTIVE    = '0'.
            modify screen.
          endif.
          if SCREEN-GROUP1   = 'M4'.
            SCREEN-INVISIBLE = '1'.
            SCREEN-ACTIVE    = '0'.
            modify screen.
          endif.
        endif.
      endloop.
    Thanks
    Anil D

  • Grid is coming with the row having editable field

    hello,
    I ahve to display OO ALV grid after checking a check box in selection screen , after selecting a row and pressing on edit button in application tool bar it has to give edit option for a field in the row which user has selected, after pressing save button (pop up for confirmation has been given here )data has to get update in ztable and the same has to be reflected in the current grid ...... TILL HERE EVERY THING IS WORKING FINE.
    If the user selects particular record and press the EDIT button, ( assume he didn't edited any thing and he didn't press the save button also )  immediately if he presses the BACK button it should go to selection screen ( this part is working) again if he presses execute button in selection screen ---> grid is coming with the row having editable field (WHICH I DONT WANT).

    Hi,
    You can code as below...
    WHEN 'BACK3'.
    perform check_save_BEFORE.
    "refresh the internal tables used for Selection process and display and also refresh the internal tables used in methods.
    LEAVE TO SCREEN 0..
    Try it.
    Thanks
    Arbind

  • How can I change the slide to 8 Radio buttons mutually exclusive?

    How can I change the slide to 8 Radio buttons mutually exclusive?
    I saw the example in Labview. but it only contains upto 5 radio
    buttons. I need 8. How can I change it? Is there any shortcuts?

    I made this with NI's radio button control found in the boolean palette.  Just resize the cluster border, and move the buttons to where you want.  To add a button, select one of them, hold down Control and Shift keys, then drag the button to a new location.  The button gets duplicated.  Do this until you have enough buttons.
    Message Edited by tbob on 10-31-2005 01:07 PM
    - tbob
    Inventor of the WORM Global
    Attachments:
    RadioButtons.PNG ‏2 KB

  • Changing the Selection Screen on the selection of a radio button

    Hi experts,
    I am stuck with a situation here.
    I have a selection screen with 2 blocks.
    The first block contains 5 radio buttons.
    The second block contains 7 select options fields.
    Now i want to show different select options when the user selects different radio buttons.
    For example, when the user selects radio button 1, select options 1, 2, 3, 4,  and 5 should be shown.
    When the user selects radio button2,  select options 3, 4, 5, 6, and 7 should be shown.
    How do i go about implementing this????
    I guess i need to do the coding in event "AT SELECTION-SCREEN OUTPUT".
    Should i use MODIF ID????
    Please help.
    Points will be awarded.
    Thanks and Regards
    Gaurav Kumar Raghav

    Use AT SELECTION-SCREEN  
    not AT SELECTION-SCREEN OUTPUT.
    cause output addition makes it a PBO not PAI
    check ur requirement & use the events accordingly
    group all select options under one group which you want to show on selection of radio button
    under AT SELECTION-SCREEN   
    loop at screen and change the property "ACTIVE (0/1)" for the group you want
    & don't forget to modify screen table in the end.
    one more thing u should do is use addition USER-COMMAND with your radio buttons.
    PARAMETERS : r1 RADIOBUTTON GROUP r1 USER-COMMAND f1,
                 r2 RADIOBUTTON GROUP r1.
    PARAMETERS : p1 TYPE c MODIF ID a,
                 p2 TYPE c MODIF ID b.
    AT SELECTION-SCREEN . " output
      LOOP AT SCREEN .
        IF r2 = 'X' AND screen-name = 'P1'.
          screen-active = '0'.
          MODIFY SCREEN.
        ENDIF.
      ENDLOOP.
    Edited by: mrugesh phatak on Oct 8, 2008 11:00 AM

  • How to change the "Address is Residential" radio button to default "off"

    Hello, I am attempting to set the "Address is Residential" radio button under UPS shipping option to default "off". Our company sells mainly to business locations, and the button is causing confusion and incorrect shipping rates with our customers. Sorry if this has been covered before, I have seen a few discussions when googling the topic, however their links are not working.
    Thanks!

    Hi,
    The option cannot be changed but a possible workaround to avoid client confusion is to hide this div, using some custom JavaScript script that will hide it after is rendered by the shipping option tag.
    Unfortunately I do not have the exact script but will leave this topic open for the community to assist if possible.
    Kind regards,
    -Sidney

  • Hi just done some up dates on my i phone three it got half way through sync with my phone then the phone turned of and came back on again with the i tune picture and the end of the usb cable. but my phone is plugged into my computer can anyone helphi just

    hi just done some up dates on my i phone three it got half way through sync with my phone then the phone turned of and came back on again with the i tune picture and the end of the usb cable. but my phone is plugged into my computer can anyone help

    Try to force your phone into recovery mode. Disconnect it from the computer's USB cord. Turn it off if you can by holding the sleep/wake switch until you see the red slide to off. If you can't turn it off, please continue. Press and hold the home button while plugging it into the computer's USB cord. Continue holding the Home button while iPhone starts up. While starting up, you will see the Apple logo. When you see "Connect to iTunes" on the screen, you can release the Home button and iTunes will display the recovery mode message.  http://support.apple.com/kb/HT1808
    Then you can restore your phone:  http://support.apple.com/kb/HT1414

  • HT201250 i am using for first time the time machine and an external hard drive because I want to erase my macbook and start from zero files. do i keep my files in the portable hard disk when I connect it again with the macbook or the time machine will era

    i am using for first time the time machine and an external hard drive because I want to erase my macbook and start from zero files. Am i keeping my files in the portable hard disk when I will connect it again with the macbook or the time machine will erase all?
    I would like to know if after I erase all my data, empy hard drive inside the macbook, the time machine will erase all my files that I have saved in my "WD "My passport" external hard drive

    Welcome to Apple Support Communities
    Time Machine has to erase the external disk in order to make backups. Before setting Time Machine up, copy the files of your external disk to the hard disk of the Mac in order not to lose them, and then, set up Time Machine. The first backup will start automatically.
    If you want more information about Time Machine, read the Pondini's site > http://pondini.org

  • IPod classic hard drive needle sometimes skips (Red X).  When it doesn't and seems to power on normally, I start to restore it in Itunes and then it starts to skip again with the Red X on the screen.

    iPod classic hard drive needle sometimes skips (Red X). When it doesn't and seems to power on normally, I start to restore it in Itunes and then it starts to skip again with the Red X on the screen.  One time I was able to run the disk utility in time and reformat the hard drive, but the red x ended up appearing again and the hard drive started skipping again.
    Is there anything I can do besides get a new hard drive?
    P.S. I have also tried the banging on palm/floor trick and it hasn't worked yet for me.

    There nothing we can suggest to save a bad iPod hardisk, except to try some 3rd Party software to try repair the Hardisk.
    The Super Fix for Most iPod Problems
    See this earlier post on partition repair using 3rd Party EaseUS Partitipon Master software.

  • Linksys E4200 - has to reboot to connect again with the internet

    I bought the E4200 a month ago (replaced D-link DIR-655) and since then I have to reboot it twice.
    I have a NAS connected to the router (and router to cable modem) and sometimes I have to FTP files from abroad. If I use the FTP too much time the E4200 just loose connectivity with the internet. Once home I have to reboot it in order to connect again with the internet. It never happen me before with the D-Link.
    Does anybody has a similar problem?
    Thanks!

    Actually mine is working great now, almost as if it had a break-in period.
    Mine has not flashed once in the past day (or more) and the last time I rebooted it was Wednesdsay evening (only to see if I could stop the flashing which was still happening
    at that time).
    I was also online on an interactive (gaming / gambling) site that is very quick to report what it considers "disconnects" if it sees any weakness in the connection to its servers and when using the E4200 it did NOT disconnect a single time all day yesterday.
    (My Belkin N1 Vision wireless router connection via my Rosewill RNX-N1 USB adapter had been "disconnecting" multiple several days in a row although I was able to surf the web without issues while it reported me as disconnected).
    Possible reasons everything is fine:
    1) I placed the router's four ridiculously tiny feet on four thick wooden drink coasters
    to give it more breathing room.
    The flashing stopped a day or two later... (Keep in mind the router is less than a week old, so the reason it stopped flashing could be unrelated).
    My wireless signal strength does seem to be sensitive to a 5.8 GHz cordless phone strangely even though it is a 2.4 GHz wireless adapter.
    Just turning the phone (which has an INternal anntenna and is about 3 1/2 feet away from my wireless adapter at the moment) 15 or 20 degrees immediately changed the wireless signal quality from 4 bars to 3 bars and vice versa!!! 
    2) As far as my needing to reboot it that one time (during the first full day I owned the E4200):
    I had been switching between two different model Rosewill wireless adapters a few times that afternoon (same chipset, same driver I believe and even show up as
    same device in 32 bit Windows 7 Device Manager) without restarting the router after each switch
    Since that one reboot, everything has been fine and my connection has been solid (pingtest.net tests over wireless produce an 'A' and speed has been for the most part relatively stable at 130 Mbps).
    I hope thay helps others here (especially Part 1 above).
    So overall I am extremely happy now.
    I now just need to see what the implications are by the current lack of official IPv6 support in the E4200 (will post separately about that).
    I noticed that my "IPv6 connectivity" on the wireless connection showed "no internet".
    I just ran some IPv6 tests online (on two separate sites) and they passed and, lo and behold, now it shows "internet access" (again) for IPv6 (and not just IPv4 as it did before)!

  • When I quit itunes it restarts again with the dot under the itunes logo but the iTunes window doesn't open until I click the icon on the dock.  Also in the middle of the size vale in the size column the value starts with a number then a ? then a number.

    When I quit itunes it restarts again with the dot under the itunes logo but the iTunes window doesn't open until I click the icon on the dock.  Also in the middle of the size vale in the size column the value starts with a number then a ? then a number.

    This forum is for questions from those managing sites on iTunes U, Apple's service for colleges and universities to post educational material in the iTunes Store. You'll be most likely to get help with this issue if you ask in the general iTunes for Mac forums.
    Regards.

  • I installed Adobe FlashPlayer version 13.0 however I am getting an error message "Plug in error". Can anybody provide an answer. I already uninstall the version and install it again with the same results. Thanks.

    I installed Adobe FlashPlayer version 13.0 however I am getting an error message "Plug in error". Can anybody provide an answer. I already uninstall the version and install it again with the same results. Thanks.

    Adobe admits to a Flash problem here:
    http://forums.adobe.com/message/6285851#6285851
    YOu can apply the fix they show and tehn wait for them to fix the problem

  • Is it possible to flip the multiple choice quiz "radio" button from left to right of the answers?

    Hello forum,
    I am using Captivate version 6.1.0.319 on a Windows 7 desktop PC and would like to know if it is possible to flip the multiple choice quiz "radio" button from left to right of the answers. I am working on a project that uses the "Require Right to Left composer" within the Global Preferences: General settings. The captions has been switched from left to right but the quiz answer radio buttons did not. Any help would be appreciated.
    Thanks, in advance. 

    Hello and welcome to the forum,
    I'm not aware of such a possibility. A workaround could be to create your own MCQ slides, using standard objects and widgets like the radiobuttons widget (there is an enhanced version created by Jim Leichliter) and advanced actions. These articles were written for previous versions, but can give you an idea about the work involved:
    http://blog.lilybiri.com/widgets-and-custom-questions-part-1
    http://blog.lilybiri.com/extended-widgets-for-custom-mcq-and-tf-questi
    Lilybiri

  • Will i have to do it all over again with the new ipod?

    my ipod is super beat up and it's time for a new one, so i deleted all my itunes programs off of my computer and i've reinstalled them.
    while i'm saving up money for a new ipod i wanted to go ahead and reimport all my songs into a library, once i do this am i able to just plug the new ipod into my computer and all of these songs will update and i'll be all set?
    or will i have to do it all over again with the new ipod?

    Once you have reinstated the tracks to your library, you'll able to sync your new iPod to it automatically and update it with the contents of your iTunes.

Maybe you are looking for

  • How do I move all my 25,000 Lightroom 5 images from an external HD to an internal (ssd) drive on a mac?

    I have all my Lightroom (LR) image folders on an external hard drive which is getting full and was always too slow in use. I want to keep my existing LR catalogue but move ALL the images, previews etc onto my laptop with nice fast ssd. How?? Any sugg

  • IMac/TV connection issues

    My power went out earlier (which happens a lot as I am on a payg meter) and when everything came back on my TV would no longer display my iMac screen. Both devices knew they were connected as when I unplugged the HDMI cable the TV said 'No Cable' and

  • Flash CS3 IDE Scroll bar behavior

    Hello, This behavior was experienced on CS3 Flash, Photoshop, Dreamweaver, at the same time. When I zoom in on anything, the scroll bar forces the screen to the bottom (PSD) or to the far right (FLA). If you attempt to pull the elevator box to the le

  • Connect from Windows through screen sharing (VNC) and get out of full screen mode

    How do you get out of fullscreen mode? I connect to a OS X Lion computer through a Windows computer (which actually also is remote). I use TightVNC software on Windows to connect. It's the only VNC software I am able to connect to OS X Lion with. Tig

  • Configure Mobile BO out of my network

    Hi experts, I have installed BO Mobile 3.1 All work fine if i´m in my private network, but, if i go out my network don´t work, why? I do a redirection of ports with a public IP and ports 6400, 11011, 11711, 8080 and in my mobile client: Mobile server