JTable - Get the Point of the selected row

I programmatically selected a row in my JTable using
table.getSelectionModel().setSelectionInterval(row, row);Now I would like to reposition the viewport in order to view the selected row.
I was thinking about using following method:
table.getViewport().setLocation(Point p);For this I would need to know the location (Point) of the selected row.
Can anyone help me with this ?

Check out the JTable methods getCellRect and scrollRectToVisible (inherited from JComponent).
luck, db
Umm, not just too late but 3 late :-) lost my net connection for a short while.
Gotta check what david's quoted me on.
Edited by: Darryl.Burke

Similar Messages

  • To change the font of a selected row in a Jtable

    Hello,
    Is it possible to change the font of a selected row in a jtable?
    i.e. if all the table is set to a bold font, how would you change the font of the row selected to a normal (not bold) font?
    thank you.

    String will be left justified
    Integer will be right justified
    Date will be a simple date without the time.
    As it will with this renderer.Only if your custom renderer duplicates the code
    found in each of the above renderers. This is a waste
    of time to duplicate code. The idea is to reuse code
    not duplicate and debug again.
    No, no, no there will be NO duplicated code.
    A single renderer class can handle all types ofdata.
    Sure you can fit a square peg into a round hole if
    you work hard enough. Why does the JDK come with
    separate renderers for Date, Integer, Double, Icon,
    Boolean? So that, by default the rendering for common classes is done correctly.
    Because its a better design then having code
    with a bunch of "instanceof" checks and nested
    if...else code.This is only required for customization BEYOND what the default renderers provide
    >
    And you would only have to use instanceof checkswhen you required custom
    rendering for a particular classAgreed, but as soon as you do require custom
    renderering you need to customize your renderer.
    which you would also have to do with theprepareRenderer calls too
    Not true. The code is the same whether you treat
    every cell as a String or whether you use a custom
    renderer for every cell. Here is the code to make the
    text of the selected line(s) bold:
    public Component prepareRenderer(TableCellRenderer
    renderer, int row, int column)
    Component c = super.prepareRenderer(renderer, row,
    , column);
         if (isRowSelected(row))
              c.setFont( c.getFont().deriveFont(Font.BOLD) );
         return c;
    }It will work for any renderer used by the table since
    the prepareRenderer(...) method returns a Component.
    There is no need to do any kind of "instanceof"
    checking. It doesn't matter whether the cell is
    renderered with the "Object" renderer or the
    "Integer" renderer.
    If the user wants to treat all columns as Strings or
    treat individual columns as String, Integer, Data...,
    then they only need to override the getColumnClass()
    method. There is no change to the prepareRenderer()
    code.
    Have you actually tried the code to see how simple it
    is?
    I've posted my code. Why don't you post your solution
    that will allow the user to bold the text of a Date,
    Integer, and String data in separate column and then
    let the poster decide.Well, I don't see a compilable, runnable demo anywhere in this thread. So here's one
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.*;
    import java.text.DateFormat;
    import java.text.SimpleDateFormat;
    import java.util.Arrays;
    import java.util.Date;
    import java.util.Vector;
    public class TableRendererDemo extends JFrame{
        String[] headers = {"String","Integer","Float","Boolean","Date"};
        private JTable table;
        public TableRendererDemo() {
            buildGUI();
        private void buildGUI() {
            JPanel mainPanel = (JPanel) getContentPane();
            mainPanel.setLayout(new BorderLayout());
            Vector headerVector = new Vector(Arrays.asList(headers));
             Vector data = createDataVector();
            DefaultTableModel tableModel = new DefaultTableModel(data, headerVector){
                public Class getColumnClass(int columnIndex) {
                    return getValueAt(0,columnIndex).getClass();
            table = new JTable(tableModel);
    //        table.setDefaultRenderer(Object.class, new MyTableCellRenderer());
            table.setDefaultRenderer(String.class, new MyTableCellRenderer());
            table.setDefaultRenderer(Integer.class, new MyTableCellRenderer());
            table.setDefaultRenderer(Float.class, new MyTableCellRenderer());
            table.setDefaultRenderer(Date.class, new MyTableCellRenderer());
            JScrollPane jsp = new JScrollPane(table);
            mainPanel.add(jsp, BorderLayout.CENTER);
            pack();
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        private Vector createDataVector(){
            Vector dataVector = new Vector();
            for ( int i = 0 ; i < 10; i++){
                Vector rowVector = new Vector();
                rowVector.add(new String("String "+i));
                rowVector.add(new Integer(i));
                rowVector.add(new Float(1.23));
                rowVector.add( (i % 2 == 0 ? Boolean.TRUE : Boolean.FALSE));
                rowVector.add(new Date());
                dataVector.add(rowVector);
            return dataVector;
        public static void main(String[] args) {
            Runnable runnable = new Runnable() {
                public void run() {
                    TableRendererDemo tableRendererDemo = new TableRendererDemo();
                    tableRendererDemo.setVisible(true);
            SwingUtilities.invokeLater(runnable);
        class MyTableCellRenderer extends DefaultTableCellRenderer{
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                 super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if ( isSelected){
                    setFont(getFont().deriveFont(Font.BOLD));
                else{
                    setFont(getFont().deriveFont(Font.PLAIN));
                if ( value instanceof Date){
                    SimpleDateFormat formatter =(SimpleDateFormat) SimpleDateFormat.getDateInstance(DateFormat.MEDIUM);
                    setText(formatter.format((Date)value));
                if(value instanceof Number){
                   setText(((Number)value).toString());
                return this;
    }Hardly a "bunch of instanceof or nested loops. I only used the Date instanceof to allow date format to be specified/ modified. If it was left out the Date column would be "18 Apr 2005" ( DateFormat.MEDIUM, which is default).
    Cheers
    DB

  • The columns of a selected row in a JTable

    Hello guys,
    I am trying to loop through the columns of a selected row in a JTable. Any ideas how i can do that?
    Thanks in advance for your replies.
    Antana.

    there is getValueAt(int row, int column) method in JTable.
    will this help you?
    and please post swing related queries to swing forum.
    --Azodious_                                                                                                                                                                                                                                                                                                           

  • I pre-ordered an iPhone 6 Plus and the delivery date now says October 14th. The point of the pre-order is to get it on release day (or shortly thereafter). Can I go to a Verizon store to pick up my new phone on release day?

    I pre-ordered an iPhone 6 Plus and the delivery date now says October 14th. The point of the pre-order is to get it on release day (or shortly thereafter). Can I go to a Verizon store to pick up my new phone on release day?

    I'm not sure that answers the question Candice.
    I'm in the same situation.  I was up trying to get on the Verizon page at 11:55, kept getting the ECPD error.  When finally got through, the Silver Iphone Plus 64 showed arrival of 9-19.  At every step of the process, it seemed that I was ordering a phone that would arrive on day1.  At no point did it say this was an estimate.  At no point did it say it might change.  In a big yellow box, it said "9-19".  Ordered it, then got confirmation email stating it should arrive at 9-19.   Seems like all should be good, right?  Order site said 9-19, I've got a confirmation email saying 9-19, done and done.
    Then I check the website, and suddenly it changed to 10-14?!?!?!?  I feel like this was a bait and switch.  I was able to pickup an iphone5 in a local store on launch day, and would not have locked myself into a preorder through Verizon if I had known this would happen!
    So, that leads back to the original questions.  Lets assume I walk into a Verizon store on 9-19, and there is an available iphone6 plus just sitting there, can I either get that phone as fulfillment of my pre-order.  Or, cancel my pre-order and buy that phone right then and there?
    JJK
    PS:  It seems there are many people you misled this way.  For every person who takes the time to post on this site, there are going to be many many more who are silently ****** off.

  • Please i am unable to restore my ipad due to error 3194.The restore process stalls when it gets to the point where the firmwarwe is being updated.error message 3194 comes up.please help me

    please i am unable to restore my ipad due to error 3194.The restore process stalls when it gets to the point where the firmwarwe is being updated.error message 3194 comes up.please help me

    http://support.apple.com/kb/TS3694#error3194 
    Unable to contact the iOS software update server gs.apple.com

  • I have an issue where coloured dots (small squares) appear on my screen and it gets to the point where the entire screen freezes although the mouse still moves but nothing works and I need to turn the computer off at the switch. Any ideas?

    I have an issue where coloured dots (small squares) appear on my screen and it gets to the point where the entire screen freezes although the mouse still moves but nothing works and I need to turn the computer off at the switch. It doesn't happen all the time but is very annoying. Any ideas?

    Reset the SMC and PRAM, if the issue continues then you likely have a failing GPU (hardware) that requires repair. To be sure take it in and have it professionally assessed.
    Intel iMac SMC and PRAM resets

  • I just bought a macbook pro and I want to know how to restore pictures that were backed up on iCloud but then deleted from my phone. Isn't that the point of the backup so I can delete and make more space. Please help!

    I just bought a macbook pro and I want to know how to restore pictures that were backed up on iCloud but then deleted from my phone. Isn't that the point of the backup so I can delete and make more space. Please help!

    Log into the iCloud on your MacBook Pro and enable Photo Stream:
    Then launch iPhoto and set iPhoto's Photo Stream preferences to the following:
    Then check the Photo Stream section of iPhoto:
    This is to confirm that the photos are still in Photo Stream. If they are they will be imported into the library. 
    NOTE: not all photos in an iPhone will be in the Photo Stream. PS only keeps photos in it for 30 days.
    If you have the missing photos in your library put them in an album.  Connect your iPhone to the Mac and open iTunes.  In iTunes you can select that album in the library and sync the photos to your iPhone to get them back on the iPhone.
    OT

  • TS3694 when doing a restore to try and solve a wifi problem with my iphone 5 i got past the point where the software was extracted from my phone but then an error message came up saying that the phone could not be restored because of an unknown error (301

    when attempting a restore,  as suggested, to try and fix a week wifi signal on my iphone 5 I got past the point where the sopftware was extracted from my phone but then an error message appeared saying that the phone could not be restored becase of an unknown error (3014). I have tried about 20 times to make it work after trying a number of suggestions I have seen online. My phone gives me know response accept showing a picture of the cable and the itunes symble an the screen permanently - please help

    Hello JD_NINJA,
    Thanks for using Apple Support Communities.
    Error 9006 when restoring your iOS device indicates that there is security software on your computer which is preventing connection to the Apple server or your device.  To troubleshoot this issue please follow the directions below.
    Check your security software
    Related errors: 2, 4, 6, 9, 1611, 9006. Sometimes security software can stop your device from communicating with either the Apple update server or with your device.
    Check your security software and settings to make sure that they aren't blocking a connection to the Apple servers.
    Get help with iOS update and restore errors - Apple Support
    When restoring your iPhone, please make sure to follow the directions in the link below to properly restore.
    Restore your device from an iCloud or iTunes backup - Apple Support
    Take care,
    Alex H.

  • How can I reduce the size of a photo proportionally.  With my old Mac mini I was able to place the pointer on the bottom right corner  hold the shift key until I achieved the desires size.

    How can I reduce the size of a photo PROPORTIONALLY?  With my old Macmini I was able to place the pointer on the bottom right corner of the picture, hold down the shift key and move the pointer to achieve the desired size.  

    You'll need to use a 3rd party editor like one of these:
    Some Image Editors That Support layers:
    Photoshop Elements 11 for Mac - $79
    Rainbow Painter - $30
    Imagerie - $38
    Acorn - $50
    Pixelmator - $60 
    Seashore - Free
    Portraits and Prints - Free
    GIMP for Mac - Free
    Xee 2.1 - free
    My personal preference would be for Photoshop Elements for Mac. Most of these will let you select and copy a head from one photo, paste it into another photo, resize and place where you need it.
    PSE has a specific feature just for that function.  I belive the Adobe site for PSE has a demo video of that feature.
    OT

  • What's The Point Of The Documents Switch In iCloud Preferences?

    According to the help pages on iCloud.com, OS X users must manually upload and download documents as they wish to edit them.  This is different from iOS devices as they get the latest version automatically pushed to them.
    What's the point of the of the Documents switch in iCloud preferences if nothing happens automatically?

    It's a pain uploading and downloading from iworks.com
    To me it's a step backwards from using iDisk, Apple needs to sort it out really

  • I am using pages designing a flow chart, question "I seem to have an issue with the arrows that you can add text to, it appears I can not move the point of the arrows up or down they only switch from left to right.

    I am using pages designing a flow chart, question "I seem to have an issue with the arrows that you can add text to, it appears I can not move the point of the arrows up or down they only switch from left to right.

    Last point...who archives? On my regular email page I now have the Archive icon to the left of my Delete icon which I would prefer was to the left, first in the line as this is the icon I use mostly. With Folders, my Sent and Trash lists, who needs to archive?
    I can help you only with the placement of the icon placement -- if you right-mouse click on the toolbar, then select Customize Toolbar, you can move an icon to where you want it to be.

  • What is the point of the download window if you use stacks?

    Greetings,
    One of the most annoying things about the download window was the fact that the window always hung around after completing dowloads in Tiger when using safari. To me, that was just a time waster of always pressing Apple+W to close that window.
    When Leopard was released, I was excited to realize that one function of the download stack was to recevie downloads from safari after completed. However, after completion, the download window still sticks around and I still have to close it... then navigate to my stack of downloads to mount the image. What is the point of the download window is I use stacks now? Why can't the window disappear after completion?
    //Cheers

    Aaargh!! Me too - it's so annoying! Firefox has a downloads window as well - I just don't see the point of it. I didn't like it in Tiger either.
    As a way to see the progress of downloads, it's fine, but it should at least close when all the downloads are finished, and completed downloads should not display.
    Ideally it should look & work exactly like the Copy window in Finder - the one that comes up when you are copying or moving a large file or number of files from one folder to another.
    Is there a hack that will make it work like that?

  • Position of the pointer of the mouse

    as I can obtain the position of the pointer of the mouse in an applet
    I use "MouseEvent e" and then I use "e.getX () and e.getY ()" and it compiles well
    but when I execute the program they make errors.
    A piece of the program:
    "public class ticker2 extends Applet implements Runnable {
    MouseEvent e;
    public void paint(Graphics g) {
    if(activo && (m.getX ()> origen[indice])
    also use a "addMouseMotionListener" in the function "init" that I don't believe that it causes conflicts
    Somebody knows where this the error or how should make it well.

    Try this,
    addMouseListener(
    new MouseAdapter() {  
      public void mousePressed(MouseEvent e) {
        if(isSelected)
         System.out.println( e.getX()+e.getY() );
    });      If it works I would be happy to relieve you of your dukeDollars :-)

  • What is the POINT of the Creative Cloud App?

    This is a bug report and a rant:
    Every time the CC app updates, one or more of my Installed Apps disappear from it. With the last update, all but two disappeared.
    The apps themselves (Dreamweaver, Photoshop, Illustrator, Muse, etc.)are all still there on my system, and run fine, they are just gone from the CC app.
    So my question is not facetious - WHAT IS THE POINT OF THE CC APP?
    Do we need it?
    Do we want it?
    Please - don't sing me the "uninstall and reinstall" song, I've done it over and over and it won't play.
    Fix it or lose it!
    Thanks

    If you have very good lighting, the 0.7 MP camera takes acceptable photos.  Light is all you can do.

  • When waking from "sleep" screen turns grey under the pointer and the computer is effectively dead. Have to hold power 'off' for five seconds to regain computer.

    When waking from "sleep" the screen appears normal but, the pointer leaves a trail of grey as it moves and the whole screen will turn grey if I keep moving the pointer. The computer is effectively dead. Have to shut down by using power off for six seconds and then re-starting. I know little about computers!

    Please read this whole message before doing anything.
    This procedure is a diagnostic test. It’s unlikely to solve your problem. Don’t be disappointed when you find that nothing has changed after you complete it.
    The purpose of this exercise is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login. Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards. Boot in safe mode and log in to the account with the problem. The instructions provided by Apple are as follows:
    Be sure your Mac is shut down.
    Press the power button.
    Immediately after you hear the startup tone, hold the Shift key. The Shift key should be held as soon as possible after the startup tone, but not before the tone.
    Release the Shift key when you see the gray Apple icon and the progress indicator (looks like a spinning gear).
    Safe mode is much slower to boot and run than normal, and some things won’t work at all, including wireless networking on certain Macs.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem(s)?
    After testing, reboot as usual (i.e., not in safe mode.)

  • What's the point of the grey space around an image?

    I understand the point of the grey space around an image when viewing in 'Fit' mode, because the image may or may not fill up the viewing space depending upon its aspect ratio...
    But when you zoom in to 1:1 mode, and you scroll around your picture, why is there still this large amount of grey space around your image? If I scroll to the end of my image, it should just stop scrolling, not scroll over the end of my image into this vast amount of unusable and unnecessary grey space!
    It's just annoying that every time I happen to be scrolling around fast, I scroll over the edges of my image into this vast grey space & I just can't fathom the reason for its existence.
    For a better picture of what I'm talking about, see here:
    http://web.mac.com/rishisanyal/Lightroom/UnusableSpace.jpg
    -Rishi

    Actually, it makes perfect sense to scroll in this fashion. It means that every part of the image can occupy the sweet centre spot of your monitor, even with all the panels open.
    Try it. Even that important corner area of the image can be centred on your monitor. Particularly important when performing some spotting along the edges.

Maybe you are looking for

  • Re; Getting data from a live web site, based on geo-location.

    re; Getting data from a live web site, based on geo-location. Approx 4 minutes 25 seconds into this YouTube Adobe ELearning video for Common JavaScript Interface in Adobe Captivate 8, the topic of extracting data from a live web site http://api.openw

  • HP LaserJet Pro M1217nfw Multifunction Printer –job prints repeatedly by AirPrint from iOS 6 devices

    HP would like to make customers aware of an issue with its LJ M1217nfw and LJ M1218nfs printers. When using AirPrint from an iOS 6 device (e.g. iPhone or iPad) with the iOS 6 OS, the print job will print continuously unless the customer cancels the j

  • Using AppleTV 2 with a VPN

    Hey,      I have seen lots of discussion on whether you can setup a VPN on an AppleTV 2. The short answer in my experience is no.  However you can setup a VPN on an attached MacMini for example and then share its internet connection with the AppleTV.

  • FF4, slower, crashes more, problems with more pages, inconvenient

    Been a FF fan for a decade. But I fail to see any of what all the rave reviews say about FF4. Instead, my family of 5 are all complaining to me that FF4 is slower, crashes more, can't open more pages, they can't find where FF4 "hid" what they use to

  • Workgroup Manager: Sharing is Greyed Out

    Having re-built a 10.4.11 Server OS, migrated data from the old drives onto the new ones, installed users, got it up and running, I now find I have a problem where the Sharing icon on the Workgroup Manager is greyed out, and thus I can't get into it