Paint drawing unscrolled graph over scrolled graph! JScrollPane JViewport

I am planning to create a JScrollPane that has a scrollable JPanel. I have created a special paint method for the JPanel.
The JPanel contains a simple graph.
The graph will be scrolled with the JScrollPane.
evreything is good until now.
I want to draw (over the JPanel) another graph which I dont want it to be scrolled by the JScrollPane.
I want: When moving the scrolls, the graph moves but the special graph does not get effected.
I planned to overrirde the paint method of the JViewport object. I can see that the plan is good and the result is 80% pluasable, however, I am experiencing some effects:
1- sometimes the special graph does not get painted!
2- sometimes when moving the scrolls the up and down, the special graph does move, as if the contents are not updated.
I am using Java 5 update 6!
Here is my code, please test it your self:
package test;
import javax.swing.*;
import javax.swing.event.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
public class Test{
     public static void main(String[]args){
          JFrame f=new JFrame();
          JPanel p=new JPanel(){
               public void paintComponent(Graphics g){
                    super.paintComponent(g);
                    g.setColor(Color.red);
                    for(int i=0;i<4000;i+=20){
                         g.drawLine(0,i,800,i);
          JViewport port=new JViewport(){
               public void paint(Graphics g){
                    super.paint(g);
                    g.fillRect(0,0,70,70);
          port.setView(p);
          p.setPreferredSize(new Dimension(500,4000));
          JScrollPane pane=new JScrollPane();
          pane.setViewport(port);
          f.add(pane);
          f.pack();
          f.setDefaultCloseOperation(f.EXIT_ON_CLOSE);
          f.setVisible(true);
}

This makes use of the fact that heavyweight/awt components are rendered over lightweight/swing components. Another way to do this is with a glass pane (JRootPane api). The tutorial has an example of glass pane use.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class FloatingControls
    private JPanel getContent()
        JPanel panel = new JPanel();
        OverlayLayout overlay = new OverlayLayout(panel);
        panel.setLayout(overlay);
        panel.add(getControls());
        panel.add(getGraphicComponent());
        return panel;
    private JScrollPane getGraphicComponent()
        JPanel p=new JPanel()
            public void paintComponent(Graphics g)
                super.paintComponent(g);
                g.setColor(Color.red);
                for(int j=0;j<4000;j+=20)
                    g.drawLine(0,j,800,j);
        p.setPreferredSize(new Dimension(500,4000));
        return new JScrollPane(p);
    private JPanel getControls()
        GridBagLayout gridbag = new GridBagLayout();
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        Panel awtPanel = new Panel(gridbag)
            public void paint(Graphics g)
                super.paint(g);
                int w = getWidth();
                int h = getHeight();
                g.setColor(Color.blue);
                g.fillRect(0,0,w-1,2);      // top
                g.fillRect(0,2,2,h-5);      // left
                g.fillRect(0,h-3,w-1,2);    // bottom
                g.fillRect(w-3,2,2,h-5);    // right
            public Dimension getPreferredSize()
                // beware of different plaf settings
                return new Dimension(350, 45);
        awtPanel.setBackground(Color.pink);
        for(int j = 0; j < 4; j++)
            awtPanel.add(new JButton("button " + (j+1)), gbc);
        JPanel panel = new JPanel(gridbag);
        panel.setOpaque(false);
        gbc.insets = new Insets(0,5,0,20);
        // an option, works with insets
        //gbc.fill = GridBagConstraints.HORIZONTAL;
        panel.add(awtPanel, gbc);
        return panel;
    public static void main(String[] args)
        JFrame f = new JFrame();
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.setContentPane(new FloatingControls().getContent());
        f.setSize(400,400);
        f.setLocation(200,200);
        f.setVisible(true);
}

Similar Messages

  • How to draw cumulative line graph over the stacked bar chart?(SSRS)

    Hello, 
    I need your help to draw a cumulative line graph over this bar chart. 
    I need your help to draw a cumulative line graph over this bar chart in SSRS.
    The dimension (Category Group) is "Hour" in this case. and expression is sum of two distinct values like 'Y' and 'N' in Activity column(Series Groups). The sum(Activity=Y) in green color and sum(Activity='N') in Red color.
    I require to draw a cumulative line graph in this same chart, that should give the result of cumulative Sum(Activity) for each hour?? I mean sum of (Y+N) for each hour and that should be cumulative over the hour.
    I mean sum of (Y+N) for each hour and that should be cumulative over the hour.
    SSRS Version details:
    Microsoft SQL Server Reporting Services Designers 
    Version 10.50.1600.1
    --Siva

    Hi Siva,
    It seems that you need to verify your email address to post images, etc
    Besides,  Microsoft® SQL Server™ 2008 Reporting Services: Step by Step is a good choice to you. With STEP BY STEP, you work at your own pace through hands-on, learn-by-doing exercises. A companion CD includes data sets and sample code. You can download
    it from this link http://my.safaribooksonline.com/9780735626041 Click the Extras, you can get the samples and database from Supplemental Content.
    And there are vast of valuable articles and SQL Server Reporting Services Books Online in MSDN ,you can click these link to begin your learning journey, SQL Server Reporting Services 2008 Books Online:
    http://msdn.microsoft.com/en-us/library/ms159106(v=SQL.100).aspx 
    Besides these, there are still many valuable videos in Microsoft Webcast, click this link
    https://msevents.microsoft.com/cui/SearchDisplay.aspx?culture=en-US#culture=en-US;eventType=0;sortKey=;sortOrder=;pageEvent=false;hdnInitialCount=;searchcontrol=yes;kwdAny=Reporting%20service to register with a windows live ID, then download the ones you
    want.
    Hope this helps.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Display Data on waveform chart or XY graph over a long period of time

    Display Data on waveform chart or XY graph over a long period of time
    Can anyone help?
    I am acquiring data from an Ni DAQ card with the following parameters - sample rate = 12800, number of samples = 4096. I want to extract order information so as to track changes in the amplitudes of certain frequency harmonics. So I use the sound and vibration toolkit to extract this information as shown in the attached Vi.  I will like to plot the resulting amplitudes against real-time starting at the time the Vi was run.  I really want the display to show these changes over long periods (eg. days, months and even years).
    Problem.
    I have tried to plot the Y component of the resulting magnitude for a given order on a waveform chart. My choice of the waveform chart is because I also want to display  alarm limits (using the mask and limit vi) (I can't have these lines displayed on an XY graph plot).  I tried adjusting the scale offset using the property node and setting the offset to current time. However, the display on the X-axis can only show a span of  2 minutes as will be seen when you run the attached vi. I want the time display on the x-axis to be over a period of  days, months  and even years.  Is there a way to set the maximum scale on the x-axis to be say a year or so in future.
    I really want the display to be like the one in in the second attachment.
    Attached is a sample VI created using an Ni USB 9234 DAQ card. Any card will do but I am only getting the signal from one channel for this example
    I will appreciate any help that can be given to me.
    Thanks
    Attachments:
    Real-Time Graph Display.vi ‏170 KB
    Sampe screen1.doc ‏37 KB

    Long term testing can be tricky- and we'l get into that later.  Lets start with the basics that you have wrong.
    The vi as you have constructed it has only one memory element, the chart history length (default is 1024.)
    You can change the number of points the Chart will remember by Right-clicking the chart an select Chart History Length from the menu.
    But for a long term test - and one where you want to REMEMBER the first value you need a memeory element that is independant of the application.  Your PC WILL loose power or need to be rebooted eventually.  Heck it might even need to be replaced! you really need to store your data in a file. Preferablly in a file that is backed-up on a regular basis so you don't lose every point of data if the PC dies.  It realy hurts when you have to restart a 2yr test because you've lost the 18months of data you collected.
    For an application like this I would seperate my "collection" and "Evaluation" operations. 
    Have one vi that takes the reading and writes it to a file at a configurable rate  You may want 1reading  per minute for seveal days then 1 per hour for a few weeks- then maybe only once or twice a week for the next couple of years since you are looking for LONG TERM stability.  having too much data to evaluate can take a lot of digging to find the few things that interest you (but always take more that you think you need)
    Have another utility that COPIES the files, reads them and displays the data you are interested in that day.  The data you want to look at won't change over time HOWEVER, you WILL want to analize it in different ways depending on what the data trends look like.  Having seperate routines for collection and display allows you to update the display style and analisys without even stopping the collection vi (much less editing the vi)
    Jeff

  • How to add a scroll bar within a view window ?I want to display x and y axis outside the scoll window and keep those axis static and move the graph within scroll area

    how to add a scroll bar within a view window ?I want to display x and y axis outside the scoll window and keep those axis static and move the graph within scroll area
    ananya

    Hey Ananya,
    I believe what you want to do is possible, but it will not be
    easy.  If you want to add a scroll bar that will scroll the graph
    back and forth but keep the axis set, you would want to add a
    horizontal or vertical scrollbar.  Then you would create an event
    handler for the scroll event.  You would have to manually plot
    different data within this scroll event.  Unfortunately, there is
    not really a built in way to do this with the Measurement Studio plot
    control.
    Thanks,
    Pat P.
    Software Engineer
    National Instruments

  • Adf Dvt bar graph zoom/scrolling to given zoom level

    Hi,
    I am developing a dashboard, where I need a functionality with bar graph, that will zoom bar graph at particular zoom level while loading.
    Please help me, How can I pass zoom level to bar graph to zoom in at loading time?
    Thanks,
    Jassi

    Thanks Vlad for response,
    <dvt:barGraph id="barGraph" subType="BAR_VERT_STACK" shortDesc="Query Result Graph"
    tabularData="#{demo.graphTabularDate}" seriesRolloverBehavior="RB_HIGHLIGHT"
    animationOnDisplay="auto" animationOnDataChange="alphaFade"
    dynamicResize="DYNAMIC_SIZE" imageFormat="AUTO" visualEffects="AUTO"
    binding="#{demo.graph}">
    <dvt:o1Axis scrolling="on" /> <!-- *** Here I have implemented zoom to but here I want, when I have lots of bar in graph then my graph loads with some initial zoom level or with max zoom***-->
    <dvt:legendArea scrolling="asNeeded" automaticPlacement="AP_NEVER" position="LAP_RIGHT" />
    <dvt:o1TickLabel tickLabelSkipMode="TLS_AUTOMATIC"/>
    </dvt:barGraph>

  • How can I draw two matrixes in one graph???

    I have to draw two matrixes in one graph.
    Matrix size is 10 X 100, 10 X 100.
    Help me!
    Have a good day!

    You can do this by adding multiple plots to the graph's plots collection and then plotting each matrix on its own plot. The easiest way to add additinal plots to a graph's plots collection is to right-click on the graph in the dialog editor, click on Properties, click on the Plots tab, and then click the Add button to add additional plots.
    Now if you have a member variable for the graph in your dialog class (let's call it m_graph for this example), you could do this:
    // Plot the first matrix
    m_graph.Plots.Item(1).PlotXY(/* Your first 10x100 matrix data */);
    // Plot the second matrix on a different plot, but same graph
    m_graph.Plots.Item(2).PlotXY(/* Your second 10x100 matrix data */);
    - Elton

  • Concatenate XY Graphs over multiple iterations

    Is there a way to pass an XY graph (via a shift register) that's generated every iteration to the next iteration, and add its values to a graph that's on the front panel?

    What does this code have to do with xy graphs?
    Don't you want to initialize the shift regisiter? (Else the time array will grow without bounds. Shouldn't it be the same size as the glucose array?) In fact you don't need a shift register. A plain autoindexing output tunel would suffice.
    Why do you use "insert into array" instead of "built array (concatenate mode)".
    Since your time array points are spaced equally, you don't need an xy graph. a plain graph is suffiient. Just set x0 and dx according to your data.
    (Use a different browser if you have problems posting)

  • Draw a line over a JLabel

    Hello,
    Does anyone know if there is a way to draw a line over a JLabel. The scenario is that I have a Jpanel that uses a Gridbaglayout and has an array of JLabels(to display images). I have the need to connect labels and to have the line draw over any labels that it intersects.
    I know this can be done if you use the same graphics context to draw the image and the line, but since I need to use JLabels and the graphics context that draws the line is a JPanel's, I have a problem.
    Is there a way to draw a line over a JLabel?
    Thanks
    lon

    Easiest thing to do would be to override paintChildren like
    public void paintChildren(Graphics g) {
      super.paintChildren(g);
      //paint your line here
    }That should do what you want - paint the children first and then draw over them

  • ALV Graphs: How to set line type graph as default graph

    Hi All,
    I need to develop a line graph. The fields on the X-axis will change dynamically. Some times they may be 10 field and some times they may be more than 100 fields. I tried with Function Module GFW_PRES_SHOW_MULT. But I can only display maximum 32 fields. Can anyone tell me exact program which helps me to full fill my requirement. It will be a great help if you could told how do display line type graph as default graph in ALV.  In REUSE_ALV_GRID_DISPLAY there is a Exporting parameter MT_CHART_TYPES but this help you only to enter description for X-axis and Y-axis.
    Many thanks in advance.

    I would call GRAPH_MATRIX_2D with options depending on representation you wish
    look at the program GRBUSG_1 to see how to use it
    there you have some options to display bar chart, but you could use other values (complete list of options is available in documentation of function module GRAPH_MATRIX_2D - click on parameter OPTS in help display to see full explanation)
    exemple:
    P2TYPE = LN to display lines

  • What is a good paint/drawing app?

    In a recent news release fromApple, they mentioned a fellow doing a cover for the New Yorker magazine.
    Does anyone know what paint/draw App he used for this?
    j.v. fromnc

    I believe the App used was Brushes. Brushes is no longer in the App store. It has been replaced by Brushes 3.
    I like Art Rage myself.

  • "no attached graph model or graph model is null" - error message

    Hi,
    When i try to ceate a inbound file adapter for customer data tutorial , i get the floowing message
    *"no attached graph model or graph model is null"*, My jdeveloper version is 10.1.3.4.0.4270

    This is what works on 8.1.7. I don't know the svrmgrl name in 8.0.5, but it should be in your %ORACLE_HOME%/bin
    > cd %oracle_home%\rdbms\admin
    >svrmgr sys/<password>@dbname
    SVRMGR> @standard
    Statement processed.
    Statement processed.
    Statement processed.
    SVRMGR> @UTLRP
    if this doesn't work then do this
    SVRMGR> @catalog
    good luck

  • Please help! - Illustrator CC - editing path messes up entire live paint drawing

    Example of problem in this image:
    http://ccteardrop.files.wordpress.com/2013/10/dana-solomon-adobe-cc-problem.png
    Basically, whenever I have a finished illustration, I go back and make a few tweaks to different paths. In previous versions of illustrator, this had never been a problem. If anything it would cause a small error I could quickly repair. In Illustrator CC, however, whenever I make a small change with the direct selection tool, it basically disrupts my entire live paint drawing. Any help would be great! Thanks so much!!!

    Hi Mylenium, Thanks for responding. I was just reading this forum in an attempt to answer my own question:
    http://forums.adobe.com/message/5762116
    Changing gap detection to "small gaps" helps slightly but the problem is still new in CC and has not been present in previous versions. Wondering if it is some kind of bug as the other forum suggests, or if there is some new setting/preference I'm missing or configuring incorrectly in CC.

  • Help! Sometimes CS6 don`t let us paint/draw on some IDs of a 3D Model (DAE imported from 3Ds Max)

    Sometimes CS6 don`t let us paint/draw on some IDs of a 3D Model (DAE imported from 3Ds Max) without any Reason. Is there a Shortcut for freezing IDs on 3D Models?
    We didn`t had that Problem CS4. Its happening without any Reason. While we are painting Textures on a Model its suddenly "freezes" the Polys with certain IDs. The IDs where putted in 3ds Max. Anyone know this Problem or may have a Solution for this? We tried a lot but couldn`t find a Solution. The only Thing we can do is reimporting the 3d Model again. Than it will work for a while till this Problem comes up again.
    HELP! thanks.

    Sometimes CS6 don`t let us paint/draw on some IDs of a 3D Model (DAE imported from 3Ds Max) without any Reason. Is there a Shortcut for freezing IDs on 3D Models?
    We didn`t had that Problem CS4. Its happening without any Reason. While we are painting Textures on a Model its suddenly "freezes" the Polys with certain IDs. The IDs where putted in 3ds Max. Anyone know this Problem or may have a Solution for this? We tried a lot but couldn`t find a Solution. The only Thing we can do is reimporting the 3d Model again. Than it will work for a while till this Problem comes up again.
    HELP! thanks.

  • Use Marquee tool to draw an ellipse over a photo

    I am trying to write a user's guide.  I take screen shots and then bring them into Photoshop elements.  In previous versions I was able to use the Marquee tool to draw an ellipse over a portion of the screen I wanted to discuss.  See below:  It was very easy to do.  Now I am using PE 8 and I cannot seem to do it.

    Thanks for your help.
    I tried it but really don't like the results.  See below:
    the ellipse is soft and washed out.  Compare it with the one I was able to do with the previous version of PE:
    which is crisp and has that little open flourish at the right side.It looks like a drawn image.  Much more professional looking.

  • Scrolling a JScrollPane in code

    hello
    java.awt.ScrollPane has a way to send the scrollpane to a certain point in code, however, it seems to be lacking in JScrollPane. how do you scroll in JScrollPane to a certain point?
    i tried having the item ask for focus, but that didnt work.
    any ideas?

    another complication: the panel is being resized as well. while its large, the user clicks on it and i want to have it shrink down to only the selected item. so i shrink it to 37 high and scroll down as previously mentioned. however, if the selection is in the last few, its still stuck on the same extent as before (i think). so it goes down as far as it could while it was large, and no more. so i can never get to those that are only visible while large.
    thinking its the extent and/or the visible area, i changed those values and it still doesnt work.
    i know its adjustable, because, once its small, the next time i make a selection (selected while small) it scrolls and shrinks (already shrunk) to the selected item. of course, this is easy becasue it must be visible to be selected and as i said, its already shrunk.
    the problem is the first time, while its large and the selection shrinks it.
    -j

Maybe you are looking for

  • Reg SDCCN and USMM - Abap runtime error

    Dear Friends, Runtime Errors : DBIF_RSQL_SQL_ERROR Exception : CX_SY_OPEN_SQL_DB When I run a T.Code SDCCN and USMM, got abap run time error "SQL error in the database when accessing a table" that errors are below. Internal Call code is ..........[RS

  • Alert issue in oracle EBS

    Hi, I have a test instance with EBS:12.0.6,Oracle DB :10.2.0.4 and RHEL:4 I am facing a alert issue in Purchasing as follows: It throws following error: APP-FND- 01874:Please link in Oracle Alert program library. I had a metalink id 211089.1 addressi

  • Refresh datacontrol which is generated from humantask

    dear all i have a datacontrol which is generated from humantask ,and the human task has a modification anf we try to refresh the datacontrol but it dose not refreshed !!!!!!!!!!!!!!!!!!!!!!!!!!! i see the following links : Refresh WSDL data control R

  • File Corrupted? Import Backup Project file?

    I have a project in Final Cut X, and both the event and the project folders are on an external HD. My mac crashed while working in Final Cut.   WHen I reopen final cut, the current Project doesn not appear in the library. (The matching event is there

  • Tabs disappear on restart on Mac; history is preserved though

    Answer seen before was to ensure that the selection to start where left off (done) and that history not deleted (done)