jtable

Swing JTable: Event when row is visible, or when scrolled to the bottom?

风格不统一 提交于 2020-01-02 04:07:07
问题 I'm looking for a way to be informed when a JTable has scrolled such that a particular row becomes visible, or failing that, when the bottom of the table has scrolled into view. Ideally this should be done without polling, but through some event firing. any ideas? 回答1: Add a ChangeListener to the viewport of the scrollpane. viewport = scrollpane.getViewport(); viewport.addChangeListener(this); then this checks the visible rows (can easily be extended to columns as well) public void

How can you disable all sorting code in JTable in 1.6

浪子不回头ぞ 提交于 2020-01-02 03:52:04
问题 I have a JTable extension that has been in use since Java 1.3/1.4 in the project that provided things like column reordering and sorting by clicking on the column. We are upgrading to Java 1.6, and the new JTable stops the old sorting code from working. It would be somewhat extensive rework to fit everything to the new JTable API. Until then is there a way to completely disable those additions in JTable? Edit: After the further investigation, the problem is centered around the fact that the

Setting the height of a row in a JTable in java

余生颓废 提交于 2020-01-02 01:16:05
问题 I have been searching for a solution to be able to increase the height of a row in a JTable. I have been using the setRowHeight(int int) method which compiles and runs OK, but no row[s] have been increased. When I use the getRowHeight(int) method of the row I set the height to, it does print out the size I increased the row to, so I'm not sure what is wrong. The code below is a rough illustration how I am trying to solve it. My class extends JFrame. String[] columnNames = {"Column 1", "Column

Editing JTable from RestulSet Table

大兔子大兔子 提交于 2020-01-01 19:48:08
问题 Continuing this question. My problem is that I can not edit my JTable. I get an exception and the Object value instead of what I should be seeing. I am using the ResultSet Table code with a MS-Access database and with a few modifications. My code can be found here. I run into an error when I rs.updateRow() is called. java.sql.SQLException: [Microsoft][ODBC Microsoft Access Driver]Error in row. I did a google search on this error with updateRow() and not much came up. The only real answer I

Display the information of a JTable row when selected

最后都变了- 提交于 2020-01-01 07:10:08
问题 How do I display the information of a JTable row when selected? I'll briefly explain what I am trying to do and then post the SSCCE that I created in case any of my explanation is confusing. I'm wanting to be able to click any row in a table and display that information on a panel. I'm not sure what I need to make use of to get the job done. I'm thinking I'll need to use: table.getSelectedRow() MouseListener() ListSelectionListener() I haven't used Listeners before, so I only know of those

How can I hide (make invisible) row in JTable?

烈酒焚心 提交于 2020-01-01 07:06:27
问题 Is there any way to do it? 回答1: The best easiest way would be to remove the corresponding element from the model. 回答2: There is the RowFilter<DefaultTableModel, Object> class you can use to filter out rows. The DefaultTableModel can be replaced by your own model. To filter, implement the method @Override public boolean include(Entry entry) { // All rows are included if no filter is set if (filterText.isEmpty()) return true; // If any of the column values contains the filter text, // the row

JTable, custom header renderer and sorting icons

核能气质少年 提交于 2020-01-01 02:40:57
问题 While setting a custom renderer on a JTable header I get the expected visual behavior (borders, font, alignment, ...) but I can't manage to get the LaF sorting icons that usually appear when the rows are sorted. This is the code for setting the custom header renderer: Enumeration<TableColumn> columns = getColumnModel().getColumns(); while (columns.hasMoreElements()) columns.nextElement().setHeaderRenderer(new XDeliveryTableHeaderRenderer()); This is an excerpt of the custom header renderer:

Is it possible to include JButton in a JTable?

为君一笑 提交于 2020-01-01 02:33:07
问题 I have a JTable that stores the results of a database query, so far so good. What I want is for the last column in each table to have a clickible JButton that will open the edit screen for the object represented in that row, and that means the button will need to know the details of the first column in the table from its own row (the ID from the database). Any advice? I already tried just adding JButtons but they turned into Text when I tried to run it. 回答1: Contrary to the tutorial above,

Preserve JTable selection across TableModel change

跟風遠走 提交于 2020-01-01 02:26:30
问题 We're seeing JTable selection get cleared when we do a fireTableDataChanged() or fireTableRowsUpdated() from the TableModel . Is this expected, or are we doing something wrong? I didn't see any property on the JTable (or other related classes) about clearing/preserving selection on model updates. If this is default behavior, is there a good way to prevent this? Maybe some way to "lock" the selection before the update and unlock after? The developer has been experimenting with saving the

Copy Data from JTable into ArrayList

徘徊边缘 提交于 2019-12-31 07:42:32
问题 Hi how can I copy data from my JTable into an ArrayList? I dont want the first row which is the columns name, I want everyother row. Thanks 回答1: If you are storing the data in the table with out using any object then just traverse row by row on the table and get every object and store it in the List. Example: This is when you are using a list to store the data. List<Object> list = new ArrayList<Object>; for(int row = 0; row < table.getRowCount(); row++) { for(int column = 0; column = table