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);
}

Similar Messages

  • How can I make a row of cells containing 3-digit decimals, who's values resulted from calculations within the spreadsheet, appear as durations of minutes and seconds?

    Row 6 in this spreadsheet is the result of Row 2/Row 3 as evidenced by the formula listed while Cell Y6 selected. How can I make the values in this row appear as durations of minutes and seconds rather than 3-digit decimals? For example, rather than appearing as 9.84 I would like the value of Cell Y6 to appear as 9:50 or 9min 50sec. (obviously .84x60seconds 50 seconds). I tried changing the cell formats from "number" to "duration," but no change is made. Using the "duration" format does however work if I am manually entering the decimal value into the cell rather than allowing it to result from another caluclation within the spreadsheet. Is there a solution to this within Numbers '09? You can see why I would want the "pace" displayed in minutes and seconds. Thanks in advance!
    Ryan

    Hi Ryan,
    You wrote:
    "The problem is that my "Distance" is a row of automatically generated values resulting from ((Row1/60)*Row 6). Changing the format of Row 1 to minutes causes row two to be expressed as a duration, which obviously it shouldn't because it is a distance. The spreadsheet has to be designed so that all I have to manually input on each entry are Row 1 Values (Time) and Row 6 Values (Average Pace). The rest of the cells must be automatically poulated as a result of formulas."
    I'm assuming that where you say "Row 1" in this you mean "Row 2", which is labeled "Time" in the example in the OP.
    In the original post, you presented a formula from cell Y6. Replacing the Header labels in that formula's cell reference with the Addresses of the referenced cells, the formula was:
    Y6: =Y2/Y3
    In this post, you are saying that Y6 contains entered data: "...all I have to manually input on each entry are Row 1 Values (Time) and Row 6 Values (Average Pace).
    Which is correct?
    Regards,
    Barry

  • How can I add a row into a JTable with JButton

    Hi all. I have the following code:
    package gui;
    import db.*;
    import javax.swing.table.AbstractTableModel;
    import java.util.ArrayList;
    public class FoundersTable extends AbstractTableModel{
        private static final int COLUMNS = 8;
        private String columnNames[] = {"��� ����", "���", "�������", "�������", "���������", "��������",
                "����� �� ����������", "������ �� ����, �����"};
        private ArrayList data;
        public FoundersTable(){
            data = new ArrayList();
        public int getRowCount() {
            return data.size();
        public int getColumnCount() {
            return columnNames.length;
        public String getColumnName(int colIndex) {
            return columnNames[colIndex];
        public Object getValueAt(int rowIndex, int columnIndex) {
            return ((ArrayList)data.get(rowIndex)).get(columnIndex);
        public void setValueAt(Object value, int rowIndex, int columnIndex) {
            ((ArrayList)data.get(rowIndex)).set(columnIndex, value);
            fireTableCellUpdated(rowIndex, columnIndex);
        public void addRow(ArrayList neueZeile) {
            data.add(neueZeile);
            int index = data.size() - 1;
            fireTableRowsInserted(index, index);
        public void removeRow(int index) {
            data.remove(index);
            fireTableRowsDeleted(index, index);
        public void removeAllRows() {
            data.clear();
            fireTableRowsDeleted(0, 0);
        public boolean isCellEditable(int rowIndex, int columnIndex) {
            return true;
    }Now in my MainJFrame class I have one button for additing and one button for removing a selected row. How can I add/remove rows with this two buttons.
    Thanks

    No my question is how can I add and remove rows WITH buttons My point was the code is the same. You use the addRow(...) method. Why did you write an addRow(...) method if you aren't going to use it?
    I don't understand your problem. Do you not know how to write an ActionListener?

  • 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 can i make perticular row or perticular cell Editable  of a JTable

    Dear al,
    can u help me by guiding me for the problem of...
    i am having a JTable, in which a (first)column of each row is having a checkbox field.
    If the checkbox is checked then and then i should able to modify the cells in that row where the checkbox is.
    I have created the table with AbstractTableModel of which the isCellEditable(int row, int col) method is overwriten. Whatever return value (true/false) reflects the perticular
    cells becomes editable/non-editable respectively.
    but at run time...(mean the table is created now) and now i want to make the cells editable/non-editable depending on the checkbox value...
    how can i implement it.........
    please suggest.........
    thank you.........

    here is the sample code from tutorial.......
    * TableRenderDemo.java requires no other files.
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import javax.swing.DefaultCellEditor;
    import javax.swing.JComboBox;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.AbstractTableModel;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.TableColumn;
    * TableRenderDemo is just like TableDemo, except that it explicitly initializes
    * column sizes and it uses a combo box as an editor for the Sport column.
    @SuppressWarnings("serial")
    public class TableRenderDemo extends JPanel {
         private boolean DEBUG = true;
         public TableRenderDemo() {
              super(new GridLayout(1, 0));
              JTable table = new JTable(new MyTableModel());
              // table.setEditingColumn(0);
              // table.editCellAt(0, 0);
              table.setPreferredScrollableViewportSize(new Dimension(500, 100));
              // Create the scroll pane and add the table to it.
              JScrollPane scrollPane = new JScrollPane(table);
              // Set up column sizes.
              initColumnSizes(table);
              // Fiddle with the Sport column's cell editors/renderers.
              setUpSportColumn(table, table.getColumnModel().getColumn(2));
              // Add the scroll pane to this panel.
              add(scrollPane);
          * This method picks good column sizes. If all column heads are wider than
          * the column's cells' contents, then you can just use
          * column.sizeWidthToFit().
         private void initColumnSizes(JTable table) {
              MyTableModel model = (MyTableModel) table.getModel();
              TableColumn column = null;
              Component comp = null;
              int headerWidth = 0;
              int cellWidth = 0;
              Object[] longValues = model.longValues;
              TableCellRenderer headerRenderer = table.getTableHeader()
                        .getDefaultRenderer();
              for (int i = 0; i < 5; i++) {
                   column = table.getColumnModel().getColumn(i);
                   comp = headerRenderer.getTableCellRendererComponent(null, column
                             .getHeaderValue(), false, false, 0, 0);
                   headerWidth = comp.getPreferredSize().width;
                   comp = table.getDefaultRenderer(model.getColumnClass(i))
                             .getTableCellRendererComponent(table, longValues, false,
                                       false, 0, i);
                   cellWidth = comp.getPreferredSize().width;
                   if (DEBUG) {
                        System.out.println("Initializing width of column " + i + ". "
                                  + "headerWidth = " + headerWidth + "; cellWidth = "
                                  + cellWidth);
                   // XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
                   column.setPreferredWidth(Math.max(headerWidth, cellWidth));
         public void setUpSportColumn(JTable table, TableColumn sportColumn) {
              // Set up the editor for the sport cells.
              JComboBox comboBox = new JComboBox();
              comboBox.addItem("Snowboarding");
              comboBox.addItem("Rowing");
              comboBox.addItem("Knitting");
              comboBox.addItem("Speed reading");
              comboBox.addItem("Pool");
              comboBox.addItem("None of the above");
              sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
              // Set up tool tips for the sport cells.
              DefaultTableCellRenderer renderer = new DefaultTableCellRenderer();
              renderer.setToolTipText("Click for combo box");
              sportColumn.setCellRenderer(renderer);
         class MyTableModel extends AbstractTableModel {
              private String[] columnNames = { "First Name", "Last Name", "Sport",
                        "# of Years", "Vegetarian" };
              private Object[][] data = {
                        { "Mary", "Campione", "Snowboarding", new Integer(5),
                                  new Boolean(false) },
                        { "Alison", "Huml", "Rowing", new Integer(3), new Boolean(true) },
                        { "Kathy", "Walrath", "Knitting", new Integer(2),
                                  new Boolean(false) },
                        { "Sharon", "Zakhour", "Speed reading", new Integer(20),
                                  new Boolean(true) },
                        { "Philip", "Milne", "Pool", new Integer(10),
                                  new Boolean(false) } };
              public final Object[] longValues = { "Sharon", "Campione",
                        "None of the above", new Integer(20), Boolean.TRUE };
              public int getColumnCount() {
                   return columnNames.length;
              public int getRowCount() {
                   return data.length;
              public String getColumnName(int col) {
                   return columnNames[col];
              public Object getValueAt(int row, int col) {
                   return data[row][col];
              * JTable uses this method to determine the default renderer/ editor for
              * each cell. If we didn't implement this method, then the last column
              * would contain text ("true"/"false"), rather than a check box.
              public Class<?> getColumnClass(int c) {
                   return getValueAt(0, c).getClass();
              * Don't need to implement this method unless your table's editable.
              public boolean isCellEditable(int row, int col) {
                   // Note that the data/cell address is constant,
                   // no matter where the cell appears onscreen.
                   // return false;
                   return true;
              * Don't need to implement this method unless your table's data can
              * change.
              public void setValueAt(Object value, int row, int col) {
                   if (DEBUG) {
                        System.out.println("Setting value at " + row + "," + col
                                  + " to " + value + " (an instance of "
                                  + value.getClass() + ")");
                   data[row][col] = value;
                   fireTableCellUpdated(row, col);
                   if (DEBUG) {
                        System.out.println("New value of data:");
                        printDebugData();
              private void printDebugData() {
                   int numRows = getRowCount();
                   int numCols = getColumnCount();
                   for (int i = 0; i < numRows; i++) {
                        System.out.print(" row " + i + ":");
                        for (int j = 0; j < numCols; j++) {
                             System.out.print(" " + data[i][j]);
                        System.out.println();
                   System.out.println("--------------------------");
         * Create the GUI and show it. For thread safety, this method should be
         * invoked from the event-dispatching thread.
         private static void createAndShowGUI() {
              // Create and set up the window.
              JFrame frame = new JFrame("TableRenderDemo");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              // Create and set up the content pane.
              TableRenderDemo newContentPane = new TableRenderDemo();
              newContentPane.setOpaque(true); // content panes must be opaque
              frame.setContentPane(newContentPane);
              // Display the window.
              frame.pack();
              frame.setVisible(true);
         public static void main(String[] args) {
              // Schedule a job for the event-dispatching thread:
              // creating and showing this application's GUI.
              javax.swing.SwingUtilities.invokeLater(new Runnable() {
                   public void run() {
                        createAndShowGUI();

  • 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 can I get a Row in a JTable?

    I want to get the Last row in a JTable. How can I get it? Thanks.

    something like
    TableModel tm = table.getModel();
    int rows = tm.getRowCount();
    Object col0Value = tm.getValueAt(rows, 0);
    Object col1Value = tm.getValueAt(rows,1);
    ...

  • How Can I Make Several RT Selections Without Window Closing?

    This applies to countless Mac settings in numerous apps and not just the RT settings.
    When I want to change the RT settings, the moment I select one the window/menu closes and I have to click the RT button again to select the second setting and so on.
    Basically I want to keep the window/menu open until I have adjusted/selected all the parameters.
    I have put up with this type of thing happening for nearly 9 years.
    Is this the way it has to be or is there a simple fix I have ben oblivious to for all this time?

    Hi -
    IMHO, the Mac human interface has always been simple:
    Select and Do.
    If the "Do" is a menu choice, the choice is applied and the menu disappears.
    If the "Do" is a call for a Dialog box to make user choices, the menu disappears and the Dialog box opens and remains open until closed by the user.
    Examples:
    Menu Edit > Paste will paste the copy of the clipboard to your document and promptly disappear.
    Menu Edit > Paste Attributes . . . will open a Paste Attributes Dialog box, and the dialog box will need to be closed by the user.
    The way to tell if the menu item is going to perform an action or call for a Dialog Box for more user choices is if the menu item is followed by an Ellipsis ( . . . ).
    Perhaps the best way to accomplish what you want is to use Feedback to ask for an RT Dialog Box in addition to the RT menu.
    MtD

  • How can I make row labels appear on the right

    I am creating a timeline for a web development project in numbers
    I have changed the content scale to get it to fit on two pages (it's illegible on one page) but the tasks are overlaid on the grey column containing row labels
    How can I make the row labels appear on the right side instead of the left side?

    Thanks Badunit - that was a big help
    The counterintuitive part of this whole exercise is that to get the timeline printed as I want, I've got to leave the column representing Week 8 blank
    Print View:
    Normal View:
    Numbers has got Excel beat in so many ways, but there are some baffling bits to it!

  • How can I make the rolumn and row headers appear on the printed sheet?

    I am working in Numbers'09. I want to print out my chart with the column letters and row numbers showing.
    How can I make the rolumn and row headers appear on the printed sheet?

    g,
    Those annotations are called "Labels", and they are only visible during editing when a cell selection is made within the table. If you need to have the labels on your final output, you can create labels in Text Boxes and position them adjacent to the table.
    Jerry

  • I have created a spreadsheet on numbers for ipad with a list of customers as a drop down menu. How can i make their address appear underneath when i select the customer?

    I have created a spreadsheet on numbers for ipad with a list of customers as a drop down menu. How can i make their address appear underneath when I select the customer?
    iselect the customer?

    Hi bazza,
    We won't be able to put the address from a formula into the same cell that you enter the customer's name. We can put the address in the cell under the customers name.
    First let's take James advice and concatenate the address in the address table.
    Here is the formula in G2
    =CONCATENATE(B2&"
    ",C2&"
    ",D2&"
    ",E2)
    It shows this way because after I clicked on B2 and typed [&"] (no brackets) I typed option-return
    This gives you your new line. Then I typed the closing ". I repeated this for the rest of the address.
    Next we want to bring this to your order sheet. I prefer using the two formulas OFFSET and MATCH instead of VLOOKUP.
    base tells OFFSETwhere to start counting from. Click A1.
    row-offset is for the row. we will use MATCH() -1 to give us the row.
    What MATCH does is give you the row number where something is found and you can specify an exact match. I usually construct the MATCH formula first and then cut and paste it into OFFSET. MATCH looks like this: MATCH(A2,Table 1::A,0). A2 is what we are looking for, Table 1A::A is where we are looking (the entire column A), and 0 means we want an exact match. Can you see it inside the OFFSET formula? Notice that we had to subtract 1 from its result.
    column-offset tells OFFSET which column A=0 so we want 6.
    we ignore "rows", "colomns" we don't need them.
    If this seems like too much, just break it down into small pieces.
    quinn

  • I synced two of my email accounts via gmail's POP3 thing. But now my iphone's gmail inbox shows a random selection of emails (not most recent ones that are in my inbox). How can I make my iphone inbox match what I see when I log on using a PC?

    I synced two of my email accounts via gmail's POP3 capabilities. But now my iphone's gmail inbox only shows a random selection of emails (i.e. right now it is May 31, 2013 but the emails in my inbox are a couple from Nov 12, a few from Oct 12, and then some way older than that and so on.When I log into my gmail from a computer, I see all my emails in the logical, standard order. How can I make my iphone inbox match what I see when I log on using a PC?

    If you're trying to decide between using POP and IMAP, we encourage you to use IMAP.
    Unlike POP, IMAP offers two-way communication between your web Gmail and your email client. This means when you log in to Gmail using a web browser, actions you perform on email clients and mobile devices (ex: putting mail in a 'work' folder) will instantly and automatically appear in Gmail (ex: it will already have a 'work' label on that email the next time you sign in).
    IMAP also provides a better method to access your mail from multiple devices. If you check your email at work, on your mobile phone, and again at home, IMAP ensures that new mail is accessible from any device at any given time.
    Finally, IMAP offers a more stable experience overall. Whereas POP is prone to losing messages or downloading the same messages multiple times, IMAP avoids this through two-way syncing capabilities between your mail clients and your web Gmail.
    That is from the page that you linked- does highlighted part of message ring a bell?

  • How can I make new pages software spellcheck a selection like in appleworks?

    How can I make new pages software spellcheck a selection like in appleworks?
    I just installed pages a new download from apple store.
    1. I cannot find any way to activate a spellcheck for a selection in a document.
    2. I want to elemenate a red line under a word it doesn't like the spelling of.

  • When I have many tabs open, & I am viewing the 1st one in the row of tabs, how can I make ctrl+T open tab next to it instead of down at the end of all the tabs?

    If, for example, I have 50 tabs open, and I happen to be working on the very first tab out of the long row of tabs (tab #1 out of 50 total tabs)....if I suddenly need a new tab next to the one I'm on so that I can do something else related to what I am doing on my current tab's website, pushing ctrl+t opens up the new tab clear down at the very end of the long row of tabs (i.e., the new tab would be tab #51). How can I make the new tab open up right beside the one I'm working on at the moment?

    You would need an extension to achieve this
    You can look at this extension:
    *Tab Utilities Lite: https://addons.mozilla.org/firefox/addon/tab-utilities-lite/

  • "I have to manually select pop up blocker everytime i open firefox. how can i make it permenent?'

    i have to manually select pop up blocker everytime i open new firefox window. How can i make this arrangement permenent?
    == This happened ==
    Every time Firefox opened
    == a week ago

    See http://kb.mozillazine.org/Preferences_not_saved

Maybe you are looking for