scrolling JTable to make cells visible


Here is the code I am using to scroll JTable to its last cell and to make that cell visible. For some reason however, that cell is selected but the table does not scroll to it to make it visible. Can anyone help and tell me what I am doing wrong

JTable table = codeEntryPN.getCodeDescriptionTable();
TableModelDataCapture tableModel = (TableModelDataCapture)table.getModel();

//adds a row of data to model to the end and fires row inserted
tableModel.addDummyRow();
int lastRow = tableModel.getRowCount() - 1;
table.setRowSelectionInterval(lastRow, lastRow);

//makes the newly added row visible
table.scrollRectToVisible(table.getCellRect(lastRow, 1, true));

Posted On: Tuesday 23rd of October 2012 11:28:48 PM Total Views:  235
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




How do I add text to a scrollable JTextPane without scrolling the JScrollPane?

I am using a JTextPane within a JScrollPane to display more text than the area provides. The controls live on a custom JDialog box and everything is fully initialized in the dialog's constructor. The scroll bars work and allow me to scroll around and view all of the text, but the problem is that the scrollbar is initialized at the lowest position. In other words, when my dialog appears the text field is scrolled down and displays the bottom of the block of text instead of the top. The first thing I tried to do was set the vertical scrollbar's value to 0 after setting up the dialog, but the request is ignored. I thought this might be the result of the dialog being resized with "pack()" so I called this after pack() and it is still ignored. As far as I can tell something happens after the dialog's constructor that changes this setting and wipes out mind, but I don't know what it is. // This is the code I call to move the scrollbar: scrollPane.getVerticalScrollBar().setValue(0);
VIEWS ON THIS POST

133

Posted on:

Saturday 22nd September 2012
View Replies!

How to make scrolling area bigger. i.e. increase window size?

I know that you use either the JPanel revalidate() or the JScrollPane revalidate(). Which one I don't know. However, I did both and still it's not resizing. I know that there's some other line of code I needed but can't recall what it was. I thought it might be the JFrame pack() method, but that didn't do it either.
VIEWS ON THIS POST

177

Posted on:

Saturday 22nd September 2012
View Replies!

JTree not scrolling to selected node

I have easily looked at 30 sites (including this one) trying to find a solution to the problem of a JTree not scrolling to a selected node. My JTree, which is in a JScrollPane, does have the proper node selected and highlighted; but I cannot get the scrollpane to cooperate. Most every site I have found (with entries going back to 2002) are all similiar to http://www.coderanch.com/t/334800/GUI/java/jtree-not-scrolling-selected-node, which prescribes calling either scrollPathToVisible(treePath) or scrollPathToVisible(row). I have also tried scrollRectToVisible(Rectangle) on the JViewport of the JScrollPane in which the JTree resides. I have also tried manually setting the value on the JScrollBar itself, all to no avail. I cannot provide the full code; but here is the snippet and the output I receive. Construction for my JTree: this.jtTree = new JTree( this.dtmTreeModel ); this.jtTree.setEditable( false ); this.jtTree.setDragEnabled( false ); this.jtTree.getSelectionModel().setSelectionMode( TreeSelectionModel.SINGLE_TREE_SELECTION ); this.jtTree.setShowsRootHandles( true ); this.jtTree.setScrollsOnExpand( true ); this.jtTree.setLargeModel( true ); // // Possible line style values are "Angled", "Horizontal", and "None" ( the default ). // this.jtTree.putClientProperty( "JTree.lineStyle", "Angled" ); this.jspATSTreeScrollPane = new JScrollPane( this.jtTree );
VIEWS ON THIS POST

61

Posted on:

Wednesday 17th October 2012
View Replies!

How to add scrolling Functionality to a JButton?

Hi Friends, I am new in Swing application. I need to add scrolling functionality to JButton... I will explain the scenario. I have a panel with many labels. And I have two button, one for up scrolling and one for down scrolling. What I need is, when I click on these button the panel have to scroll correspondingly (The Panel is already added to a JFrame).
VIEWS ON THIS POST

54

Posted on:

Wednesday 17th October 2012
View Replies!

line wrapping and scrolling in a JPanel

, I've got an empty JPanel to which I want to add an (unknown) number of JLabels. Each JLabel has a text which is just one word. When my program is adding JLabels to the JPanel, I want it to have the same behaviour as a normal text editor: when a line is full, the next line gets filled (line wrapping). If I just keep adding JLabels to a JPanel of a fixed size with .add(), there's no line wrapping. I tried it by giving the JPanel a fixed size, flowLayout and nesting it within a JScrollPane, but it keeps filling one long line, instead of jumping to the next one. Any obvious solutions\t
VIEWS ON THIS POST

77

Posted on:

Thursday 18th October 2012
View Replies!

update rows in jtable

I can update rows in database, but in jTable I see the changes only after I close the application and rerun it. What should I do This is my code: private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) { try { Class.forName("org.apache.derby.jdbc.ClientDriver"); Connection con = (Connection) DriverManager.getConnection("jdbc:derby://localhost:1527/Proiect","aneresia","aneresia"); int rowNumber=jTable1.getSelectedRow()+1; // Statement stmt1 = con.createStatement(); // int rowsUpdated; con.setAutoCommit(false); stmt1.executeUpdate("Update Carti set nume_autor='"+jTextField2.getText()+"' , pren_autor='"+jTextField3.getText()+"', nume_carte='"+(String)jTextField4.getText()+ "' , nr_car_stoc="+jTextField5.getText()+" ,editura='"+jTextField6.getText()+"' , an_aparitie="+jTextField7.getText()+ " , pret_v="+jTextField8.getText()+" where cod_carte="+rowNumber); model.fireTableRowsUpdated(rowNumber, rowNumber); con.commit(); con.close(); } catch (SQLException ee) { ee.printStackTrace(); } catch (Exception f) { } }
VIEWS ON THIS POST

192

Posted on:

Sunday 21st October 2012
View Replies!

Ordering jtable

Hi all, I have a JTable with just one column. Every cell contains a picture thumbnail with a name and a timestamp below. The pictures themselves are represented by JPA Entities, which have tags associated to them (a comma separated String, which does not appear in the table). Now I want my user to be able to sort the table based on the timestamp or the tag String. I would like a popup menu that lets the user select the way he want the ordering to take place. What would be the best way to implement this I can compare Strings or timestamps, but just making my picture Entity implement Comparable won't do the trick, because that won't let me choose what field should be used to compare the pictures.
VIEWS ON THIS POST

138

Posted on:

Monday 22nd October 2012
View Replies!

Calculate sum in jtable and display the sum in jtextfield

Hi all,i got a table that contains codes,names,qty,price and totals.What i want to ask is how to calculate the qty*price and the total was putted in the the totals column and also putted in the JTextField..When there are new rows,or deleted rows,it will automatically edited in the JTextField.
VIEWS ON THIS POST

165

Posted on:

Monday 22nd October 2012
View Replies!

jcombo box and jtable

, I'm fairly new to Java (so please bear with me ) and am learning to use swing. I've created a simple JFrame. I have a JComboBox in the frame and below this a JTable. I have some values (a series of name) added to the JComboBox and when I select a value, such as the name 'Mary' then I want their information (grade etc) to appear in the columns of the table. So far, I've made little or no progress. I can get the chosen value from the JComboBox to appear in a textfield, but not in the table. Do you think I am going to right way Any advice would be great.
VIEWS ON THIS POST

143

Posted on:

Monday 22nd October 2012
View Replies!

color in jtable cell

i have this code (to be entirely frank i cant recall where i found it), that paints every other line with a diferent color Color cor = table.getBackground(); if((row%2) == 0 && cor.getRed() > 20 && cor.getGreen() > 20 && cor.getBlue() > 20) setBackground(new Color(cor.getRed() - 20, cor.getGreen() - 20, cor.getBlue() - 20)); else setBackground(cor)
VIEWS ON THIS POST

135

Posted on:

Monday 22nd October 2012
View Replies!

SWT: Get the right behavior from Tree and Table scrolling on Mac OS X

On Mac OS X, in the Tree and Table widgets, the scrollbars are always visible. Is there a way to hide them (at least the horizontal one). I've tried several "tricks", like myTree.getHorizontalBar().setVisible(false), myTree.getHorizontalBar().setEnabled(false), and myTree.getHorizontalBar().dispose(), which remove the scrollbar but leaves a colored rectangle (based on the shell color used) and the square of the intersection between vertical and horizontal scrollbar. I'm going crazy!
VIEWS ON THIS POST

55

Posted on:

Monday 22nd October 2012
View Replies!

how use the jtable in java applete

hi master sorry i again Disturb you pleae give me idea how i use the jtable in java applete please send me code
VIEWS ON THIS POST

116

Posted on:

Monday 22nd October 2012
View Replies!

jtable help

In jtable when a value is being edited a border is highlighted arround the cell. But once the cursor is out of focus for instance to another component on the form, the border on the cell is still highlighted and the value that was entered on the cell doesnt get saved to the database. Is there a way to solve this issue.
VIEWS ON THIS POST

112

Posted on:

Monday 22nd October 2012
View Replies!

jtable help

In jtable when a value is being edited a border is highlighted arround the cell. But once the cursor is out of focus for instance to another component on the form, the border on the cell is still highlighted and the value that was entered on the cell doesnt get saved to the database. Is there a way to solve this issue.
VIEWS ON THIS POST

106

Posted on:

Monday 22nd October 2012
View Replies!

jtable rendering problem

I have problem in displaying the default AND values in the combo boxes in the table. The table in its empty state, that is when it is contructed and before the user has a chance to make any changes, a row with no data and 2 columns is created. The table looks like: (empty)|(empty) When the user hits the button once, the new row is added at position 0 in the table and the row that was created first without the user hitting the button moves down. Now the table looks like : (empty)|(some value) (empty)|(empty) When the user hits the button the second time, the new row is added at the last but one row and the table looks like : (empty)|(some value) AND|(some value) (empty)|(empty) When the user hits the button the third time,the new row is added at the last but one row and the table looks like : (empty)|(some value) AND|(some value) AND|(some value) (empty)|(empty) When the user hits the button the fourth time,the new row is added at the last but one row and the table looks like : (empty)|(some value) AND|(some value) AND|(some value) AND|(some value) (empty)|(empty) Addtional rows can be added thus expanding the table.
VIEWS ON THIS POST

109

Posted on:

Monday 22nd October 2012
View Replies!

jtable right mouse click

hi! how can i set a selection with right mouse click in jtable it only works with left mouse clicks. my table has single_selection mode. thx martin
VIEWS ON THIS POST

139

Posted on:

Tuesday 23rd October 2012
View Replies!

Swing bug? scrolling in BLIT_SCROLL_MODE with painting JTextArea components hangs app

no replies\t I am surprised...
VIEWS ON THIS POST

162

Posted on:

Tuesday 23rd October 2012
View Replies!

How do i add label/textbox to a jtable

Hi all, Can anybody help me in this regard. I have a JTable with n number of rows. I want to implement a key search functionality on the table in such a way that after selecting a column and when i type a character, the character typed should be displayed in a small textbox on the table. (Similar to JBuilder - projects window, wherein when u keyin a character, a small yellow color label is visible displaying the different characters we typed in). How do i do the same in a jtable. Please help me in this regarsd as early aspossible
VIEWS ON THIS POST

106

Posted on:

Tuesday 23rd October 2012
View Replies!

jtable and the scrollbar

Has anyone ever programitcally changed their horizontal scrollbar I'm using a JTable in a scrollPane and I need to take three simple steps: 1. get the current position of the horizontal scroll bar 2. recreate the table with new data (not a problem) 3. reposition the scrollbar on the new table to the same position as the old table Can anyone give me an idea how to get the horizontal scrollbar position I tried this approach but haven't had much luck: scrollPane.remove( oldTable ); Point p = scrollPane.getViewport().getViewPosition(); scrollPane.setViewportView( newTable ); scrollPane.getViewport().setViewPosition(p);
VIEWS ON THIS POST

105

Posted on:

Tuesday 23rd October 2012
View Replies!

Very sloooooow scrolling

in my app, with several tabbed panes, i've the following structure: contentPane jtabbedPaneExt jscrollPanel1 jTabbedPane1 jScrollPane7 jPanel1 my app works nicelly, except if i use the arrow of the scroll, when the scrolling is extremely slow. Why
VIEWS ON THIS POST

54

Posted on:

Tuesday 23rd October 2012
View Replies!