Results 1 to 5 of 5
  1. #1
    nenadm is offline Member
    Join Date
    Nov 2008
    Posts
    19
    Rep Power
    0

    Default JFileChooser horizontal scrollbar problem

    Hi,
    I use JFileChooser to make possible to user to navigate among great number of files and folders. However it is desirable that file chooser always stay positioned on the position of last selected file.
    But for some reason horizontal scroll bar don't stay at last position but always stay centered. Moreover it have desirable behaviour only if user dont scroll horizontaly at all (remember position), but if user scroll to the end, close and again open file chooser, it dont remember last position.
    I am interested is it possible in some way to work upon on position of JFileChooser scroll bar or handle this situation.
    Thanks alot.

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    In my SSCCE the scroll position seems to persist. Are you doing something different than I'm doing here?
    Java Code:
    import java.awt.event.*;
    import javax.swing.*;
    
    public class JFCTest
    {
      private JPanel mainPanel = new JPanel();
      private JFileChooser jfc = new JFileChooser();
    
      public JFCTest()
      {
        JButton openJfcBtn = new JButton("Open JFileChooser");
        mainPanel.add(openJfcBtn);
        
        openJfcBtn.addActionListener(new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
          {
            jfc.showDialog(mainPanel, "Go For It!");
          }
        });
      }
    
      public JComponent getComponent()
      {
        return mainPanel;
      }
    
      private static void createAndShowUI()
      {
        JFrame frame = new JFrame("JFCTest");
        frame.getContentPane().add(new JFCTest().getComponent());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      }
    
      public static void main(String[] args)
      {
        java.awt.EventQueue.invokeLater(new Runnable()
        {
          public void run()
          {
            createAndShowUI();
          }
        });
      }
    }

  3. #3
    nenadm is offline Member
    Join Date
    Nov 2008
    Posts
    19
    Rep Power
    0

    Default

    Well just one thing and i think there is a problem, i set preferred position of my JFileChooser. When i use default window dimensions all works fine.

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,455
    Rep Power
    20

    Default

    Off hand I'd say that shouldn't be a problem either provided you set the position just once, before you display the chooser for the first time.

    db

  5. #5
    nenadm is offline Member
    Join Date
    Nov 2008
    Posts
    19
    Rep Power
    0

    Default

    Thank you guys,
    i find out that problem is in centering my file chooser.

Similar Threads

  1. Regd the scrollbar in a table in JSP
    By itmani2020 in forum Advanced Java
    Replies: 4
    Last Post: 08-13-2008, 02:26 PM
  2. Replies: 0
    Last Post: 07-02-2008, 09:06 PM
  3. Need JFileChooser Help
    By Wraithier in forum New To Java
    Replies: 4
    Last Post: 06-18-2008, 06:40 PM
  4. Using java.awt.Scrollbar
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-03-2008, 10:19 AM
  5. how to use JFileChooser
    By tommy in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •