Scrollpane scrolling manually to component

Sorry that I am spamming another post that is not a question, but again I was fighting with Swing over something quite poorly documented and I must share my victory for future people that may struggle with the same (and use the forum search).
Situation: a scrolling panel which manually handles scrollwheel scrolling. This will select one of the many JLabels holding icons in the panel, giving them a colored border when the active one.
Requirement: when a label is selected that is out of view, the scrollpane should scroll to make that label visible.
Now after examining the javadocs I realized that scrollRectToVisible() is the solution. This method requires a Rectangle of the position to scroll to, which you can easily get by calling getBounds() on the component (label in my example) that must be visible. So what I did was:
- call scrollToVisibleRect() on the JScrollPane. This does not work, to my surprise
- call scrollToVisibleRect() on the viewport. This works partially, the scrollpane scrolls down, but it will never scroll up
- I also tried validate() here and there just to know for certain I am not crazy
And finally after some more hair pulling and a google quest I stumbled upon the answer; you need to call scrollRectToVisible() on the component that you wrap the scrollpane around, not the scrollpane itself! So if you have something like:
JPanel mypanel = new JPanel();
JScrollPane sp = new JScrollPane(mypanel);You need to call mypanel.scrollRectToVisible() to make the scroll work!
Source of the solution:
http://www.esus.com/docs/GetQuestionPage.jsp?uid=989

Its kind of dumb how they have when that broadcasts when
scrolling is going on but not one directly when its stops.
Thanks for your help.
Heres what i used:
_root.onMouseUp = function () {
if (_xmouse>=0 && _xmouse<=555 &&
_ymouse>537 && _ymouse<558) {
trace('stop that');
}

Similar Messages

  • Scrolling a custom Component (e.g. JPanel) with overridden paint(Graphic g)

    Hi.
    I&#8217;m creating an application for modelling advanced electrical systems in a house. Until now I have focused on the custom canvas using Java2D to draw my model. I can move the model components around, draw lines between them, and so on.
    But now I want to implement a JScrollPane to be able to scroll a large model. I&#8217;m currently using a custom JPanel with a complete override of the paint(Graphic g) method.
    Screen-shot of what I want to scroll:
    http://pchome.grm.hia.no/~aalbre99/ScreenShot.png
    Just adding my custom JPanel to a JScrollPane will obviously not work, since the paint(Graphic g) method for the JPanel would not be used any more, since the JScrollPane now has to analyze which components inside the container (JPanel) to paint.
    So my question is therefore: How do you scroll a custom Component (e.g. JPanel) where the paint(Graphic g) method is totally overridden.
    I believe the I have to paint on a JViewport instructing the JScrollPane my self, but how? Or is there another solution to the problem?
    Thanks in advance for any suggestions.
    Aleksander.

    I�m currently using a custom JPanel with a complete override of the paint(Graphic g) method. Althought this isn't your problem, you should be overriding the paintComponent(..) method, not the paint(..) method.
    But now I want to implement a JScrollPane to be able to scroll a large model.When you create a custom component to do custom painting then you are responsible for determining the preferredSize of the component. So, you need to override the getPreferredSize(...) method to return the preferredSize of your component. Then scrolling will happen automatically when the component is added to a scrollPane.

  • No audio when scrolling manually

    Hi. audio is on when I play clips at normal speed, in both canvas and viewer, but off when I scroll manually in canvas and viewer or play clips/sequences at reduced or increased speed (e.g. when using the 'l' and 'j' functions).
    This never happened before. I must have changed a setting by mistake. Anyone know how to fix?

    http://discussions.apple.com/help.jspa#questions

  • TS3899 I just switched to Iphone 5c from Blackberry...is there a way to jump from the 1st email listed to the bottom of the list (sometimes 300-400) without scrolling manually thru them all?  Also is there a way to organize them by sender?

    I just switched to Iphone 5c from Blackberry...is there a way to jump from the 1st email listed to the bottom of the list (sometimes 300-400) without scrolling manually thru them all?  Also is there a way to organize them by sender?

    Well, I think I know why the rules are not working. The alias mailbox is being listed as another mail folder  and not as an actual inbox so the rules are not being applied. While I wish the rules would work, I will continue to manually mark some of the emails as spam.
    As for the second issue with emails vanishing, I am waiting to see if it happens again. I think it must happen when it is syncing the data but I am not sure that it happens all the time. Today the previous emails seem to be their and it grabbed the new email so I don't know what happened with the vanishing email. Anyway this can be closed since I believe the main issue has been solved as being a setup issue with Yahoo alias email account.

  • Please Help me place the arrows of my ScrollPane scroll bar together on one end of the scroll track!!

    I have a scrollpane component with a movie clip of some
    thumbnail images.
    I just want to have its scrollbar arrows together on one end
    of the track (or together ANYwhere) instead of having them at
    opposite ends of the scroll track.
    I have been able to customize the appearance of the
    scrollpane and its scrollbar using the HaloTheme library, but that
    approach has so far been of no use in getting the arrows together.
    I cannot tell you how deeply any help will be appreciated. I
    will probably sob and mewl with gratitude, the way I imagine
    someone lost in a vast rain forest for many weeks mewls when
    rescued. I am desperate. I am going insane. Please, please help me.

    Cherrylanenc are you on a managed network?  If not then I would recommend reviewing the steps listed in Sign in, activation, or connection errors | CC, CS6, CS5.5 - http://helpx.adobe.com/x-productkb/policy-pricing/activation-network-issues.html.

  • Horizontal scroll for Tree component scrolls too far right

    I've enabled the horizontal scroll bar for the Tree component.
    But the scroll bar allows the user to scroll very far to the right into blank space.
    The maximum width of my components measures 124px, as calculated by measureWidthOfItems(0,0), and I've verified this by measuring pixels of a screen shot.
    I have tried adding an event to set the Tree.maxHorizontalScrollPosition, and I traced the value that I'm setting it to, and I also traced the value that it actually assumed after I set it. Both are 124px.
    So I can't understand the behavior. I can scroll something more like ~400px to the right with lots of blank space.
    Any ideas why?
    Thanks,
    David

    Hmm, I'm not sure why this works, but it works, so for completeness here's what I did (in case anyone else runs across this same thread):
    var measWidth:Number = myTree.measureWidthOfItems(0,0);
    filesTree.maxHorizontalScrollPosition = measWidth - myTree.width;
    I call the above code whenever the window is resized (in my app there are 2 places that can cause a resize of the window, I manually added calls to a function with the above code). There is also an example out there that resizes any time the window is resized, but if you do this then you really can't have liveDragging=true in a DividedBox (which I have) because the cost of resizing is very high and overtaxes the cpu when called many times consecutively. I just call it when the dragging is finished (that way I have live dragging enabled, but it only updates the scroll bars when the user stops dragging, which is visually acceptable).

  • ScrollPane scrolling

    Is there any way to capture the event when a user stops
    scrolling a scrollPane component. Right now I have actions set to
    take place when my scroll listener hears the user scrolling, but i
    have no way of stopping them once they let up/release the scroll
    bar. I thought to use an onRelease but that turned the entire thing
    into one big button that didnt let you scroll at all.

    Its kind of dumb how they have when that broadcasts when
    scrolling is going on but not one directly when its stops.
    Thanks for your help.
    Heres what i used:
    _root.onMouseUp = function () {
    if (_xmouse>=0 && _xmouse<=555 &&
    _ymouse>537 && _ymouse<558) {
    trace('stop that');
    }

  • Reskinning scrollPane scroll bar

    Hey. I'm trying to resking the scroll bars of the scrollPane
    component
    in Flash 8 and haven't quite figure it out using the standard
    / limited
    Flash Help provided. I've been able to use the Help to reskin
    a
    standard UIScrollBar component by duplicating / altering the
    desired
    states. This is the simple code placed on the scrollBar
    instance on
    the timeline that can redirect it to use a new instance:
    onClipEvent(initialize){
    downArrowDownName = "ScrollDownArrowDown2";
    ScrollDownArrowDown2 obviously being the new movie clip.
    However, even
    though Flash Help tells me that the scrollPane component
    utilizes the
    UIScollBar elements and to refer to that section to alter the
    ScrollPane, I cannot simply use the code above on the
    scrollPane
    component. It sounds like this should be fairrly easy to
    figure out,
    but I'm out of options. Thoughts?

    anybody?

  • Horizontal Scroll in list component

    Hi,
    I'm using a list component which is populated from a textbox.  I've set the horizontal scroll policy to auto and also to on however  the scroll either doesn't appear (in the case of auto) or doesn't move (in the case of on).  Is there a setting which I need to modify to have the horizontal scroll working normally?
    Thanks

    I tried the invalidate method as follows but nothing happened:
    mylist.invalidate();
    Not sure if I explained myself well, I just want the horizontal scrollbar to appear and be able to move it when one or more items in the list are long and thus not all visible...thanks

  • Implementing a graph scrolling using JScrollPane component

    I would like to ask a question apropos using of JScrollPane component. A part of the default behaviour of this component is adjusting the component's state when the size of the client changes. But, I need to achieve an opposite effect - I need to adjust a size of my client when the size of JScrollPane (and its viewport) changes (for instance, when the user resizes the frame).
    I implement a graph component which will show the graph of a time function. This component should always show nnn seconds without connection to the size of the scroll pane's viewport. So, if the the scroll pane component is resized I need to adjust the size of my client in order to keep the displayed time period unchanged.
    Now the question: how may I check the size of the viewport when the size of the JScrollPane changes? And whether I can do it even if the JScrollPane component has no client?
    If you know any other method of achieving the same effect, plese let me know.
    Thanks.

    I still find getExten\tSize (and getViewRect) work for me. Here's another demo.
    In my component, there's a big oval thats bounded by my component and a smaller
    oval that should track with the viewport's bounds.
    import java.awt.*;
    import javax.swing.*;
    public class ViewportLemonJuice extends JPanel {
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawOval(0, 0, getWidth(), getHeight());
            Container parent = (Container) getParent();
            if (parent instanceof JViewport) {
                Rectangle rect = ((JViewport) parent).getViewRect();
                g.drawOval(rect.x, rect.y, rect.width, rect.height);
        public static void main(String[] args) {
            JComponent comp = new ViewportLemonJuice();
            comp.setPreferredSize(new Dimension(800,800));
            JScrollPane sp = new JScrollPane(comp);
            sp.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
            JFrame f = new JFrame("ViewportLemonJuice");
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.getContentPane().add(sp);
            f.setSize(500,300);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • How to Scroll the UIScrollBar component to the top?

    I'm using the UIScrollBar with a dynamic text field. If
    content gets scroll by the user, and then the text fiel dis update
    with new text, the new text remains "pre-scrolled". So, obviously,
    I want to set the scroll position to 0 every time I update the
    content in that field. But how do you do this?
    Is this something I do to the text field or to the
    UIScrollBar component?
    What is the method?
    Could somebody please give me an example?
    Thanks in advance...

    Silly me, I think I walked past this one several times
    thinking I had tried it.
    // To scroll the UIScrollBar to the top
    info_txt.scrollV = 1;
    My problem was that I was using the parantheses to pass the
    value, like this:
    // This doesn't work
    info_txt.scrollV(1);

  • Scrolling to a component

    I have a JPanel that contained withn a JScrollPane (called flowchartPane). The JPane contains other JPanels that are arranged with a grid layout.
    These JPanels contain graphics and when put together in various combinations make a flowchart.
    The actual size of the JPane is larger than the viewport of the JScrollPane. So there are times when I want to scroll to a perticular component that is out of the bounds of the view port rectangle.
    I am aware of the scrollRectToVisible method and have been utilising it in my method. However my method seems to be unreliable.
    What the method attempts to do is, if a component (comp) has its left, right, top or bottom edge outside the bounds of the viewport scroll the viewport so the component is in view.
    However this method is not reliable and does not allways do what is expected. Can anyone think of anyway I can improve it, see what I am doing wrong or help in the writing of a scroll to component method.
    Kind regards
    Andrew Scott.
       public void scrollToComponent( Component comp)
           int x = comp.getLocation().x;//get x location of  the component
           int y = comp.getLocation().y;//get the y location of the component
           int h = comp.getHeight();//get the height of the component;
           int w = comp.getWidth();//get the width of the component
          Rectangle vr = flowchartPane.getViewport().getViewRect();
          int newY = vr.x;
          int newX = vr.y;
          //if outside the bounds of the viewport
          if (  ((x+w) > (vr.x + vr.width)) |  (x < vr.x) |
          ((y+h) > (vr.y + vr.height)) | (y <  (vr.y))) 
            //Do not attempt to scroll to an posision zero or less on the X axis
            if (x-w > 0)
              newX = x;// - w ;
            else
              newX = x;
            //Do not attempt to sctoll to a position zero or less on the Y axis
            if (y - (h/2) > 0)
             newY = y;// - (h/2);
            else
              newY = y;
            flowchartPane.getViewport().scrollRectToVisible(new Rectangle(newX,newY,vr.width,vr.height));
          }//end if
       }//End Scroll to Component

    Stanislav,
    Close, but no cigar. I will say that is the best solution yet, but its far from perfect.
    It does not want to scroll upwards or to the left. It will only scroll to the right or down.
    Why is that??
    From your ideas Stanislav I developed this method:
    public void scrollToComponent( Component comp)
         Rectangle vr = flowchartPane.getViewport().getViewRect();
         int centerX=comp.getBounds().x + comp.getBounds().width/2;
         int centerY=comp.getBounds().y + comp.getBounds().height/2;
         int newX=centerX-vr.width/2;
         int newY=centerY-vr.height/2;
        flowchartPane.getViewport().scrollRectToVisible(new Rectangle(newX,newY,vr.width,vr.height));
    }//end scroll to componentKind Regards.
    Andrew.
    Message was edited by:
    scottie_uk

  • [Issue]Scrollpane Scrolling

    I'm guessing this is the correct sub-forum since I'm not using Actionscript.
    Issue:
    I have a movie clip that is basically a container for images with text descriptions. Everything works except when you try and scroll using a mouse-wheel. When you using this the scrollpane only seems to scroll down about 4 lines (@ 18pt font size) and then you have to either move the mouse around the scrollpane area while scrolling down or hover over the scrollpane's scroll bar. The actual movie clip is more or less only half viewable using the mouse-wheel and not doing one of the two methods I listed above.
         I've tried searches and it seems that no one else has ever had this issue.

    I'm guessing this is the correct sub-forum since I'm not using Actionscript.
    Issue:
    I have a movie clip that is basically a container for images with text descriptions. Everything works except when you try and scroll using a mouse-wheel. When you using this the scrollpane only seems to scroll down about 4 lines (@ 18pt font size) and then you have to either move the mouse around the scrollpane area while scrolling down or hover over the scrollpane's scroll bar. The actual movie clip is more or less only half viewable using the mouse-wheel and not doing one of the two methods I listed above.
         I've tried searches and it seems that no one else has ever had this issue.

  • How to make scrollpane scroll with textfield focus

    I have a JScrollPane that contains a JPanel with a grid of Labels and JTextFields for data entry. When I tab through the textfields down the panel - reaching fields that are out of view, the scroll pane does scroll down fields with the cursor - keeping the cursor in view.
    Is there a way to do this? I've tried some things, but I have not been able to get this working.

    here you go..
    package com.u2d.focustest;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.FocusEvent;
    import java.awt.event.FocusAdapter;
    public class KeepCursorInView extends JFrame
       public KeepCursorInView()
          JPanel contentPane = (JPanel) getContentPane();
          JPanel fieldPanel = new JPanel(new GridLayout(12, 3));
          JScrollPane scrollPane = new JScrollPane(fieldPanel);
          contentPane.add(scrollPane, BorderLayout.CENTER);
          for (int i=0; i<36; i++)
             addField(fieldPanel);
       private void addField(final JPanel panel)
          final JTextField tf = new JTextField();
          panel.add(tf);
          tf.addFocusListener(new FocusAdapter()
             public void focusGained(FocusEvent e)
                Rectangle bounds = tf.getBounds();
                panel.scrollRectToVisible(bounds);
       public static void main(String[] args)
          JFrame f = new KeepCursorInView();
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          f.setBounds(100,100,400,400);
          f.setVisible(true);
    }

  • How can I manually adjust component numbers and names?

    I am developing a set of circuit diagrams that have to be complementary.
    Now I run into the problem that the component names change from one project to the other.
    Is there a way to adjust the component numbering manually?
    When I have multisim renumber the components automatically it becomes a mess.
    Does anyone have a suggestion for me? I have been trying all kinds of solutions but most of these create error messages.
    When I remove the components and rebuild part of the circuits, at a certain point multisim renumbers the components again automatically. I cannot stop that, the only option is to press "OK"...
    In the attachment is my circuit diagram.
    I wish to have opamps numbered U1A, U1B, U1C, U1D, U2A, U2B etc.
    Further I would like to have the power pins show only on the U?A OpAmps, so I can indicate them to be connected once instead of four times.

    Hi,
    - To manually change the refdes(reference designator), double-click on the component and go to the Label tab.
    - When you have a multi-section component like an opamp which shows the power pins on each symbol, it is not really a good idea to modify an instance of the symbol and remove these pins. When you will connect one of the pins to power, you will see that an x will appear on the remaining sections telling you that this pin is now connected.
    Hope this helps.
    Regards,
    Tayyab R,
    National Instruments.

Maybe you are looking for

  • How do I disable automatic hyperlinking in Apple Mail, Mavericks?

    I typed the text of an email address with 'at' instead of @ and the remainder of the email address. I expected it to appear as all text but part of it came out as a link (I did not set it as a link) which linked to my website which I did not want. I

  • IPod Touch 2 gen (16 GB) will not update

    My iPod Touch will not update to version 3. iTunes stops in the middle of the process of downloading the update file, and tells me the network connection has been reset. I have also tried restoring it, but the same thing happened and now the iPod wil

  • The database is at release 8.52. The PeopleTools being run require database

    Created a DEMO system using PeopleTools 8.51 and HCM 9.0 . Connecting through Application Designer shows the message 'The database is at release 8.52. The PeopleTools being run require databases at release 8.51. Do I need to run rel851.sql to change

  • Object services for Object relational Mapping

    Hello everyone, The Object Services of ABAP Objects can create the corresponding Object Model from existing database tables. Is it either capable to carry out an Object relational mapping, just like Hibernate does forJava. Thanks a lot.

  • Solution Manager DB was installed in 'Simple mode'

    We are just a couple months into our first SAP installation.  I just received this message from my hardware/server guy: "Please be aware that the Solution Manager DB was installed in “Simple mode.”  This means that we don’t have transaction logs, and