1. How to get the contents of the selected JTable row? coderanch.com |
2. JTable - Selected row coderanch.comhallo , I am working with 2 JTables.The tables are having parent-child realation and for each row in parent table,respective record is displayed in child table. Initially in child table i am showing record for the first record in parent table.For this i want the first row of parent table to be set selected initially. Can anybody guide me on these ... |
3. JTable - selection of a right-click coderanch.com |
4. JTable - selecting a row after a right click from the mouse coderanch.com |
5. JTable.getSelectedRow() returning -1 when cell is selected coderanch.comHello, I imagine it's my renderer(??), but not sure why -- when I call JTable.getSelectedRow() (or for that matter, getSelectedColumn()), if a full row isn't selected, it will always return -1. But I need the row to be returned correctly even when just a cell is selected. Below is a clip of my cell renderer. Advice is appreciated! Thanks! public class ... |
6. cell selections in JTable coderanch.com |
7. JTable and Custom TableCellRenderer - selection problem coderanch.com |
9. Selecting cells in JTable coderanch.comclass MyTableModel extends AbstractTableModel { Vector columnNames = null; Vector data = null;; public MyTableModel( Vector myData, Vector columns ) { this.data = myData; this.columnNames = columns; } public int getColumnCount() { return columnNames.size(); } public int getRowCount() { return data.size(); } public String getColumnName(int col) { return columnNames.get(col).toString(); } public Object getValueAt(int row, int col) { return data.get(row); } public ... |
10. commit data in selected row JTable coderanch.com |
11. How to select a row in a Jtable? coderanch.com |
12. Selecting cells in JList coderanch.com |
13. Help me to use Jtable selection please.... coderanch.comhi from the table A first get the selected rows int [] rowsSelcted=normTable.getSelectedRows(); then remove rows from the model as javax.swing.table.DefaultTableModel model =(javax.swing.table.DefaultTableModel)normTable.getModel(); for(int num = 0;num |
14. to add new row with checkbox selected... coderanch.com |
15. JTreeTable programmatic selection coderanch.comhi guys, For my treetable component I am using the code from the second article by Sun: JTreeTable II. Rendering, user selection etc. works fine. What my treetable does: - it is not editable (except for expanding and collapsing the nodes, of course). - via a JMenuItem it is possible to group leafs to nodes according to some data information in ... |
16. no selection for JTable coderanch.com |
17. JTable Row Selection coderanch.com |
18. JTable row and column selection listener coderanch.com |
19. JTable Selected Row has vertical lines but showGrid is false coderanch.com |
20. How to disable JTable cell/row selection? coderanch.com |
21. JTable Cntl Left Mouse cell selection for jdk1.3 coderanch.com |
22. Forcing a cell selection in a JTable coderanch.com |
23. how can I disable cells in a table for selection? coderanch.comI have a table in which main diagonal should be disabled for selection l s t l X s X t X Users should be able to click on the remaining cells in order to turn them on or off. I would like to disable the main diagonal so that it is clear to the user that those cannot be changed. ... |
24. disabling table cells for selection coderanch.comI have a table in which main diagonal should be disabled for selection. Users should be able to click on the remaining cells in order to turn them on or off. I would like to disable the main diagonal so that it is clear to the user that those cannot be changed. What I did is, I created a subclass of ... |
25. JTable selected row coderanch.com |
26. Using a the selected JTable name coderanch.com |
27. JTable row selection behaviour coderanch.comHi Mathews, SINGLE_SELECTION means we can not select more than one row. So when we click on some row, original selection will go away. What user wants is: every time he clicks on a new row (without pressing control or shift ), original selection PLUS the new row should remain selected. For example: 0) no rows are selected 1) user clicks ... |
28. JTable and it's selection listeners coderanch.comHi there, I've got me a nice JTable with some data in it.. Now I would like to get a popup window if I change a certain cell and select another row (popup window will only appear if changed data is not correct).. So this is my code: public void valueChanged(ListSelectionEvent e) { System.out.println("CurrentRow: "+currentRow+" FirstIndex: "+e.getFirstIndex()+" LastIndex: "+e.getLastIndex()); if (currentRow!=currentForm.getRow()){ ... |
29. JTable Cell Selection color coderanch.comHi there, When selecting a row in a JTable, that rows background color turns blue (or whatever you want it to be) while the current selected cells colors stays the same (white background, black foreground).. how can i change this? It's because I have a lot of data in different tables. A user can select which columns he wants to see ... |
30. JTable cell is selected but i want the entire row to be selected coderanch.comHi, i have my own listselectionmodel, but how can i make it select an entire row if a single cell is selected(this is only the case when i get focus on the table by pressing Tab, othwerwise(mouseclick) is selects the entire row), or how can i make sure that when Tab is pressed an entire row is selected instead of a ... |
31. JTable Row Selection Listener coderanch.com |
32. How to allow a cell selection for only one column coderanch.comHi all, I wonder if anyone can tell me if it is possible to select a cell from one particular column. This is what I want to do: I have a couple of cloumns and I only want the user to be able to select a cell from the first column only. I have enabled rowSelectionAllowed() , columnSelectionAllowed and also cellSelectionAllowed. ... |
33. JTable Row not selected coderanch.comHello, I have a dialog with 3 JTables on it. Two of them display data which is determined by what is selected in the first table. Also, the two tables contain custom cell renderers. When I display the dialog I select the first row in all 3 tables via setRowSelectionInterval(0,0). The problem is that visually, only the first table (no custom ... |
34. how to get the values from selected row of JTable coderanch.comimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public class ReadingARow { JTable table; JLabel label; public ReadingARow() { String[] headers = { "column 1", "column 2", "column 3", "column 4" }; int rows = 18; int cols = 4; String[][] data = new String[rows][cols]; for(int row = 0; row < rows; row++) for(int col = 0; col < ... |
35. JTable Header selection coderanch.comHi, I m having a JTable in which I m appending columns programatically. When i click on the header of the column(s) that column gets selected. If there are 10 columns and i click on 5 columns then all the 5 columns get selected but there is no way to deselect the columns by clicking on the header again. I want ... |
36. location of a selected row in a JTable coderanch.comimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class LocationTest { JDialog dialog; JTable table; JFrame f; public LocationTest() { createDialog(); f = new JFrame(); table = getTable(); ListSelectionModel model = table.getSelectionModel(); model.addListSelectionListener(new TableSelector(this)); model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(table)); f.pack(); f.setLocation(200,200); f.setVisible(true); } private void createDialog() { dialog = new JDialog(new Frame(), "location"); dialog.setSize(300,50); } private JTable getTable() { String[] headers ... |
37. How to detect JTable cell selected coderanch.com |
38. JTable Selection/Focus Rectangle coderanch.comimport java.awt.*; import java.awt.event.*; import java.awt.geom.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public class TableSelection { public TableSelection() { CustomTable table = new CustomTable(); initTable(table); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.getSelectionModel().addListSelectionListener(new TableListener(table)); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.add(new JScrollPane(table)); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } protected class CustomTable extends JTable { Rectangle r; public CustomTable() { r = new Rectangle(); setSelectionBackground(getBackground()); } protected void paintComponent(Graphics g) ... |
39. JTable row selection coderanch.comI am trying to give the user the option of selecting a specific row and having the mouseclick return an int value for the row each time they click. It seems from reading the API and other examples that this is something that should be easy to implement but in all honesty I have not been able to do it. I ... |
40. Selected columns coderanch.comimport java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; import javax.swing.table.*; public class ColumnSelection { public ColumnSelection() { JTable table = getTable(); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); SelectionListener selectionListener = new SelectionListener(table); // for row selections table.getSelectionModel().addListSelectionListener(selectionListener); // for column selections TableColumnModel model = table.getColumnModel(); model.getSelectionModel().addListSelectionListener(selectionListener); JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getContentPane().add(new JScrollPane(table)); f.setSize(400,400); f.setLocation(200,200); f.setVisible(true); } private JTable getTable() { int rows = 48, ... |
41. JTable - selecting multiple rows by selecting checkbox column coderanch.comHi, I an new to swing .so please bear with me I am trying to implement functionality something similar to yahoo mail. I have a JTable having 5 columns. now i want to add one more column which has checkbox for each row. Then when the user selects multiple checkboxs and clicks on add, i want to select corresponding rows from ... |
42. JTable How to prevent a column being selected. coderanch.comI have a JTable where the user is allowed to select rectagular areas. I want to prevent the rectangular selection ever going over the leftmost column. Well in fact it doesn't matter if the user drags a rectangle over this column, but I don't want a click on single cell in the leftmost column to remove the previously selected rectangle. I ... |
43. Mutiple selection of table rows inconsistent coderanch.comHi again, For people struggling with this, as a workaround, you might like to try this suggestion. It has worked for me because I am not interested in drag events on my table. If you require multiple selection by dragging then this is not for you. Assume this code is in your custom table class (probably constructor). MouseMotionListener[] mouseMotionListeners = this.getMouseMotionListeners(); ... |
45. How to disable the selection of rows in JTable per Mouse Dragging? coderanch.com |
46. TableSorter and Selection gives problems coderanch.comHello, I'm trying to use a JTable in combination with the Sun TableSorter (v2.0 02/27/04). All works fine, but the user selection on the JTable disappears, when rows are added dynamically. TableSorter provides a the method public int modelIndex(int viewIndex), so it's always possible to modify the correct row in the tablemodel when you only have an index of the view. ... |
47. JTable loses selection coderanch.com |
48. Row Selection coderanch.com |
49. JTable is losing selection coderanch.comIn the begining I didn't like the default table cell editor behavior. When the cell editor lost its focus, it was still active. The cell editor was active, it didn't return the value to the table model. This migh confuse the user, so I decided to use: table.putClientProperty( "terminateEditOnFocusLost", Boolean.TRUE ); But it still lacks something. When I'm losing the focus ... |
50. JTable - reselecting selected row coderanch.com |
52. TableCellRenderer setBackground of selected cell not working coderanch.comHi there I have this JTable... Columns 0, 1 and 6 are made with custom renderers and column 6 has a custom editor too. Now the problem with this table, is that when the user selects an item in the last column, there should be the same selected border and background color, but instead is it just white. The table is ... |
53. How to select the row on right click. coderanch.com |
54. Why can't I do selection if I use my own cell renderer for JTable? coderanch.com |
55. How to get selected cell from selected area? coderanch.comLet's say you have a table. You do an area select within the table (click&drag or click&shift-click). Then you do some sort of a search function or the like that results in a cell within the selected area being highlighted. That is, some operation that results in something like: table.changeSelection(row, column, true, true); So now you have a selected area with ... |
56. How to display ghost image of JTable multiple row selection coderanch.comThis looked like fun so I took a stab at it. Some hints on function: To copy: select a node and then, with the mouse button still pressed, press and hold the control key down until the drag is underway, drag the copied node to the target for release. To move a single node: press and hold mouse button, drag and ... |
57. unexpected selection changes in JTable coderanch.com |
58. How to move the selected row in Jtable to be the first row in the table coderanch.comneeds *lots* of testing import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.table.*; class Testing extends JFrame { int currentSelectedRow = 0; public Testing() { setLocation(400,100); setDefaultCloseOperation(EXIT_ON_CLOSE); String colNames[] = {"Col 1", "Col2"}; String[][] data = new String[50][2]; for(int x = 0; x < data.length; x++) { for(int y = 0; y < data[x].length; y++) { data[x][y] = ""+(x+(y*(data.length-1-2*x))); } } DefaultTableModel ... |
59. Keeping row selected when JTable is sorted coderanch.com |
60. Prevent selection of certain JTable cells coderanch.comHi folks, At the moment, I'm putting together a date picker using a JTable, which looks something like this: DefaultTableModel dtm = new DefaultTableModel(); JTable t table = new JTable(dtm); dtm.addColumn("S"); dtm.addColumn("M"); dtm.addColumn("T"); dtm.addColumn("W"); dtm.addColumn("T"); dtm.addColumn("F"); dtm.addColumn("S"); Object row1[] = {"", "", "", "1", "2", "3", "4"}; Object row2[] = {"5", "6", "7", "8", "9", "10", "11"}; Object row3[] = {"12", ... |
61. JTableHeader column selection coderanch.comHere is a snippet that I am using to catch which column header is being selected. final JTableHeader header = monthTable[i].getTableHeader(); header.setReorderingAllowed(false); header.addMouseListener(new MouseAdapter(){ public void mouseClicked(MouseEvent e) { int col = header.columnAtPoint(e.getPoint()); tableModel[selectedTab].sortArrayList(col); } }); The problem is when the user wants to resize the column width. Since Microsoft Excel allows the user to double-click between the columns to resize, ... |
62. Multiple selection in JTable coderanch.comI do not get the question completely. You press Ctrl+A to select all the rows, then how do you need a mouse click to select the 4th row? If your question is that you selected some rows and need to add the 4th row to the selected rows then: Hold the Ctrl down when you click on the 4th row to ... |
63. On selecting a row in JTable,some data should be displayed in JTextArea. coderanch.com |
64. How to Update data in JTextArea on selecting a row in JTable. coderanch.comThe soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ... |
65. JTable - prohibit selecting row 2 - rowCount coderanch.com |
66. JTable selection problem coderanch.comclass MyCellRenderer implements TableCellRenderer{ private Color tracked= Color.white; private Color tracking = new Color(237, 243,255); public static final DefaultTableCellRenderer DEFAULT_RENDERER = new DefaultTableCellRenderer(); public Component getTableCellRendererComponent( JTable table, Object value,boolean isSelected,boolean hasFocus, int row,int column) { Component comp = DEFAULT_RENDERER.getTableCellRendererComponent( table, value, isSelected, hasFocus, row, column); String s = table.getModel().getValueAt(row, 4 ).toString(); if(s.equals("Tracked")){ comp.setBackground(tracked); comp.setForeground(Color.BLACK); ((JLabel)comp).setToolTipText("You have tracked this buddy."); }else{ ... |
67. JTable row and cell selection coderanch.comHello all, I 've had a problem and Ive been looking for a solution in vain for 1 month now. I would really appreciate your help. In My JTable row CANNOT be selected. when you click somewhere on the table, only the cell on which you clicked get its borders blue. I want the entire row to get selected whenever the ... |
68. Anything odd with JTable selection in 1.5 ? coderanch.com |
69. Selecting a row in JTable coderanch.comHi i have this problem, When i select a row in my JTable, the full row is not getting highlighted as in MS-Excel. Kindly provide your help. I wrote the following code: import java.awt.*; import javax.swing.*; import javax.swing.table.*; public class table1 extends JFrame { // Variables declaration private JTable jTable1; private JScrollPane jScrollPane1; private JPanel contentPane; // End of variables declaration ... |
70. selecting rows upwards using mouse in JTable coderanch.com |
71. how to - multple row selection with JTable coderanch.com |
72. Selecting entire column coderanch.com |
73. Selecting multiple rows in a JTable. coderanch.com |
75. Table row selection problem coderanch.comHi all, I have made a table.The working of the table is made in such a way that when i click on the enter button a new row is being added. But I want to add the new row only when the last column of the last row is selected. Is this possible? |
76. JTable cell selection coderanch.comThe JTable itself is not aware of any selection changes nor data for that matter. It relies on XXXModels. (In case you dont know, google for MVC architecture) So what you need to do is: 1)Get the table's selection model (JTable#getSelectionModel) 2)Add a selection listener to the selection model (ListSelectionModel#addListSelectionListener) 3)The listener will tell you when the table selection changes. Then ... |
77. JTable selected row problem coderanch.comSorry the code is not formatted correctly. Here is the formatted one. My sample code for the table and the main is below: import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.swing.JComboBox; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableCellEditor; import javax.swing.table.TableCellRenderer; public class BusinessRuleTable extends JTable { String[] colNames = new String[] { "RuleType", "Date", "Action/Type", "Description" }; private ... |
78. Disable Selection in a JTable coderanch.comOriginally posted by Oliver Brocker: On a javax.swing.JTable I can set the table's selection mode with setSelectionMode. Here I can set it to SINGLE_SELECTION, SINGLE_INTERVAL_SELECTION or MULTIPLE_INTERVAL_SELECTION. But I want that the user cannot select any cell. So is there a way to disable the selectionmode? Unfortunately there is no NONE_SELECTION alternative. yourTable.setSelectionModel( new NullSelectionModel() );public class NullSelectionModel implements ListSelectionModel { ... |
79. JTable MultipleRoW Selection Problem coderanch.com |
80. JTable selection problem coderanch.comI've written a program that works fine with Java 1.1.8/1.2 but when run with Java 1.3.1 has a JTable selection problem. Here's the problem: When the window with the JTable appears to the user, the user can select a row and open it. This works just fine in earlier versions of Java; the selected row opens and displays to the user ... |
81. Jtable without cell selection? coderanch.com |
82. selecting row in JTextPane coderanch.com |
83. Row selection return value coderanch.com |
84. Query on selecting a specific row in JTable coderanch.com |
85. Problem with selection in JTable coderanch.comHi, I am having a problem that I hope someone can help me with. I have a JTable with products and wants to select the last chosen product when I get back to the page containing the table. To select the productobject I have created my own renderer that draws a border around the product when it is selected. I use ... |
86. Problem in JTable row selection coderanch.comDear Friends, I'm using JTable in my application. It has 4 columns and rows are fetched from database. 1st column contains JCheckBox to select the particular row in the table. 1st column header also contains JCheckBox. All rows in the table are selected and unselected by check and uncheck the column header JCheckBox. The problem is, If I check anyone of ... |
87. Select All checkbox in Jtable coderanch.comI am trying to implement a Select all functionality in Jtable column header. for reference, I refer code from here While working with code, requirement implemented fine, but there is an issue with this code.. Case- When user clicks on "Check All", all the checkboxes gets selected, But if user un select any of the checkbox from table then ideally "check ... |
88. Changing the background color of a selected row in a JTextArea coderanch.comI wish I could re-do this thread and be more specific.... Requirements: - single-click highlights row of text (got this already using Actions) to certain color (got that now with textArea.setSelectionColor() ) - selected row stays highlighted so long as caret does not does not leave row or mousevent doens't fire on another row (rows in jtextarea are simply new lines...so ... |
89. JTable auto select row coderanch.com |
90. Multiple values from Jlist to multiple columns selection coderanch.com |
91. user select jtable row coderanch.comRanchers, I'm confused..... In my jtable i want the user to select the row, and hit edit button then that selected rows data will show up in the text fields of the edit dialog window. not sure how to go about getting the data from the table to the text fields? thank you |
92. problem getting the selected row in jtable coderanch.comAll, having a issue with getting the current selected row in my jtable. it returns -1 so its like its not seeing the selected row from the user. here is my code public void initComponents() { try { testframe mf = new testframe(); int n = mf.PartToolOrderTable.getSelectedRow(); setTitle("Updation of data..."); setBounds(325, 325, 400, 350); setResizable(false); //cotainer cpane = getContentPane(); cpane.setLayout(new FlowLayout()); ... |
93. jtable column selection coderanch.com |
94. Row Selection problems with JTable coderanch.comHello! I am working on a project for school, and have run into a couple of problems with a JTable. The project compiles, but does not do two things. The first is in an attempt to select the first row upon program start, which returns the error "Row Index out of Range". I cannot get past this error. To run what ... |
95. JTree row selection by mouseclick question coderanch.comIs is it possible to select a JTree's row not just by clicking on the name of the row, but by clicking anywhere in the row? I think the default behaviour(you can select only by clicking on the name) is caused by the default tree node renderer which resizes the JLabel renderer component based on the content. So it won't detect ... |
96. jtable column with defaultcelleditor(jcheckbox) does not get highlighted when selected coderanch.comi had to use celleditors because i wanted my checkboxes to be disabled at some point. if i use just a renderer, when i click the cell, the checkbox appears for a short stint. at least using a celleditor, i was able to disable those that i wanted via the iscelleditable method to ignore if cells are clicked. im tackling a ... |
97. row is selected just clicking on row of a table coderanch.com |
98. JTable row selection based on a character key pressed coderanch.comHi, I am developing a File Explorer. I am displaying the contents of a directory in a JTable (all files and sub directories). The first column contains the icon of the file type (file or directory) , second column filename, third file size and fourth creation date. When I click on any file (row) and press an alphabetical key i should ... |
99. Cell Selection In JTable coderanch.com |
100. Selecting a row in one JTable should select the same row in another JTable coderanch.com |