JRadioButton in JTable can't set default selection

Guys, I need your help in here.
Basically, I want to have a JTable that will have a JRadioButton in one of its columns.
Furthermore, upon loading the table, I want the radiobutton on the first row is selected as default.
Below are my codes for the renderer, editor, and the part of the main code itself:
public class RadioButtonEditor extends AbstractCellEditor implements TableCellEditor
    private JRadioButton _button = new JRadioButton();
     * The constructor. Used to create new RadioButtonEditor object
     * @param checkBox - given JCheckBox
    public RadioButtonEditor()
        this._button.addActionListener(new ActionListener()
            public void actionPerformed(ActionEvent e)
                fireEditingStopped(); 
    @Override
    public Component getTableCellEditorComponent(JTable table, Object value,
            boolean isSelected, int row, int column)
        if(value == null)
            return null;
        this._button.setSelected(isSelected);
        return this._button;
    @Override
    public Object getCellEditorValue()
        return this._button.isSelected();
public class RadioButtonRenderer extends JRadioButton implements TableCellRenderer
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column)
        System.out.println("MASUK: " + isSelected);
        if (value==null)
            System.out.println("1");
            return null;
        System.out.println("2");
        this.setSelected(isSelected);
        return this;
//Part of the main code
this._mainTable = null;
        DefaultTableModel dm = new DefaultTableModel();
        dm.setDataVector(this._myManager.getCreditListTableContents(this._dataStartIndex), this._myManager.getCreditListHeaderList());
        ButtonGroup buttonGroup = new ButtonGroup();
        for(int i=0; i<dm.getRowCount(); i++)
            JRadioButton temp = (JRadioButton)dm.getValueAt(i,0);
            buttonGroup.add(temp);
        this._mainTable = new JTable(dm){
            @Override
            public boolean isCellEditable(int row, int column)
                    if(column == 0)
                        return true;
                    else
                        return false;
            @Override
            public TableCellRenderer getCellRenderer(int row, int column)
                TableCellRenderer renderer = super.getCellRenderer(row,column);
                switch(column)
                    case 1: case 2: case 4: case 5: case 6: case 7: case 8:
                        ((JLabel)renderer).setHorizontalAlignment(SwingConstants.CENTER);
                        break;
                    case 3: case 9: case 10:
                        ((JLabel)renderer).setHorizontalAlignment(SwingConstants.LEFT);
                        break;
                return renderer;
        this._mainTable.getColumn(this._myManager.getCreditListHeaderList()[0]).setCellRenderer(new RadioButtonRenderer());
        this._mainTable.getColumn(this._myManager.getCreditListHeaderList()[0]).setCellEditor(new RadioButtonEditor());
        JRadioButton tempBttn = (JRadioButton)this._mainTable.getModel().getValueAt(0,0);
        tempBttn.getModel().setSelected(true);But still I can't make it.
Really need help guys.
Thnx a lot
-Peter

in this form works as I excepted
import java.awt.Component;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.border.EmptyBorder;
import javax.swing.plaf.UIResource;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellRenderer;
public class JRadioButtonTableTest {
    public static void main(String args[]) {
        DefaultTableModel model = new DefaultTableModel(new Object[][]{{Boolean.TRUE}, {Boolean.FALSE}, {Boolean.TRUE},
                    {Boolean.FALSE}, {Boolean.TRUE}, {Boolean.FALSE}, {Boolean.TRUE}}, new Object[]{"Boolean"}) {
            private static final long serialVersionUID = 1L;
            @Override
            public Class getColumnClass(int col) {
                return Boolean.class;
        JTable table = new JTable(model);
        table.setDefaultRenderer(Boolean.class, new BooleanRenderer());
        JFrame f = new JFrame("JRadio Button Renderer Test");
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.add(new JScrollPane(table));
        f.setPreferredSize(new Dimension(100,200));
        f.setLocation(150, 200);
        f.pack();
        f.setVisible(true);
    static class BooleanRenderer extends JRadioButton implements TableCellRenderer, UIResource {
        private static final long serialVersionUID = 1L;
        private final Border noFocusBorder = new EmptyBorder(1, 1, 1, 1);
        BooleanRenderer() {
            super();
            setHorizontalAlignment(JLabel.CENTER);
            setBorderPainted(true);
        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if (isSelected) {
                setForeground(table.getSelectionForeground());
                super.setBackground(table.getSelectionBackground());
            } else {
                setForeground(table.getForeground());
                setBackground(table.getBackground());
            setSelected(value != null && ((Boolean) value).booleanValue());
            if (hasFocus) {
                setBorder(UIManager.getBorder("Table.focusCellHighlightBorder"));
            } else {
                setBorder(noFocusBorder);
            return this;
    private JRadioButtonTableTest() {
}JTable is sensitive to EDT at all,
javax.swing.SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                table.setValueAt(Boolean.FALSE, row, column); // or TRUE
        });Edited by: mKorbel on 23.3.2011 9:22

Similar Messages

  • How to set default selection in html:radio

    hai
    how to set default selection in <html:radio>.

    No it won't help.
    You can't set a value into an <input type="file"> control at all. The user has to put values in themselves.
    The reason behind this is security. If the programmer could put any value they liked in there, you could upload any file at all from a users computer without their intervention. eg C:\windows\system32\passwords.txt
    Bottom line: you can't put a default value into the input type="file" control.
    And a good thing too ;-)

  • The default priority setting in Mail is set to "normal"  and is causing emails I send to be sent with red priority flag. How can I set default priority to low = no flag?

    The default priority setting in Mail is set to "normal"  and is causing emails I send to be sent with red priority flag.
    I have found the flags to reduce the priorty level manually to "low Priorty", but how can I set default priority to low = no flag?
    Thank you for advising,

    Try deleting the .plist.
    Quit the application.
    In Finder hold down the option/alt key while selecting the Go menu item. Select Library. Then go to Preferences/com.apple.mail.plist. Move the .plist to your desktop.
    Open the application and test. If it works okay, delete the plist from the desktop. 
    If the application is the same, return the .plist to where you got it from, overwriting the newer ones.
    If you want to make your user library permanently visible, run the below command in Applications/Terminal.
    chflags nohidden ~/Library/
    You will need to do that after any updates.

  • In Initial View, can you set defaults for Navigation tab, Page layout, and Magnification?

    Adobe Acrobat 9 Pro V9.4.0
    Win7 Pro x64
    Problem: In Initial View, can you set defaults for Navigation tab, Page layout, and Magnification?
    Every time Acrobat scans a document, I have to go to Initial View to set Navigation tab, Page layout, and Magnification. It does not remember the settings I last used.
    Thanks in advance.

    See my response to this post

  • How can I set default values for Allocate Mode in AO config?

    Hi, How can I set default values for allocate mode in AO config. To be specific, in the attached vi, I need to set the Allocate Mode in AO Config to 'Use FIFO Memory (6)' if the value inside my case structure is false and to 'no change (0)' if the value inside the case strusture is true.
    Solved!
    Go to Solution.
    Attachments:
    generateWaveformFIFO.vi ‏15 KB

    Create two constants for the Allocate Mode input (right click > create > constant). Place one in the true case of the case structure, and place the other one in the false case. Wire them to the same tunnel (border of the case structure), then wire the tunnel to the Allocate Mode terminal of the AO Config. I don't have Traditional DAQ installed, but that should do it.
    Misha

  • How to set default selected checkbox in af:tableSelectMany /

    Hi,
    I am new to ADF technology, I am using JDev 10..3g.
    I want to set the checkbox as default selected for particular rows.
    but I don't know how to set default selected checkbox in <af:tableSelectMany />
    Is there any way to do this using ADF<af:tableSelectMany />
    Thanks,
    Mohammed

    Hi Jeroen,
    Thanks for reply. but the problem is that I am getting data from database and based on some flag I need to select checkbox while page is loading first time.
    at that time the table is null as till now it not rendered. and when its rendered it means page is displayed now.
    just before display I need to set checkbox as selected.
    I don't want to do like this (when user is pressing any command button then only is should update checkbox selection).
    Thanks,
    Mohammed.

  • How can I set default printer options on an iMac for an HP pro 8500 printer to print in draft mode?

    How can I set default printer options on an iMac for an HP pro 8500 printer to print in draft mode?

    When you use the Canon driver, the 2 sided printing is set in a different location. There is an entire menu dedicated to it (at least on my mx892). The printer dialog box has a menu selector in the middle of the screen (I think it says "layout" by default). If you click on it, you will see the duplexing options at the bottom. Much more flexibility than the single checkbox available with "airprint". The interface is unusual (at least for me) but you can pre-set up many different configurations (Fast Duplex, Fine Single-sided, B&W, Photo, etc etc.)

  • HT1677 Where can you set default in Safari to view as web page instead of Mobile Version?

    Where can you set the default setting in Safari to open page as web page instead of Mobile Version on iPad running iOS6.01?

    And, to make it even more fun, sometimes a website changes how it deals with Safari Mobile. A website that treated it like a desktop browser suddenly starts treating it like a cell phone. Just to mess with you. Or push an app.
    Best of luck.

  • How can we set default value within html:file

    Hai,
    To set default value to text box i use the following code. It works well.
    <html:text property="modifyserverdesc" value="<%= serverDesc%>" styleClass="text" size="38"/>But for file i use the code
    <html:file styleClass="file" property="modifyserverimgfile" value="<%= serverImage%>" size="40"/>It doesn't display value. What is problem here?

    Hi,
    guess that one option in a RowImpl would be to check if the attribute is null or if the attribute value can be found in the VO that populates the list. If first is true or seconds false (cannot be found) you return the first value of the VO, making it the current attribute value
    Frank

  • Can we set default value to dynamic parameter?

    <font size="3"><font face="Times New Roman">Hi,</font></font><font size="3"><font face="Times New Roman"><span> </span>I am using BO XI and CR XI.</font></font><font size="3"><font face="Times New Roman"><span> </span>I want to set default value for dynamic cascading parameters as &#39;ALL&#39; when i open report in BO Xi INFO view.</font></font><font size="3"><font face="Times New Roman">I think is not possible.</font></font><span style="font-size: 12pt; font-family: &#39;Times New Roman&#39;">can anybody know solution for this. </span>

    Hi,
    I cannot imagine why you would want to do this. The nextvalue from sequence would just the next available number from the sequence, the numbers wouldn't necessarily even be sequencial. So not very useful as a parameter to a report.
    Rod West

  • Can I set default to always open a link in a new window, as opposed to a new tab?

    Can I set a default to always open a link in a new window, rather than a new tab?

    No, not to '''''always''''' open a link in a new window. Whether a link opens in the same window or a new window depends on the the page creator specifying ''new'' or ''blank'' for that link. ''Firefox can divert the new/blank window to a Tab instead, which is the default setting.''
    If you don't want tabs when a new/blank window is specified, deselect the pref for ''' Open new windows in a new tab instead''' in Tools > '''Options > Tabs'''

  • Can't set default java for Mozilla in java control panel

    OK. It was fine before installation of SE 6u5. Now Sun java works ok in IE7 but not in Firefox 2.0.0.8. THe problem is obviously in the java control panel that sun java is set as default java for MS IE, but not Mozilla. Here is my question:
    I used to be able to tick BOTH IE and Mozilla. But now, when I tick Mozilla, it accepts but after I click yes to close the control panel and open it again, the tick i just made disappears. (So, it means not accepted as a default java) I did make new installation of Firefox for other reasons. Could it be that something has been messed up by both installations. I have tried to remove the deployment.properties and install JRE 1.6.0_5 again while Firefox is already there, but in vein. Thre is another problem that may be related. I can't use the installer downloaded from the internet. I have to use the installer available in the Documents and Settings\administrator\application data\sun\java\jre1.6.0_05 to install jre1.6.0_5.
    Environment: Windows XP pro SP2 with up-to-date Windows updates. Sun java installed: JRE 1.4.2_17, JRE1.6.0_5, and JDK 1.5.0_15.
    I need help to know what can I do to make sun java woking with my Firefox again.... Another question: can i uninstall the JRE 1.4.2_17 since I have now JRE 1.6.0_5?
    Thanks in anticipation.

    You cannot set a default value for this attribute, because by default Identity Sync sets useraccountcontrol to 512.
    You can find this default value in the configuration registry (under the ou=services tree on your configuration directory server) and change it to 514. Make sure you restart the Identity Sync services after you update the value.
    Bertold

  • Can you set default tabs to open in the finder?

    Hi, I love the new "tabs" feature in the finder. I use Bootcamp and have a partitioned drive, so on the Mac side, I like to keep one tab the "videos" folder of my windows drive open so I can easily view files without having to restart my computer and open Windows. Is there a way to set Finder to ALWAYS have this tab open and the other tab to the local "All my files"?

    Not that I'm aware of.
    You can set it so the Finder always opens with (or opens a new tab with) a specific location, including "All my Files."
    However, you can't set Finder to automatically open with multiple tabs, each with a different default view.  It's a good feature request.

  • Can not set default page

    I cant set default page. It keeps reverting to: http://search.jzip.com/

    #Uninstall jZip (or Windows jZip or Windows jZip Toolbar) from Control Panel > Add or Remove Programs.
    #Open Windows Explorer
    #*Navigate to the C:\Program Files\jZip Toolbar folder
    #*Double-click uninstall
    #*Delete the Windows jZip Toolbar folder.
    #In Firefox, remove the Add-on if it is there
    #*Choose Add-ons > Extensions.
    #*Select the jZip Toolbar entry '''''if it's there''''' and click the Uninstall button.
    #*Close the Add-ons Manager tab/window
    #In Firefox, reset preferences
    #*Type '''about:config''' in the address bar and press Enter.
    #*If you see a warning, accept it (promise to be careful)
    #*Filter = jzip
    #*In results in the bottom panel, right-click each entry and choose Reset.
    #Restart Firefox.
    There should have been options during the jZip installation; see image below.
    An excellent free application to replace jZip (and the one that I have used for a very long time) that does not install all the "extras" is 7zip:
    *http://www.7-zip.org/
    '''If this reply solves your problem, please click "Solved It" next to this reply when <u>signed-in</u> to the forum.'''
    Not related to your question, but...
    You need to update some plug-ins:
    *Plug-in check: https://www-trunk.stage.mozilla.com/en-US/plugincheck/
    *Shockwave Flash (Adobe Flash or Flash): [https://support.mozilla.com/en-US/kb/Managing%20the%20Flash%20plugin#w_updating-flash Updating Flash in Firefox]

  • *Can I pass default Selection dynamically for Drill Down Charts*

    Hi
    I am having Charts with Drill Down tab and I am currently having to select a value for the Default Selection Combo Box while saving the chart.
    I want to be able to update this default selection depending upn data coming from the XML / Webservice. Is there a way to update the Default Selection dynamically ?
    Please let me know if anyone has come across this.
    Thanks,
    Rahul
    Edited by: Rahul Modey on Sep 2, 2008 5:15 PM

    Hi Rahul,
    Drill Down > Default Selection > Series/Item may not be filled dynamically.  They must be selected manually.
    Good Luck.

Maybe you are looking for

  • Ipad mini cookies issues!!

    When I try to access the internet at my current location, I am promted to provide a user name and password through a web site. When i get to the point where the web site should come up, I get a message asking me to enable cookies. I have done so and

  • Connect ipad mini toBose Soundlink mini

    If I connet my ipad to the bose soundlink mini speaker can i buy a charger for the speaker in the car

  • Field Validations

    when i do the field validations, if i get any mismatched text  in that field , how could i catch that error?

  • Send all the pdf with mail

    Hello! In my pdf's file, i have a button that send a xml file with the pdf's content, but i need to send all the pdf with mail, i need to send a .pdf file with mail, not an xml. Is it possible? Thank you

  • Iweb: Why do navigation bar page links not work live when published?

    Why do the navigation bar page hyperlinks not work when site is published? There are no objects or boxes over. Works fine until published live. Help!!!