How to show 10 bottom rows instead of showing 10 top rows of table as defau

A table was created with JTable class and JScrollPane class. If you run the following code, it always shows you the top 10 rows, the scrollbar stays at the right-top by default. However, what I want the program to show is the bottom 10 rows (The table has 30 rows totally) and the scrollbar should stay at the right-bottom as default. I should greatly appreciate it if anybody could tell me how to implement this scenario.
import javax.swing.JTable;
import javax.swing.JScrollPane;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JComponent;
import java.awt.*;
import java.awt.event.*;
//import java.lang.string.*;
public class SimpleTableDemo extends JFrame {
private boolean DEBUG = true;
public SimpleTableDemo() {
super("SimpleTableDemo");
Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Angela", "Lih",
"Teaching high school", new Integer(4), new Boolean(false)}
String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(650, 150));
if (DEBUG) {
table.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
printDebugData(table);
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Add the scroll pane to this window.
getContentPane().add(scrollPane, BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
private void printDebugData(JTable table) {
int numRows = table.getRowCount();
int numCols = table.getColumnCount();
javax.swing.table.TableModel model = table.getModel();
System.out.println("Value of data: ");
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + model.getValueAt(i, j));
System.out.println();
System.out.println("--------------------------");
public static void main(String[] args) {
SimpleTableDemo frame = new SimpleTableDemo();
frame.pack();
frame.setVisible(true);

Dimension d = table.getSize();
scrollpane.getViewport().setViewPosition( new Point( 0,
          (int)d.getHeight() ) );This sets it to the end of the table, you might need to edit it to do as you require.
Mike

Similar Messages

  • How to Select a range instead of the whole row in Excel? ie a to k, m to z, VBA Code Below.

    Sub CopyPasteEntries()
    Dim i, g, h As Integer
    i = 2
    Sheets("Sheet1").Select
    Do Until IsEmpty(Cells(i, 1))
        i = i + 1
    Loop
    g = i - 1
    h = 2
    For i = 2 To g
        Sheets("Sheet1").Select
        If Cells(i, 1).Value <> "Created" Then 'first cell
            Cells(i, 1).EntireRow.Copy
            Sheets("Sheet2").Select
            Cells(h, 1).Select
            ActiveCell.PasteSpecial xlPasteAll
            h = h + 1
        End If
    Next
    Application.CutCopyMode = False
    End Sub

    Instead of
    Cells(i, 1).EntireRow.Copy
    use any of these
    Cells(i, 1).Resize(1,11).Copy  'A to K
    Intersect(Cells(i,
    1).EntireRow, Range("A:K")).Copy
    Range(Cells(i, 1), Cells(i,11)).Copy
    Range(Cells(i, "A"), Cells(i,"K")).Copy
    Range("A" & i & ":K" & i).Copy
    Cells(i, 1).Range("A1:K1").Copy

  • Showing report data columns into two rows instead of one row using SSRS 2012

    Hi All,
    I have a ssrs report with 13 columns and I want to show those 13 columns data into two rows instead of showing in one row. please send me step by step process.
    id     fullname     firstname      lastname        mailingaddress     billingaddress       
    city       state       zipcode   
    1       ABC                A                  C                  
        xyz                      xyz123                   york     
    PA          12345    
     homephone     cellphone          workphone          company    
    1234567890      4567890123     0123456789         ABC,Inc
    id     fullname     firstname      lastname        mailingaddress     billingaddress        
    city          state     zipcode   
    2          XYZ               X                  Z                      
         abc                     abc123           lewisburg     
    PA      54321    
     homephone     cellphone           workphone        company    
    4567890123      0123456789     1234567890         xyz,Inc
    id     fullname     firstname      lastname        mailingaddress     billingaddress        
    city          state     zipcode   
    3       BCD                  B                  D                  
    123abc                  xyz123                leesburg       PA     
     54123    
     homephone     cellphone          workphone        company    
    4567895623      0783456789     1238967890       Hey,Inc
    Thanks in advance,
    RH
    sql

    Do a right mouse click on the left, gray row marker => "Insert Row"=> "Inside Group
    - Above or Below", then you get a second detail row.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • Make download button show all download instead of only a few downloads.

    Just updated from version 25.
    Is there a way to make it show all download instead of showing only a few downloads when I click it the download button? Also, is there a way to make it automatically opens the show all download when I download a picture?

    No to your second question. about:downloads it the page that show all the downloads.

  • How do I display an invalid zip code in a summary table

    On my airshow website we have a feedback form, one of the questions is the zipcode where the visitor came from. This works fine. The summary results tab includes a lookup for the zipcode where I show the city associated with the zipcode and then how many responses came from that zipcode. This can be seen here http://www.hollisterairshow.com/feedback-results.php?tab=7
    In testing, I found that an invalid zipcode is not displayed in the summary table, although it is counted in the total number of responses. I'd like to display the invalid zipcode and leave the City blank, or maybe put "Invalid zip code". The current code is displayed below, it's beyond my ability to figure out how I should change it to display invalid zipcodes and I'd really appreciate some direction on this.
    I know I could validate the zipcode on entry but it's quite possible the zipcode table I have is out of date and i can't find a free downloadable list, so I'm thinking anything invalid could cause me to update my table.which is fine.
    Thanks for any assistance.
    Tony
    <div class="TabbedPanelsContent">
    <?php
    // Make a MySQL Connection
    $query = "SELECT feedback.zip, COUNT(feedback.zip), zipcodes.citystate FROM feedback, zipcodes WHERE feedback.zip = zipcodes.zipcode GROUP BY feedback.zip";
    $result = mysql_query($query) or die(mysql_error());
    // Print out result
    while($row = mysql_fetch_array($result))
    echo $row['zip']. " ". $row['COUNT(feedback.zip)']. " ". $row['citystate'];
    echo "<br />";
    ?>
    </div>

    Use an outer join on the two tables so that results are returned for all feedback rows, instead of just matching rows. The column zipcodes.citystate will be NULL. In your recordset output, you can test for null in the column and populate it with "Invalid Zipcode" if you want.
    You'll need to move the join to the FROM clause as I believe that MySQL does not support outer joins in the WHERE clause like most other DBMS's.

  • Alternating row color is missing a row

    Hi,
    I've made a table and have checked the "alternating row color" box.  It's working fine except for the top row, which should be colored in and isn't.
    Any suggestions on how to fix this?
    thanks.

    Is the top row a header row? That may prevent it from being the intended colour. If so, remove the header setting and reapply the alternating row colour.

  • Show the page instead of row in page break

    we know, on the bottom of web query, there is the page indicator showing row 24/500, which means the current page starts from row 24(there're 23 rows in a page). And if we click the right arrow button, it will turn to the next page, showing 47/500. Now we want to show this in the format of page, like PAGE 1/22. I think the arrow button works well, but we'd like to show the current page instead of row number.
      any guy knows how to do this?

    I belive you would need to reprogram Table class and use it in your report i/o standard one
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/weblogs?blog=/pub/u/37289">vitaliy</a>

  • How can I use more lines to show a field of a row in a report?

    How can I use more lines to show a field of a row in a report? Table A have two columns: (c1 number(5),c2 varchar2(1000)).When I show the table on a report,the column c2 show itself in one row.So the width of html page is very wide.How can I split the field c2 to many lines?
    Thanks for any help.

    I was wondering if an answer was found for this one.
    I have the same problem using the default "Look 4" template for the region. I have found in the CSS file where it is defined and it specifies "nowrap" in the style, which is why the long value is not being split over multiple lines.
    So, my question is, without modifying or creating templates, is there a way to override the "nowrap" attribute from within the item definition? e.g. in the Column Attributes.Column Formatting.CSS Style field. I had some success changing the display properties, such as background colour and font size but I can't seen to override the nowrap attribute!

  • How to show employee names in descending order but 3rd row is fixed and always top on the table ?

    how to show employee names in descending order but 3rd row is fixed and always top on the table ?
    for example employee names is A,B,C, D, E
    and output is     C,E,D,B,A

    Since you are posting in the design forum, the short answer is - you don't.  Rows in a table have no inherent order that you can rely on and the "position" of rows is a visual characteristic that should be implemented by the application that displays
    this information or by the query that is used to generate the resultset.  
    So the next question is how one accomplishes this particular order within a select statement.  That is a tsql question which, for future reference, is best posted to the tsql forum.  In addition, many of the questions or issues that you will face
    have been discussed in the forums - often many, many times.  The first thing you should do when faced with an issue is to simply search the forums and leverage the the knowledge that has already been discussed.  In doing so you are quite likely to
    see suggestions or related issues that you should consider in your search for a solution.  
    Now, to answer the question - you need to formulate a order by clause that forces the rows to be sorted in the manner you desire.  Effectively you have 2 levels of sorting.  The first level divides your rows into 2 groups.  Group 1 consists
    of rows where name = E and Group 2 is everything else.  Following that you then need to sort the rows in each group by name in descending order.  Something like:  
    order by case name when E then 1 else 2 end, name desc

  • I'm giving my iphone 4 to my sister. How do I get it to show her name instead of mine?

    I'm giving my iphone 4s to my sister.  How do I get it to show her name instead of mine?

    What to do before selling or giving away your iPhone, iPad, or iPod touch

  • I just upgraded my iPhone4s to iOS7 and now I am unable to make phone calls and send/receive text messages. Network signal indicator on the upper left side of the display shows hollow circles instead of full circles. Any idea how to fix the problem?

    I just upgraded my iPhone4s to iOS7 and now I am unable to make phone calls and send/receive text messaes. Network signal indicator on the upper left side of the display shows hollow circles instead of full circles (but with the network provider name). I checked with my colleagues in the office who use the same network and theirs work just fine on iOS7. Any idea how to fix the problem?

    I have also called my service provider and my service remains active in the network. I tried removing and reinserting my SIM but to no avail.

  • Webapps.  How can I create a link to a page instead of showing the details-view

    I want my client to define what page a webapp shall point to in list-view, instead of showing the  details view, but I cant figure out how.  I have tried this, but it seams that tags don't work inside links:
    <a href="{tag_my_custom_link}">{tag_name}</a>
    .. does any one know how to do this?

    The problem is the format of your tag.  If your field name in the web app is "My Custom Link" then your tag is {tag_My Custom Link} (note the spaces).
    Cedric is right though, make sure the field is a textfield and not a hyperlink field in your web app.  If you use BC's new "Develop" tab up top you can navigate to your web app detail layout in /Layouts/Web Apps/<yourwebapp> and find "list.html".  Then, you can use the toolbox on the right (click the data tab) to insert tags without having to guess.  You can choose your custom field and insert the tag.

  • When i search for mp3 files spotlight shows id3 tags instead of filenames as it used to do !!! I DONT want that .. how can i disable it !!!!!???????

    when i search for mp3 files spotlight shows id3 tags instead of filenames as it used to do !!! I DONT want that .. how can i disable it !!!!!???????

    Sorry, my handful of mp3's had the file name as the id3 tag name.
    So, I am seeing the same thing as you.
    Oddly, a while back I was trying to help someone out in Mountain Lion that wanted to see the id3 tags in the Finder.
    It's all a bit silly. They should have added columns instead or changing it to tag song name.
    They are transitioning to having everything reflect the content and not the file system, so this may not be reversible.
    The best I think you can do is provide feedback: http://www.apple.com/feedback/macosx.html

  • When I hold command   R to restore at start up, my laptop just start normally instead of showing me options. Any ideas on how to fix thi ?

    When I hold command   R to restore at start up, my laptop just start normally instead of showing me options. Any ideas on how to fix this ?

    Prepare Your Mac for Sale
    Boot from the OS X Installer Disc One that came with the computer.  After the installer loads select your language and click on the Continue button.  When the menu bar appears select Disk Utility from the Utilities menu.  After DU loads select the startup volume from the left side list then click on the Erase tab.  Set the format type to Mac OS Extended (Journaled) then click on the Options button.  Select the one pass Zero Data option and click on the OK button.  Then click on the Erase button.
    Note: You can skip the Zero Data option if you are not concerned about removing sensitive personal data from the hard drive.  If you choose to skip this part of the process then it is possible for others to recover data from the hard drive.  The Zero Data procedure will prevent others from getting access to your personal information.
    This process will take 30 minutes to several hours depending upon the size of the hard drive.  After formatting has completed quit DU and return to the installer.  Now complete the OS X installation.  At the completion of the installation do not restart the computer.  Instead just shut it off.  The next user will be presented with the Setup Assistant when they turn on the computer just as it would if new out of the box.

  • HT202060 How can I make Activity Monitor show one graph instead of four for MacBook Air?

    How can I make Activity Monitor show one graph instead of four for MacBook Air?

    Learn about OS X: Activity Monitor shows one CPU Usage graph on systems with more than four cores
    Copied and pasted from top of the page.

Maybe you are looking for