JScrollPane resets position after JTable.changeSelection

I have JTable inside JScrollPane (what a surprise!). Table has some 20 columns, and only 10 are shown at once. If a user scrolls to the right to see the last few columns, and after that I change selection in JTable using
jTable.changeSelection(newSelectedRow, 0, false, false);
JScrollPane resets it's position to show first columns again, and user has to scroll again to the left.
I solved this by
Point p=scrollPane.getViewport().getViewPosition();
jTable.changeSelection(newSelectedRow, 0, false, false);
scrollPane.getViewport().setViewPosition(p);
Iz works, but the table first renders first 10 columns and then scrolls to the left, which is annoying.
Is there any other way?

jTable.changeSelection(newSelectedRow, 0, false, false);Well your are telling it to go to the specified row and column(0).
Two options:
a) get the current view X position and determine which column this represents and set the column accordingly
b) use setAutoscrolls( false );

Similar Messages

  • Reset position for linear movement

    Hi All,
    I am using PCI 7344 and UMI7774.I am using three of its Axis.The first two axis are just used as a DRO ( DIgital Read Out) and the third axis is used to control servomotor.
    Now at a instant of time, I require to Reset all the axis position to zero.Now the third axis can be reseted by using the Reset Position Vi. But since the first two axis are manual, I have used scales which are used for linear movement measurement( The scales are same as encoders, but can be used for linear measurement.It also has A, B & Z). How can I reset the position for this 2 axis.
    Regards
    Manish Karnik

    Hey I missed some point.
    Hi All,
    I am using PCI 7344 and UMI7774.I am using three of its Axis.The first two axis are just used as a DRO ( DIgital Read Out) and the third axis is used to control servomotor.
    Now at a instant of time, I require to Reset all the axis position to zero.Now the third axis can be reseted by using the Reset Position Vi. But since the first two axis are manual, I have used scales which are used for linear movement measurement( The scales are same as encoders, but can be used for linear measurement.It also has A, B & Z). How can I reset the position for this 2 axis.
    Now after reseting the position the axis should be able to read the counts from zero for all the axis. ( For axis 3 it is possible)
    Regards
    Manish Karnik

  • JTable.changeSelection() has stopped working for me in Java 1.5

    The application I'm working on has a search function for a large table of data. In addition, you can restrict the search to a selected area of the table. This worked fine when compiled on Java 1.4, but has stopped working on Java 1.5. It appears the problem is with changeSelection not actually changing the selection to the cell that was found in the search.
    I've been able to reproduce the problem with some small modifications to the SimpleTableSelectionDemo.java tutorial program. I've included the code below with my changes.
    Basically all I did was modify the mouseListener so that instead of printing the table contents, it calls changeSelection to a fixed location (simulating the search going to a matching cell).
    If I compile/run in 1.4, I can select a cell or region, right-click the mouse and see the specified cell selected. If I start typing the selected cell is edited.
    If I compile/run in 1.5, when I right-click the selected cell is not changed (the second selected cell of the select region stays selected). If I start typing the wrong cell is edited.
    Hopefully someone can tell me if this is a run-time bug, or a change in behavior (and what I need to do to get it working again in 1.5).
    * SimpleTableSelectionDemo.java is a 1.4 application that requires no other files.
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.JComponent;
    import javax.swing.ListSelectionModel;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.ListSelectionListener;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    * SimpleTableSelectionDemo is just like SimpleTableDemo,
    * except that it detects selections, printing information
    * about the current selection to standard output.
    public class SimpleTableSelectionDemo extends JPanel {
        private boolean DEBUG = true;
        private boolean ALLOW_COLUMN_SELECTION = true;
        private boolean ALLOW_ROW_SELECTION = true;
        public SimpleTableSelectionDemo() {
            super(new GridLayout(1,0));
            final String[] columnNames = {"First Name",
                                          "Last Name",
                                          "Sport",
                                          "# of Years",
                                          "Vegetarian"};
            final Object[][] data = {
                {"Mary", "Campione",
                 "Snowboarding", new Integer(5), new Boolean(false)},
                {"Alison", "Huml",
                 "Rowing", new Integer(3), new Boolean(true)},
                {"Kathy", "Walrath",
                 "Knitting", new Integer(2), new Boolean(false)},
                {"Sharon", "Zakhour",
                 "Speed reading", new Integer(20), new Boolean(true)},
                {"Philip", "Milne",
                 "Pool", new Integer(10), new Boolean(false)}
            final JTable table = new JTable(data, columnNames);
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            table.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
            if (ALLOW_ROW_SELECTION) { // true by default
                ListSelectionModel rowSM = table.getSelectionModel();
                rowSM.addListSelectionListener(new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        //Ignore extra messages.
                        if (e.getValueIsAdjusting()) return;
                        ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                        if (lsm.isSelectionEmpty()) {
                            System.out.println("No rows are selected.");
                        } else {
                            int selectedRow = lsm.getMinSelectionIndex();
                            System.out.println("Row " + selectedRow
                                               + " is now selected.");
            } else {
                table.setRowSelectionAllowed(false);
            if (ALLOW_COLUMN_SELECTION) { // false by default
                if (ALLOW_ROW_SELECTION) {
                    //We allow both row and column selection, which
                    //implies that we *really* want to allow individual
                    //cell selection.
                    table.setCellSelectionEnabled(true);
                table.setColumnSelectionAllowed(true);
                ListSelectionModel colSM =
                    table.getColumnModel().getSelectionModel();
                colSM.addListSelectionListener(new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        //Ignore extra messages.
                        if (e.getValueIsAdjusting()) return;
                        ListSelectionModel lsm = (ListSelectionModel)e.getSource();
                        if (lsm.isSelectionEmpty()) {
                            System.out.println("No columns are selected.");
                        } else {
                            int selectedCol = lsm.getMinSelectionIndex();
                            System.out.println("Column " + selectedCol
                                               + " is now selected.");
            if (DEBUG) {
                table.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e) {
    //                  printDebugData(table);
    // ==============================================
    // Changed to do a changeSelection() on a right-click
    // without clearing any existing selected area.
                        if (e.getButton() == MouseEvent.BUTTON3) {
                            System.out.println("mouse clicked");
                            table.changeSelection(2, 3, true, true);
    // ==============================================
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            add(scrollPane);
        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("--------------------------");
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            JFrame frame = new JFrame("SimpleTableSelectionDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            SimpleTableSelectionDemo newContentPane = new SimpleTableSelectionDemo();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    }

    Running on Mac OS X 10.4.3
    java version "1.5.0_02"
    Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_02-56)
    Java HotSpot(TM) Client VM (build 1.5.0_02-36, mixed mode, sharing)
    The same problem occurs here.

  • Can't save pictures on original folder position after edit...since I'm upgraded to IOS7 on IPad2.

    can't save pictures on original folder position after edit, get save popup to save at different position, also still on toubles to get them back to original folder positon since I'm upgraded to IOS7 on IPad2.

    I say the problem is probably noted, and probably will be resolved. Not that i can speak for Apple.  I find the "problems" of wallpaper to be pretty minor compared to the advantages of iOS 7.  The fun of wallpaper has always been pretty insignificant here.

  • Hard Drive dead? - Failed to Issue COM RESET successfully after 3 attempts.

    Hello, i think my 13" 2.53Ghz Unibody (mid2009) MBP's hard drive has had it's last spin. I was using it normally in bootcamp, when windows7 froze, so I rebooted holding the power button....windows wouldnt start any more...ok, so i tried to boot into OSX...stuck at the loading screen with the apple.
    Went into verbose mode and it stops at "Failed to issue COM RESET successfully after 3 attempts. Failing..." Google says this has to do with the hard drive.
    Did a extensive hardware test (boot + D), all OK, booted from install disk and tried to run disk utility, but it crashed when trying to locate the drives (didn't even list the drive on the right pane). Single User mode wont load either, will give the same COM RESET message. I am literally out of options here.
    Is there something i can do to either fix this or verify 100% that my hard disk is truly dead?
    I have a backup in timemachine so the data is ok, but the timing couldnt be worse, i have no time to fix this now and needed a working laptop, highly frustrating.
    thanks for any tips

    nobrex wrote:
    Hello, i think my 13" 2.53Ghz Unibody (mid2009) MBP's hard drive has had it's last spin. I was using it normally in bootcamp, when windows7 froze, so I rebooted holding the power button....windows wouldnt start any more...ok, so i tried to boot into OSX...stuck at the loading screen with the apple.
    Went into verbose mode and it stops at "Failed to issue COM RESET successfully after 3 attempts. Failing..." Google says this has to do with the hard drive.
    Did a extensive hardware test (boot + D), all OK, booted from install disk and tried to run disk utility, but it crashed when trying to locate the drives (didn't even list the drive on the right pane). Single User mode wont load either, will give the same COM RESET message. I am literally out of options here.
    Is there something i can do to either fix this or verify 100% that my hard disk is truly dead?
    I have a backup in timemachine so the data is ok, but the timing couldnt be worse, i have no time to fix this now and needed a working laptop, highly frustrating.
    thanks for any tips
    Welcome to the Apple Forums!
    Your HDD is probably dead, since the error doesn't appear to indicate something wrong with the motherboard. Just buy a new 2.5" HDD. I don't know about prices in Brazil, but here in the US, a 1TB drive runs for around US$100. Also, check on eBay for people who upgraded their drive and are selling their Apple drive. Some will ship to Brazil, and you can score those for $50-100.
    I hope you backed up your hard drive. If not, you'll have to do the whole reinstallation process.

  • Scroll bar does not retain its position after or before pack

    Hi
    My Scroll bar does not retain its position after pack in my application.
    But i need to retain its state.
    My code snippet is :
    System.out.println("VAlue--->" + getHXValue());
    scrollPane.getHorizontalScrollBar().setValue(getHXValue());
    pack();
    My VAlue printed is 100.
    But my positon of scroll bar is at 0 th location.
    Can any one help me.....

    Swing related questions should be posted in the Swing forum.
    My code snippet is :Snippets don't help.
    If you need further help then you need to create a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",
    see http://homepage1.nifty.com/algafield/sscce.html,
    that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the "Code Formatting Tags",
    see http://forum.java.sun.com/help.jspa?sec=formatting,
    so the posted code retains its original formatting.

  • How to enforce position after decimal point

    Hi,
    i need to enforce a position after the decimal point in an SAPScript Form.
    The Form is MEDRUCK_RV and the field ist RM06P-PRMG1.
    I tried to enforce it with RM06P-PRMG1(Z9.1) but it doesn't work.
    I need to cut the left-hand zeros and display one position after the decimal point.
    Can someone help?

    Hi,
    Try this.
    DATA : DFORMAT TYPE XUDCPFM,
           L TYPE I.
    SHIFT RM06P-PRMG1 LEFT  DELETING LEADING  '0'.
    SELECT SINGLE DCPFM FROM USR01
    INTO DFORMAT WHERE BNAME = SY-UNAME.
    IF SY-SUBRC EQ 0.
    IF DFORMAT EQ 'X'.
    SEARCH RM06P-PRMG1 FOR '...'.
    ELSE.
    SEARCH RM06P-PRMG1 FOR ','.
    ENDIF.
    ENDIF.
    IF SY-FDPOS NE 0.
    L = SY-FDPOS + 2.
    RM06P-PRMG1 = RM06P-PRMG1+0(L).
    ENDIF.
    Thank You,
    Saritha

  • Failed to issue COM RESET successfully after 3 attempts. Failing...

    Just in case anyone else has this problem, and wants to claw their eyes out.
    I upgraded the Hard Disk in my MacBook Pro about four days ago (the new MBP, summer 2009 with SD card). I installed a Hitachi Travelstar 7K320. It worked awesome for about four days, until I went to run the EFI Firmware Update this morning.
    My machine stopped booting. I held Command-V to get the verbose boot output, and eventually got the message: Failed to issue COM RESET successfully after 3 attempts. Failing... - which is where the boot halted.
    I removed the Hitachi and restored the stock drive, and the laptop now booted fine. I think it's something Apple will have to look into.

    I believe posting relevant facts is productive, & a very relevant fact here is that you are trying to use a drive with an interface (SATA-II) that Apple does not currently support in its laptops.
    SATA-I controllers are supposed to be compatible with SATA-II drives, but many of them are not. The problem is how some controllers implement auto negotiation, which is supposed to tell the drive to fall back to SATA-1 speeds with the slower controllers. Some SATA-II drives have a jumper to force the slower speed if auto negotiation doesn't work; some do not.
    How this compatibility problem came about, & why the jumper is required, is complicated but the short version is that at least four different specification bodies had some responsibility in producing SATA specifications, & not all controllers were designed to the same standards. This includes not just the controllers Apple has been using but those in many PC's as well.
    So I agree that Apple dropped the ball, but not necessarily the way you might think: it should have made it very clear that the firmware update implemented an unsupported interface speed, that it might cause problems, & (most importantly) provided a reversion strategy to the former firmware if it did.
    Hopefully, Apple will take another 'swing' at this & either provide that reversion strategy or a new update that at least allows the controller to work more reliably with the faster interface. But until then, unless your drive has the jumper, my previous suggestion is probably the best you can do.
    BTW, none of the current mechanical drives available for laptops can saturate a SATA-1 bus except for brief bursts from the drive's buffer, so the real loss in performance of running a single SATA-II drive at SATA-1 speeds is almost negligible, something you might notice in a benchmark but not in real-world use.

  • HT4085 My WWF will not rotate in the landscape position after I upgraded.

    My WWF will not rotate in the landscape position after I upgraded.   How do you get it in the landscape position

    Hi northlewisburg,
    Welcome to the Apple Support Communities!
    I know how frustrating these types of situations can be and it sounds like you have done some great troubleshooting already. I would recommend reading over the attached article and working through the troubleshooting steps provided.
    iOS: Screen does not rotate
    http://support.apple.com/kb/TS3805
    Have a great day,
    Joe

  • Desktop Icons Change Positions After Restart

    Hi,
    After I inadvertently synced my computer with another Mac computer my icons change position after restart. I was trying to sync another computer to mine.
    I have tried the usual suggestions of taking out com.apple.finder.plist and com.apple.desktop.plist and letting the system create these new files but the problem still persists. I also checked the Finder > View > Show View Options and arrange by none is still selected.
    Does anyone have a suggestion how I can fix this problem? Will I have to go back in time with Time Machine and restore my entire system to solve this?
    I can't operate with the desktop icons changing positions like this.
    Thanks,
    Pacecom

    Delete the hidden .DS_Store file associated with your Desktop folder. Launch the Terminal.app (in /Applications/Utilities/), copy & paste the following command into the window that pops up, hit the return key, quit the Terminal.app, OPTION-click and hold the Dock's Finder icon, and select Relaunch:
    *rm ~/Desktop/".DS_Store"*
    Now, set the Desktop as desired, log out and back in, and the Desktop should be as it was as you last set it.

  • When I upload an app, it asks for my password, then says it's incorrect.  When I reset it (after 3 tries) and put in the new one, it still says it is incorrect.

    When I upload an app, it asks for my password, then says it's incorrect.  When I reset it (after 3 tries) and put in the new one, it still says it is incorrect.  What am I doing wrong?

    I assume that you meant that you reset the password three times. Did you receive any verification that the new password was accepted?
    Sign out of you account, restart the iPad and sign in again. Settings>Store>Apple ID - tap the ID and sign out.
    Restart the iPad by holding down on the sleep button until the red slider appears and then slide to shut off. To power up hold the sleep button until the Apple logo appears and let go of the button.
    Go back to Settings>Store>Sign in again.

  • Audio shifts positions after recording?

    When I record something using my mic, whether it be audio or an instrument, the recording shifts over a few frames once I’m finished recording, which means I have to go back and manually line it up perfectly each time.  This is extremely frustrating, and sometimes it's nearly impossible to line the audio back up with the instrumentals.  How do I fix this and make it so that the recording stays in the same position after I finish recording it?

    peta_reynolds wrote:
    I have just opened my original file has the problem. The wave file looks perfect but on playback there seems to be a double up on audio.
    I know it sounds strange, but that actually makes some sense. What it means is that the .pkf file that Audition created (this is the quick visual display) is intact, but the audio it relates to has got itself misplaced. Now I'm almost certain that you have a HD problem, I'm afraid.

  • JTable changeSelection() method

    I use changeSelection method for my Jtable in an Anonymous class.
    jtable.addKeyListener(new KeyAdapter(){
      public void keyPressed(KeyEvent e)
       // when "enter key is pressed" ....
        jtable.changeSelection(row, col, false, false);
    });Initially selection in the first row, When Enter key is pressed and I set the change in the first row of the table(the row is still first row, index 0), but it still goes to the next row, index (1).
    When I set the col, it selects the column I want. Column selection is fine. but not row.
    Can anyone help
    Thanks

    I think your problem is being caused by the keylistener that the JTables UI will have added. This moves the row selection down a row when enter is pressed.
    I haven't got time to try this at the moment, but you could try something like
    jtable.addKeyListener(new KeyAdapter(){
      public void keyPressed(KeyEvent e)
       // when "enter key is pressed" ....
        jtable.changeSelection(row, col, false, false);
        e.consume();
    });

  • Flash Player remember window position after exit?

    How about make the Flash Player remember window position after exit?  So that it opens in our preferred position everytime?

    These are user-to-user forums.  If your suggestion is meant as a possible product improvement, use...
    Adobe - Wishlist & Bug Report
    http://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

  • HT5262 How to reset password after ipod says ipod disabled

    How to reset password after ipod says disabled?

    Place the iOS device in Recovery Mode and then connect to your computer and restore via iTunes. The iPod will be erased.
    iOS: Wrong passcode results in red disabled screen                         
    If recovery mode does not work try DFU mode.                        
    How to put iPod touch / iPhone into DFU mode « Karthik's scribblings        
    For how to restore:
    iTunes: Restoring iOS software
    To restore from backup see:
    iOS: How to back up     
    If you restore from iCloud backup the apps will be automatically downloaded. If you restore from iTunes backup the apps and music have to be in the iTunes library since synced media like apps and music are not included in the backup of the iOS device that iTunes makes.
    You can redownload most iTunes purchases by:
    Downloading past purchases from the App Store, iBookstore, and iTunes Store        
    If you previously synced to the computer then you may be able to recovery use of the iPod without erasing the iPod by following the instructions here:
    Disabled Recovery-must use syncing computer.

Maybe you are looking for

  • Insert Problem jdbc odbc

    I have problem with my Insertion code. here is my code:- import java.awt.*; import java.awt.event.*; import javax.swing.*; import java.sql.*; import java.lang.Class; import java.util.*; public class BookForm extends JFrame implements ActionListener  

  • Dynamic Type Conflect when assigning References error in portal

    Hi Forum, We have one ABAP Dynpro Application which runs fine but gives "Dynamic Type conflict when assigning References" error dump after integrating it with Netweaver portal 7 SP12 by creating Webdynpro ABAP iview. Please help us to resolve this is

  • Selective disable/enablement of sub workflows

    Hi, I am trying to design workflow with fork(For parallel execution) and many sub workflows. These sub workflows are totally independent of each other and cna have parallel execution. My requirement is to given an option for user to selectively enabl

  • Installing flash player on old sytem with window xp 32 bit

    Having trouble installing flash player. get to about 71% installled and then error out with failed to register.  Need help in find the correct soultion to fix the problem. I have tried about every solution that is recommended.  Had trouble the last t

  • File Explorer won't display image in local HTML file

    I'm studying HTML. I created a file, RECIPE.HTM and in it I have a tag to an image file, HOTDOG.PNG, located in the same folder.  When I open the RECIPE.HTM file, it displays correctly in the browser.  It will not display in the Preview Pane, however