JTable - make 1st row selected by default

hi,
i have a JTable, how can i make the 1st row selected by default?
thanks.

try table.getSelectionModel().setSelectionInterval(0, 0)
You need to check and make sure there is at least one row in the table before you do this, otherwise exception will throw.
Hope this will help.

Similar Messages

  • How can I make a row selected in JTable?

    I want to make a row selected and highlighted in JTable programmatically.
    But, I couldn't find method like setSelected(int row).
    How can I do this?

    try this ....
    private void makeRowVisible(JTable table, int row) {
         java.awt.Rectangle cellRect = table.getCellRect(row, 0, true);
         if (cellRect != null) {
              table.scrollRectToVisible(cellRect);
    }

  • Make html:checkbox selected by default depending upon bean value --struts

    Hi all,
    I have a doubt regarding the html:checkbox .
    I have the following code in my jsp.
    I am giving it inside logic:iterate tag and fetching the value from session scope.
    <html:checkbox property ="readchk" value ="read" indexed="true" onclick="return assignme(this.value,this.checked,'s')"/>
    How to make this checkbox selected by default.
    "readchk" (bean) is in my ActionForm, it has been been assigned either
    0 or 1 .
    I want to make the checkbox selected by default if the readchk is 1
    and the checkbox not selected if the readchk value is 0.
    Could anybody please help me out in fixing this problem.
    Thanks
    Parvathi

    If u give the value for ur check box in the action form it wld be checked!!
    regards
    Shanu

  • How can I make JSF checkboxes selected by default?

    Hi everyone,
    I have a problem in setting default value for checkboxes. I use them in a table. tableRowGroup's sourceData property is a list data provider. In the page bean I have the following code to select rows:
    private TableSelectPhaseListener tablePhaseListener = new TableSelectPhaseListener();
        public void setSelected(Object object) {
            RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
            if (rowKey != null) {
                tablePhaseListener.setSelected(rowKey, object);
        public Object getSelected(){
            RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
            return tablePhaseListener.getSelected(rowKey);
        public Object getSelectedValue() {
            RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
            return (rowKey != null) ? rowKey.getRowId() : null;
        public boolean getSelectedState() {
            RowKey rowKey = (RowKey)getValue("#{currentRow.tableRow}");
            return tablePhaseListener.isSelected(rowKey);
        }I received a list of objects from a service using list data provider and use checkboxes to select them. Then I get the selected checkboxes in the action method of the page bean using
    RowKey[] selectedRows = getTableRowGroup1().getSelectedRowKeys(); What I want to do is to set all the checkboxes as selected by default. Normally, this is performed by assigning the same values to selected and selectedValue properties of the checkbox component. But, in my case this is not applicable since we take advantage of getSelected() and getSelectedValue() methods in the pagebean. Properties of my checkbox component are as follows:
    <ui:checkbox binding="#{MyPage.checkBox1}"
                                                        id="checkBox1" selected="#{MyPage.selected}" selectedValue="#{MyPage.selectedValue}"/>I cannot assign same values to selected and selectedValue. Can anyone help me to make these checkboxes selected as it is rendered?

    Hi Fanado,
    In Finder, click once on an Excel document then Get Info (command i)
    Choose Open with: Numbers
    Then Change All... to make Numbers the app for all Excel documents.
    The same for Word and Powerpoint
    Regards,
    Ian.

  • How to set Datagrid 1st row selected

    I want to set 1st row as selected = true as default in
    datagrid after loading the form which out clicking on any item i
    want to set the 1st row as selected, how can i achieve this.
    Thanks in advance

    Thanks for your help,
    Here's the code which i wrote
    datagrid creationComplete="changeColor();"
    [code]
    private function changeColor():void
    dgrid.selectedIndex = 0;
    dgrid.setStyles("selectionColor","#800f3e");
    [/code]

  • Make second workset selected by default

    Hi,
    I have a pcd role as shown below.
    Role A                     (visible : yes)
      |
      --------Workset A    (Entry point : yes; visible :  yes)
              |
              ------------------Folder A (visible : yes)
                                |
                                --------------------Workset 1  (visible : yes; leaf folder : yes)
                                                    |
                                                    -----------------------Page 1 ( default entry to folder : false)
                                                    Workset 2  (visible : yes; leaf folder : yes)
                                                    |
                                                     -----------------------Page 2 ( entry point : yes; default entry to folder : true)
                                                   Workset 3  (visible : yes; leaf folder : yes)
                                                    |
                                                     -----------------------Page 2 ( default entry to folder : false)
    Along with this, I want to mention that it is EP 7.4. And I have tries by changing the property 'Clicking folder name launches first node' to false, but no effect.
    I want the role to open with Page 2 as the first screen.
    But it is not working.
    Please help.
    Thanks
    Arindam

    If u give the value for ur check box in the action form it wld be checked!!
    regards
    Shanu

  • About row selection in JTable

    This is also a question about JTable, when type the key "ENTER", the row selection will focus on the next line, how can I stop this default action? Can I make the default action of pressing "ENTER" to be activate a cell in the JTable to editing state?
    Thanks for any help.

    Sorry, I need to ask for help again, yes, in your case, the method works,
    but I am afraid this method does not help me, because I don't know HOW TO MAKE THE F2 FUNCTION in my case.
    I use the method you recommend, and yes I can stop the default response of pressing ENTER, it means when I stroke ENTER in my table, the selection won't go to the next line, but it just up to my half purpose, how can I use Enter to editing a cell then? My silly question is I even don't know how to make F2 works?

  • JTable and getting the selected Row to display

    Hi,
    I am pasting a code below, in this code i am highlighting one row when loading the table, but since this Row is last, it does not get displayed unless the user scrolls down,
    how can i make this row displayed, when i load the table first
    I m using jdk1.4.1
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class TestTableSelect extends JFrame
         public TestTableSelect(String input)
         super("Table select");     
         this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         getContentPane().add(getTable(input));
         setSize (650, 250);
    setVisible(true);
              private JPanel getTable(String input)
              JPanel panel = new JPanel();
              panel.setLayout(new BorderLayout());
              panel.setPreferredSize(new Dimension(100, 250));
              Vector data = dataVector();
              Vector column = headVector();
              JTable table = new JTable(data, column);
              table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
              table.getTableHeader().setReorderingAllowed(false);
              table.getTableHeader().setResizingAllowed(false);
              table.setSelectionBackground(Color.cyan);
              table.setRowSelectionInterval(0,getSelectedIndex(data, input));
              javax.swing.JScrollPane scrollPane = new JScrollPane(table);
              table.setPreferredScrollableViewportSize(new Dimension(650, 150));
              panel.add(scrollPane, BorderLayout.NORTH);
              return panel;
         private Vector dataVector()
              Vector data = new Vector();
              for ( int i = 0; i < 20; i++)
                   Vector data1 = new Vector();
                   data1.add("ABC");
                   data1.add("This is testing");
                   data1.add(" ");
                   data1.add(" ");     
                   data.add(data1);
                   Vector data1 = new Vector();
                   data1.add("DEF");
                   data1.add("This is testing");
                   data1.add("1");
                   data1.add("1");     
                   data.add(data1);
              return data;
         private Vector headVector()
              Vector column = new Vector();
              column.add("Name");
              column.add("Description");
              column.add("Default");
              column.add("Firm");
              return column;
         private int getSelectedIndex(Vector data, String key)
              for(int i = 0; i < data.size(); i++)
                   Vector data1 = (Vector)data.get(i);
                   if(((String)data1.get(0)).trim().equalsIgnoreCase(key))
                   return i;     
              return 0;
         public static void main(String args[])
         new TestTableSelect("DEF");

    table.scrollRectToVisible(table.getCellRect(table.getSelectedRow(), 0, true);Put this after your table.setRowSelectionInterval(0,getSelectedIndex(data, input)) .
    //David

  • Change JTable's row color on row selection

    Hello!
    Everywhere I've looked they're only explaining how to draw rows in different colors WHEN THE TABLE IS BEING CREATED, via prepareRenderer.
    But that is not what I am looking for. What I want is to actually change the row's color after the table has been drawn/rendered/whatsoever. For instance, when the user clicks on that row. The default behaviour is for the row to become blueish, but, when the user selects another row, the first selected row turns back to white. I would like to prevent that from happening. I want the row to become FIRE RED when the user clicks on it, and I want the row to remain like that for good, even when the user selects a different row. Do I make any sense here? :-)
    Thank you for your time and future suggestions.

    Everywhere I've lookedApparently you didn't look in the Swing forum, because thats where Swing related questions should be posted.
    but how do I assign a cell renderer to an entire row/table ?The easiest way is to use the prepareRenderer(...) method you have already found. My "TablePrepareRenderer" class (which you can find by searching the Swing forum) shows you how to do this.
    You will note that the color of the row is determined by data in the table. So all you need to do is add another column in the TableModel that contains the information you need to determine the row color. That column can be removed from view in the table by removing the TableColumn from the TableColumnModel.

  • How to make first row as selected in af:table

    Hi,
    I am using JDeveloper 11.1.1.4 and ADF-BC in my application.
    In all the pages across my application we have multi select enabled for the table[af:table].
    But when the pages are displayed,the first row is not selected by default.
    My requirement is to display first row as selected across all the tables in my app.
    I have the selectionListenerset as for example selectionListener="#{bindings.RSCMapVO2.collectionModel.makeCurrent}" in all the pages.
    Please suggest on how to make first row as selected.
    Regards,
    Praveen

    Hi
    Put these codes in your selection listner method(You have to define a selectionListner method in your backing bean and put this code segment
    (Special thanks go to Franks how posted this code segment. threadID=1089583)
    RichTable yourTable = (RichTable) selectionEvent.getSource();
    //the Collection Model is the object that provides the structured data
    //for the table to render
    CollectionModel yourTableModel = (CollectionModel) yourTable.getValue();
    //the ADF object that implements the CollectionModel is JUCtrlHierBinding. It
    //is wrapped by the CollectionModel API
    JUCtrlHierBinding yourTableBinding = (JUCtrlHierBinding) yourTableModel.getWrappedData();
    //Acess the ADF iterator binding that is used with ADF table binding
    DCIteratorBinding yourTableIteratorBinding = yourTableeBinding.getDCIteratorBinding();
    //the role of this method is to synchronize the table component selection
    //with the selection in the ADF model
    Object _selectedRowData = yourTable.getSelectedRowData();
    //cast to JUCtrlHierNodeBinding, which is the ADF object that represents
    //a row
    JUCtrlHierNodeBinding nodeBinding = (JUCtrlHierNodeBinding) selectedRowData;
    //get the row key from the node binding and set it as the current row in the
    //iterator
    Key rwKey = nodeBinding.getRowKey();
    tableIteratorBinding.setCurrentRowWithKey(rwKey.toStringFormat(true));
    Thanks
    Padma

  • Multiple Row selection In JTable

    I am working with JTable and JList, I can transfer element from table to list and vise versa on clicking on button, my problem is that when i transferred element to either of them that should be selected. i can also transfer multiple item at time and doing sorting with table if i am adding element of 1st row and last row of table, both the rows should be selected.
    Any thoughts!!!!!!!!!!!
    ThnX
    Prashant_SDN

    Thnx for response and selection in list is done sucessfully.
    I have one additional query, I am transfering element from list to table and did use sorting so rows did not get added after existing row of table but added as per sorting.
    so how do i get the index of newly added row after sorting.
    Any thoughts!!!!

  • JTable row selection with tab key

    Helo.
    I'm having a problem selecting rows in a JTable. The JTable is with single row selection and without column and cell selection. When I press <tab> the selection changes to another cell, and I wanna it to change to the other row of the table, can anyone help me? I think this is a easy one and I haven�t found a way to do it. I�m using JBuilder for the development.

    The default Action for the Tab KeyStroke is to move focus to the next cell.
    The default Action for the Enter KeyStroke is to move focus to the next line.
    So this functionality is already available in JTable by default.
    If you want to Tab Key to work the same way as the Enter Key then you need to map the Tab Key to use the Action assigned to the Enter Key.
    This [url http://forum.java.sun.com/thread.jsp?forum=57&thread=505866]posting shows how you can reassign an Action for a given KeyStroke.
    For more information on this topic read this section from the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to Use Key Bindings.

  • How do you make the rows in a JTable uneditable.

    Hi
    Does anyone knows how to make the rows in a JTable uneditable.
    --kirk                                                                                                                                                                                   

    Hi,
    implement a TableModel, e.g AbstractTableModel and use it to initialise
    your table. (JTable aTable = new JTable(myAbstractTableModel))
    And if you want your table to be editable implement isCellEditable() in your table model, and let it return true. If not let it return false, or don't implement it att all.

  • How to make row selection by checkbox in ADF table

    hello,
    using jdev11g TP4 , fusion web application
    when i drag my view object as ADF table into jsf page,
    i want to know how to make row selection by checkbox
    thanks
    greenApple
    Edited by: greenApple on Nov 10, 2008 11:33 AM

    Hi,
    the tree component has changed compared to 10.1.3. You no longer have a tableSelectmany component that renders as checkboxes. Instead you use the ctrl key and select the table rows
    Frank

  • How to make a row enabled for lead selection and make other Rows disabled?

    Hi,
    What I require is:
    In a webdynpro table , which can have multiple rows, I want to make the rows which are retrieved fom backend as disabled for selection.
    And when I add a new row (using an ADD functionality) , this newly added row should only be enabled for lead selection.
    The Table property "enabled" can be assigned a context , and can be used to control the disabling of whole table.But then if I add the new row to this table, even this will be disabled.
    I can set lead selection to a the new row, but if the whole table is disabled, this won't work.
    Please suggest a solution for this.
    Thanks,
    Richa

    Do not set the enabled flag to the whole table but to the editors of each column. Bind the enabled property to a calculated boolean flag in the data source node. In the get method of this flag add a code that will make the editor enabled only if it belongs to the lead selection element.
    Now do not allow the selection of rows in the table (there is a property for this, perhaps is named rows selection I don't remember well now), but change the lead selection of the data source node to the desired element when you add the element programatically.
    Hope it helps.

Maybe you are looking for

  • 6980 wont stop printing report pages

    Help-My 6980 Deskjet has recently started printing report pages after every print job.  It seems to go into quiet mode on its own, prints the job and then continues to print multiple report pages until I turn it off.  Of course I'm out of warranty so

  • How To Set Terminal Type in Solaris 10 Jumpstart?

    Hi all, I'm installing Solaris 10 via jumpstart, and I'd like to set the terminal type for the console to be vt100 by default. I've tried setting the terminal type to vt100 in sysidcfg, with a line: terminal=vt100 but this has no effect (and never ha

  • Multiple displays, external and airplay

    I have a macbook air that I am using for a church presenation computer. We have Apple TV that is connected to our projecter, I would like to use that for the output display for my presentation. I also have an external monitor that I would like to use

  • Where are the diagnostic LEDs in the imac g5 isight?

    I have looked everywhere, including under the right speaker. Have removed the display ... they are nowhere to be found. But I know they're hidden here somewhere!

  • Can't download iTunes

    When attempting to download iTunes I get a message that says "Service 'Apple Mobile Device' (Apple Mobile Device) failed to start. Verify that you have sufficient privileges to start system services." How do I fix this and download iTunes to my compu