My Canvas is on Top of My Scroller

Hi, I've been trying to right the code for a function grapher in netBeans.
I have the grapher class which extends java.awt.Canvas and draws a coordinate plane using its paint method. This grapher class is placed inside a scrollerPane with the following code:
graphScroller = new javax.swing.JScrollPane();
graph = new Grapher(width, height);
graphScroller.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
graphScroller.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
graphScroller.setViewportView(graph);
org.jdesktop.layout.GroupLayout graphPanelLayout = new org.jdesktop.layout.GroupLayout(graphPanel);
graphPanel.setLayout(graphPanelLayout);
graphPanelLayout.setHorizontalGroup(
        graphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(graphScroller, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 684, Short.MAX_VALUE)
graphPanelLayout.setVerticalGroup(
        graphPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
        .add(graphScroller, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 423, Short.MAX_VALUE)
);Whenever the size of the grapher is less than the scroller everything works fine, but when, for instance, the width is greater than the width of the scroller, the grapher extends past and covers up anything else in the program. It does, however, move back and forth whenever the scrollbar is moved. Is there some way to set like a z-index or something so that it is behind all the other elements? Thanks.

I don't know about GroupLayout, but with normal layout managers, you
either override getPreferredSize (and perhaps getMinimumSize and getMaximumSize) or call the corresponding get* methods. I never call setSize, because that is called by proper layout managers on you behalf:
import java.awt.*;
import javax.swing.*;
public class ComponentExample extends JComponent implements Runnable {
    public void run() {
        JComponent comp = new ComponentExample();
        comp.setPreferredSize(new Dimension(600,400));
        JFrame f = new JFrame();
        f.getContentPane().add(new JScrollPane(comp));
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setSize(400, 300);
        f.setLocationRelativeTo(null);
        f.setVisible(true);
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        int w = getWidth();
        int h = getHeight();
        g.setColor(Color.WHITE);
        g.fillRect(0, 0, w, h);
        g.setColor(Color.GREEN);
        g.drawLine(0, 0, w, h);
        g.drawLine(0, h, w, 0);
    public static void main(String[] args) {
        EventQueue.invokeLater(new ComponentExample());
}

Similar Messages

  • How can I have a browser image that scrolls with images on top of it scrolling in tandem -

    How can I have a browser image that scrolls with images on top of it scrolling in tandem - so the background is a hexagon pattern with small images inside some hexagons and I want them all to be scrollable as a user uses the browser scroll bars. At the moment the background image jumps when I preview so the small hexagons all become out of alignment. Any tips appreciated. I have browser image set to tile - pinned at the middle and set to scrolling - the small images are not pinned -

    Thanks for your answer - The images on the top layer are also links and change to show they're links on rollover - so I wanted to keep them as separate graphics - and it works to a point but when I preview the page in a browser the tiled browser image always moves no matter how I pin it and then everything becomes unaligned. Any further suggestions appreciated.

  • Is anyone else's icloud calendar scrolling up to the top, despite me scrolling down?!  It's very annoying!...Am using Google Chrome on a PC (at work) and a mouse with a roller for scrolling.

    Is anyone else's icloud calendar scrolling up to the top, despite me scrolling down?!  It's very annoying!...Am using Google Chrome on a PC (at work) and a mouse with a roller for scrolling.

    I FOUND THE SOLUTION....well, thanks to your link ELLEN!!!!
    https://discussions.apple.com/thread/4581925?start=0&tstart=0
    With Chrome open to iCloud calendar, hold down the Ctrl button and press the 0 (zero) button.  This will fix your problem.  Did mine!
    With thanks to wetintcars.com and husainfrommumbai!!!

  • Moving to top of a scrolling TextArea

    After updating a textarea where I'm displaying some information I call revalidate() on its scrollPane to check again if it needs to add scrollbars. Problem is it does this fine but it then scrolls to the end of the textArea. How can I move it back to the top of the textArea? I've searched all over the class libraries (to my best ability) and the Java tutorial also to no avail. Anybody got any suggestions?

    This might help..
    When you create your textArea add the scrollpane to it, but use AS_NEEDED, so they only appear when needed. But still as lots of text gets added it will scroll to the bottom. But now you dont need to call revalidate()
      JScrollPane scroll = new JScrollPane(text_area);
                        scroll.setVerticalScrollBarPolicy(
                   JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED );I would be interested to find out how to set the viewpoint to the beginning too.

  • How to keep the tables headers on top and never scroll with the table?

    does anyone knows the code to do so?
    urgent needed.
    thx.

    Hi
    Do you need a window shows in the below website???
    http://www.milonic.com/mfa/2004-August/004742.html
    If so, view source the page.
    Newt.

  • Scroll in a tab canvas

    I have a master fixed horizontal toolbar
    attached to a 2 page tabbed canvas.
    The first page is a detail block of say 5 records displayed vertically.
    How can I add a scroll bar verically to scroll tru my columns as there are lots some 20 columns for the first tab page only.
    Or is it that I should not condider using tab canvas?

    You need three canvas.
    1) A tab canvas as the one you have built.
    2) second canvas on top of page 1 of the first one , and you built you first block with vertical scroll bar on it
    2) a 3rd canvas on page 2 of the first canvas.
    You should have a scroll bar with you click tab1 and hide scroll bar when you click page 2 tab.
    null

  • Scrolling a canvas

    Hi
    I am tring to scroll a canvas
    Here is the code
    JScrollPane scrollPane = new JScrollPane(ca, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(500,500));
    scrollPane.revalidate();
    add(scrollPane, BorderLayout.CENTER);
    where ca is the canvas
    How do i get the scroll bars to dispaly and move the canvas, presently all is shown is the canvas with blank tracks?
    Thanx

    yeah it works but i don't want to implement a textArea but a canvas.
    The code i have for the canvas is
    class Canvas0 extends Canvas{
    public Canvas0(){}
    int ROOTx = 300;
    int ROOTy = 20;
    int rootx = 20;
    int rooty = 20;
    int textx = 275;
    int texty = 25;
    int KID1x = 250;
    int KID1y = 60;
    int kid1x = 20;
    int kid1y = 20;
    int text1x = 225;
    int text1y = 65;
    int KID2x = 200;
    int KID2y = 100;
    int kid2x = 20;
    int kid2y = 20;
    int text2x = 175;
    int text2y = 105;
    int KID3x = 150;
    int KID3y = 140;
    int kid3x = 20;
    int kid3y = 20;
    int text3x = 125;
    int text3y = 145;
    int LEAFx = 100;
    int LEAFy = 180;
    int leafx = 20;
    int leafy = 20;
    int text4x = 75;
    int text4y = 185;
         public void paint(Graphics g){
              Font f = new Font("TimesRoman", Font.BOLD, 12);
              String text;
              String text1;
              String text2;
              String text3;
              String leaf;
              g.setFont(f);
              g.drawOval(ROOTx,ROOTy,rootx,rooty);
              g.drawLine(ROOTx+5,ROOTy+5,KID1x+5,KID1y+5);
              text = OViewer.getMain();
              g.drawString(text,textx, texty);
              if(OViewer.getKids1().toString().compareTo("null") != 0){
                   System.out.println("111aaaaa");
                   g.drawOval(KID1x,KID1y,kid1x,kid1y);
                   g.drawLine(KID1x+5,KID1y+5,KID2x+5,KID2y+5);
                   KID1x = KID1x + 15;
                   KID1y = KID1y + 15;
                   text1 = OViewer.getKids1();
                   g.drawString(text1,text1x, text1y);
                   text1x = text1x+15;
                   text1y = text1y+15;
                   System.out.println("1111bbbbb");
              while(OViewer.getKids2().toString().compareTo("null") != 0){
                   g.drawOval(KID2x,KID2y,kid2x,kid2y);
                   g.drawLine(KID2x+5,KID2y+5,KID3x+5,KID3y+5);
                   KID2x = KID2x + 15;
                   KID2y = KID2y + 15;
                   text2 = OViewer.getKids2();
                   g.drawString(text2,text2x, text2y);
                   text2x = text2x+15;
                   text2y = text2y+15;
              while(OViewer.getKids3().toString().compareTo("null") != 0){
                   g.drawOval(KID3x,KID3y,kid3x,kid3y);
                   g.drawLine(KID3x+5,KID3y+5,LEAFx+5,LEAFy+5);
                   KID3x = KID3x + 15;
                   KID3y = KID3y + 15;
                   text3 = OViewer.getKids3();
                   g.drawString(text3,text3x, text3y);
                   text3x = text3x+15;
                   text3y = text3y+15;
              while(OViewer.getLeaf().toString().compareTo("null") != 0){
                   g.drawOval(LEAFx,LEAFy,leafx,leafy);
                   LEAFx = LEAFx + 15;
                   LEAFy = LEAFy + 15;
                   leaf = OViewer.getLeaf();
                   g.drawString(leaf,text4x, text4y);
                   text4x = text4x+15;
                   text4y = text4y+15;
    }//end of Canvas0
    Is this the problem with the scroll, will i have to use a swing draw facility instead of a java class?

  • How to fade out lines of scrolling Text as they reach top of screen

    Hello,
    What I require is scrolling text (full screen width) & the ability to make the lines of text fadeout as they reach the top of the screen. Making the scrolling text fade out as it reaches the top of the screen is easy with Final Cut Express & I think makes for a more polished presentation instead of the text scrolling off the top of the screen.
    I have tried using “feather” in the Mask effect in Final Cut Pro x but I cannot make the top line of full screen scrolling text fade. Is there any way to achieve this effect in Final Cut Pro x ?
    Thanks, JohnH

    Hello Luis Sequeira1 Thanks for your reply,
    As you can see Karsten Schlüter replied to an earlier request from me regarding the same subject & yes it is possible to obtain the fade effect using “feather” in the Mask effect. However I’m surprised that there is not an easier way to fade out the top line of scrolling text. I was hoping someone would have a quicker way of achieving the effect – It’s so quick with Final Cut Express. Either my iMac is not up to running Final Cut Pro x (3.06 GHz Intel Core 2 Duo with 4GB 800 MHz DDR2 SDRAM) or the Final Cut Pro X Trial version is different to the full version (Apple says both versions are the same) I find it hard to believe that an effect that is so easy in Final Cut Express is so difficult to achieve in the supposedly all singing & dancing Final Cut Pro x.
    JohnH

  • Photos - How to view newest photos at top of scroll

    In the new Photos App, Ho can you change the photos view screen so it shows the newest photos at the top of the scroll and the oldest photos at the bottom...
    We cannot find the option to flip it and it seems the default is oldest at top newest at bottom!... Not what we want!
    Does anyone know how to flip this?

    There's no way to do this that I'm aware of.

  • Making a line's coordinates adjust to a Dynamic/Scrolling Canvas

    Hi,
    I am trying to use Flex to develop a simple display... I have a canvas
    with couple of Buttons. I draw line between some of these buttons. As long as
    there is no scroll on the screen the line show up fine. But once width/Height 
    of the Canvas increases and you get the scroll... the lines don't scroll
    accordingly. The lines appear to be sticky on the Canvas rather than
    move with the buttons...
    Any idea how I can overcome this???

    Once i draw the line i add it as a child to the canvas. But when the size of the canvas changes, the line seems like it sticks to the canvas while the other components of the canvas adjust well.

  • Can I freexe a part of the website so it stays on top even if website scrolls.

    Here is an example.
    I have a picture.banner.......>>>>
    then going down I have a drop down menu for mobiles >>>>
    Then I have the content area......
    Whilst the user scrolls down the content area......
    I want the banner and the menu to stay on screen at the top and not scroll up off the screen.
    yet allow the menu to drop down....
    The rest of the page to scroll down as the user reads it.
    I am using the bootstrap framework so do not know how I can achieve this...
    Thanks in advance for any feedback.
    Terry

    Nancy O. wrote:
    No need for any of that.  Simply use the Bootstrap Affix class.
    JavaScript · Bootstrap
    Nancy O.
    Seriously?
    I don't know Bootstrap but looking at the link it would appear you have to link in a .js file and then call the affix using:
    $('#myAffix').affix({
      offset: {
        top: 100,
        bottom: function () {
          return (this.bottom = $('.footer').outerHeight(true))
    That cant be right, it must be simpler and less bloated than that?

  • Facebook "top bar" scrolls off

    One of the features of Facebook, and other sites, is that no matter where you are on the site, some content stays fixed.  For Facebook, this is the top bar which has the notifications, the search, and a couple of buttons like your account information.
    In Safari 6, this bar stays at the top just fine as long as you are on the page's natural font size.  You can scroll up and down all day and the top bar stays there.  However, if you zoom in a bit to make the font bigger, eventually scrolling down causes the top bar to scroll up and become not visible.  This is true no matter where I am on the page.  If I'm at the top, and then zoom, it will start to scroll off right away.  If I'm half-way down the page and zoom, the bar shows up as being there, and then scrolls off.
    So, it isn't like the bar just goes away.  It starts in the right place after a zoom operation, but then doesn't bahave properly when you scroll.
    I find this very annoying.  This does not happen in Chrome.  I can make the fonts much bigger, and the bar stays there.  As such, I'm still using Chrome.
    Note: this didn't work on Safari 5, either, but I figured they would have fixed it by now!

    More testing...
    On Chrome on Mac, and Chrome on Windows, if the top bar of FB is "all visible", meaning you haven't zoomed in so much that the top bar has lost some of the test to the right of the window or the left of the window, it always stays.  If you zoom in a lot such that, say, the "home" link, which is the right-most link of the FB bar, is outside the scope of the window, even Chrome doesn't keep the top bar in place.
    On IE under Windows 7, it operates just like Safari - any zoom causes the top bar to scroll away.
    I guess this isn't just a Safari thing, then, but Safari should still fix this!

  • Canvas not displaying controls added with addChild

    I have a custom class holding some information, a property in
    the class is an XML string and another method parses the XML add
    creates controls (labels and buttons) based on the xml. I also have
    a variable named renderer which is a mx.containers.Canvas. After
    the XML is loaded and the controls are added using
    Canvas.addChild() I add the Canvas to my stage. The problem I'm
    running into is that even though the Canvas is added to the stage,
    I cannot see any of the controls inside of the canvas. Doing a
    trace(Canvas.numChildren()); I can see that I have added 101
    children to my canvas container (which is what my xml file shows)
    however they will not display. I know the canvas has been added to
    the stage because I can see the scroll bars when i set the policies
    to "on" and it even sets the scroll bars correctly if the
    components are too big for the canvas and would have to be scrolled
    down to see them all, it just doesn't show any of the components.
    Anyone run into a similar issue?

    Did you set an explicit width and height (or percentWidth and
    percentHeight, or styles top, left, top, bottom) on the controls
    you create? By default controls have 0x0 size. Creating controls in
    MXML causes additional code to be generated which gives the
    controls default sizes, but it won't happen in your own
    ActionScript code.

  • Creating Scrolling Clouds in AS3

    Hi, ive spent the last 2 hours looking online for tutorials
    and such on how to create random scrolling clouds for a flash
    project im making, and after 2 hours ive found nothing at all.
    I have a canvas of 900x600, and i want clouds to span across
    900x150 of the canvas at the top. I want the clouds to go from
    right to left and overlay on the image below.
    Can anyone point me to a tutorial that will help me, or show
    me how i can make this myself... it seems there is little to no
    tutorials on the web that explains how to do this and its quite
    annoying.

    What exactly have you done? Have you drawn any of the clouds?
    Set them as movieclips or given them names?
    Assuming you've done that, in AS3 you'd simply want to create
    a function to move the clouds from right to left via their name and
    tie that to an event listener. For this simple example, make sure
    that your clouds are off the stage on the right or wherever you
    want them to start moving.
    quote:
    function moveWaterfall(e:Event):void{
    CloudName.x -= 1;
    if (CloudName.x < 0){
    CloudName.x = 900;
    quote:
    addEventListener(Event.ENTER_FRAME, moveWaterfall);
    If you have a cloud movieclip with the name CloudName, it's x
    position should reduce by 1 pixel every frame until it's x position
    becomes less than 0 in which case it's x position will reset to
    900. Adjust those values according to where you position your
    clouds.
    To increase the speed, either increase the number of pixels
    you're subtracting from the x value or increase your FPS.
    I hope this gives you some idea... I'm not exactly sure what
    you are all looking for.

  • Stacked Canvas Layout and Design

    I am trying to create a canvas template for use in our development environment. What I am wanting to do is to create a header and a footer section on this template with a stacked canvas in the middle. This stacked canvas would hold all of the content, data and controls for each form. This stacked canvas is the only thing that would change. The header and footer would look the same for each form. I am trying to create something similar to an HTML page with frames that defines header, content and footer frames. I want the user to be able to vertically scroll only the stacked canvas while the header and footer stay in position.
    My question is: How can I use the tools in Forms Builder to place controls in the stacked canvas? The builder does not allow me to scroll the stacked canvas in design mode so I can't reach all the areas of the stacked canvas. Does this make sense?
    I am using Forms 10g.
    Thanks...

    It isn't exactly clear, but assuming you have a content canvas (which I like to call the parent) and a stacked canvas "stacked" on top of the parent the there are several ways to put objects on the stacked canvas. Probably the easest and clearest is to simply find the stacked canvas in the Object Navigator and double click on it. This should open the Layout Editor with the parent canvas window selected (white boarder) and the stacked canvas displayed on top and selected (black boarder). Now just draw your objects on it. You can verify that they are on the stacked canvas by looking at the Properties for each object. You should see where you can choose which canvas you want the object to be displayed.
    If this does not work, look in the Builder menu "View" > "Stacked canvas..." and ensure that your stacked canvas is not being hidden. If the stacked canvas is already displayed in the Layout Editor, this menu item may be disabled.
    I am assuming you are using Forms 10.1.2 or newer. Older versions will be slightly different.

Maybe you are looking for

  • Erro na comunicação SEFAZ AM - Ambiente de Produção

    Bom dia Srs, Estou com problemas de comunicação com a SEFAZ AM, ambiente de produção. No "Service Status", mostra o ambiente de produção com erro 70, desde o dia 01.10.2010. Entrei em contato com a SEFAZ AM e eles dizem que não tem problema do lado d

  • Is there a limit to amount of code that can be added to the HTML Header?

    I've got several javascript functions in the HTML Header section of the page attributes. I recently added another function and now receive an HTTP 404 Not Found error at runtime when navigating to the page. When I remove the function the error is gon

  • Message Mapping UDF

    Hi Guys, For the UDF functions for messagemapping,Its a pain to code it using the dataflow editor provided in the repository. We are having the XI version 3.0(SP 20). So I decided to use eclipse for coding and debugging the functions and then copy it

  • Issue related with the Date Format --- error when activating the DSO

    Hi Friends.. plz help me to fix the issue ...im getting when activating the DSO... Actually im not getting error when loading the data thru DTP..im facing this issue while activating the DSO.. is there any routine to solve this or i have to go for da

  • Procedure - invalid status

    Hi all,      I have the procedure name val_xyz and it is worked fine upto july end and now while trying to compile the procedure, it is showing [email protected] invalid. I checked the status in the user_objects, it showing the status as "INVALID". C