How to draw in a JPanel and refresh it?

Hey guys,
i want to draw a map, consisting of a lot of colored rectangles, in a JPanel.
it is part of project i am working on. a robot is discovering a track and i want to draw this track step by step, the informations are sent via bluetooth.
i am not sure how to draw it step by step and how to refresh it?
i am able to draw a static graphic with the abstract class Graphics and the method paintComponent of the class JPanel.
How do I add one or more rectangles to the existing graphic?
thanks for your help!

i would like to realize the standard approach.
but i am not quite sure how.
i tried to realize it like this, but there is an error, if the i uncomment the two lines and i do not understand why!
import java.awt.image.*;
import java.awt.*;
import javax.swing.*;
public class TrackWindow extends JFrame {   
     public TrackWindow() {
          super("Mapping");
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          this.setAlwaysOnTop(true);
          this.setLocationByPlatform(true);
          this.setSize(500, 500);
          this.add(new TrackPanel());
          this.setVisible(true);
     public static void main(String[] args) {
          new TrackWindow();
     public class TrackPanel extends JPanel {
          public BufferedImage track = null;
          public TrackPanel() {
               track = (BufferedImage)this.createImage(200, 200);
               //Graphics2D g2 = track.createGraphics();
               //g2.fillRect(0, 0, 15, 15);
          public void paintComponent(Graphics g) {
}could you please help me a little.
Thank you!

Similar Messages

  • How to draw a perfect circle and how to make sure it is perfectly centered inside a square

    How to draw a perfect circle and how to make sure it is perfectly centered inside a square in Photoshop elements using the Ellipse option.

    1. Create a square canvas.
    2. With the Elipse tool, hold down Shift (Shift forces a circle). Draw the circle anywhere on the canvas (Shape 1 in this example).
    3. Simplify the circle layer
    4. Ctrl-click the layer to select the circle.
    5. Copy the selection to the clipboard (Edit > Copy).
    6. Deselect the selection.
    7. Paste from the clipboard (Edit > Paste). The pasted circle (Layer 1) will be centered.
    8. Delete the original circle layer.
    NOTE: Step 6 is the key. This guarantees that the pasted circle will be centered.
    If you want a circle completely within a square you can simply draw and simplify a circle on any shape canvas. Ctlrl-click the circle to to select it and copy to the clipboard.
    Then do File > New from Clipboard. This creates the circle cropped to a square on transparent background.

  • How can I disable back, forward and refresh button in browser running ADF 11.1.2.2

    How can I disable back, forward and refresh button in browser running ADF 11.1.2.2?

    I insert the java script into ADF page. But it does not work. The ADF source look like below. Did I insert into wrong region?
       <f:view>
            <af:document id="d1">
                <af:messages id="m1"/>
                <af:resource type="javascript">
                  window.history.forward();
                  function noBack() {
                      window.history.forward();
                </af:resource>
                <af:form id="f1">
                    <af:pageTemplate viewId="/template/temp2.jspx" id="pt1">
                        <f:facet name="body">
                            <af:panelStretchLayout id="psl1" topHeight="30px">
                                <f:facet name="bottom"/>
                                <f:facet name="center">
                                    <af:panelBox text="Incident List" id="pb1">
                                        <f:facet name="toolbar"/>
                                        <af:panelCollection id="pc1">
                                            <f:facet name="menus"/>
                                            <f:facet name="toolbar"/>
                                            <f:facet name="statusbar"/>
                                            <af:table value="#{bindings.ServiceRequestMain.collectionModel}" var="row"
                                                      rows="#{bindings.ServiceRequestMain.rangeSize}"

  • How to get a form parameter and refresh the web web page itself?

    I thought its easy as a piece of cake. But what I found out is that somehow it is getting the parameter after the web page is refreshed!
    Any advice is greatly appreciated. Thanks!
    for navigation method
       //navigation method
        public Object refresh()
            return Navigation.HOME;
        }for web page
    <h:commandLink value="Regenerate resutls"  action="#{bean.refresh}">
                       <f:param name="algorithm" value="#{HomeMBean.algorithm}"/>
                    </h:commandLink>

    What I am trying to say here is:
    for a web page, I want to refresh the web page based on a parameter chosen by users,
    In web page:
    <h:commandLink value="Regenerate resutls"  action="#{bean.refresh}">
                <f:param name="algorithm" value="#{HomeMBean.algorithm}"/>
    </h:commandLink>in managed bean:
        //navigation method
        public Object refresh()
            return Navigation.HOME;
        }also in managed bean:
    String algorithm = FacesContext.getCurrentInstance().
    getExternalContext().getRequestParameterMap().get("algorithm");
            logger.debug("parameter="+algorithm);What I observed is I will never get the parameter "algorithm" before the web page is refreshed. In other words, the method setAlgorithm() is always called after the web page is rendered.
    I in fact want to render the web page based on the parameter "algorithm".
    I spent quite a lot time on it but can't figure out why.
    My guess is for managed beans, I can't rely on one property to generate another property, is that right?
    How should I solve this problem? Thanks a million!

  • How to kill an alv-grid object and refresh the frontend

    Hello experts,
    i have created an alv-grid display!
    now i want to hide the whole alv-table on the screen when user e.g. hits a button!
    How can i kill this object and refresh the frontend?
    Thanks a lot,
    Marcel

    Hello Marcel
    For this requirement I would use the following approach:
    (1) main screen '0100': here you display your ALV grid
    (2) Define a dummy screen '0101' the user will never see
    (3) Link the container for the ALV grid (e.g. go_docking) to the dummy screen when the user pushes the HIDE button (method LINK)
    (4) Link the container back to your main screen when the user pushes the DISPLAY button
    I never ever destroy a grid control and re-build it from scratch but always use either of its methods REFRESH_TABLE_DISPLAY or SET_TABLE_FOR_FIRST_DISPLAY.
    Regards
       Uwe

  • Download and refresh button in Dashboard

    Hi,
    I have a chart report and table report in the same section of a dashboard. How to have a common Download and Refresh button at the end for both the reports. If I use the report links in both the "reports link" of teh report I get two sets and one is in the middle of the section. If I use the one in the end, it downloads only the second report. Is it possible to do both with one refresh and download, and how can it be done.
    Thanks for your time and help.

    If the table report and the chart report are completely different, then I don't know how you would do that (except for using the dashboard refresh button and the very bottom left of the dashboard page).
    But if they are of the same columns, you can create a pivot table to mimic a regular table and check the "chart pivoted results" to have a chart of that data. Then you will have only one refresh and download for both table and chart.

  • Changing monitor resolution and refresh rate

    Does anyone know how to change the monitor resolution and refresh rate on a Sun workstation?

    Hi,
    On Solaris 8 you can use the command fbconfig to do this job.
    Please check the FAQ:
    http://access1.sun.com/technotes/00921.html
    and also man page of fbconfig.
    Regards

  • How do I draw on a Jpanel

    I've spent around 15 hours trying to work out how to draw something as simple as a line onto a JPanel!
    I kind of understand about using paint, set color etc. if I was writing code in notepad I'm sure that it wouldn't be a problem but as I'm using the JDK SE form editor I'm very confused as to what should be done.
    Basically i have a frame with 2 panels in gridLayout position and filled top to bottom left to right equally spaced.
    I've added a button to the left panel. When this button is clicked I want to draw a line on the right panel. It's that simple! If I can do that then I can move on.
    All the examples i've read don't show what to do when using the JDK SE form editor. Please can someone tell me exactly what to do...thanks

    see if you can follow this
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      public Testing()
        setSize(400,300);
        setLocation(200,100);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        getContentPane().add(new DrawPanel());
        pack();
      public static void main(String[] args){new Testing().setVisible(true);}
    class DrawPanel extends JPanel
      java.util.List points = new java.util.ArrayList();
      public DrawPanel()
        setPreferredSize(new Dimension(400,300));
        setBackground(Color.WHITE);
        addMouseListener(new MouseAdapter(){
          public void mousePressed(MouseEvent me){
            points = new java.util.ArrayList();
            points.add(me.getPoint());}});
        addMouseMotionListener(new MouseMotionListener(){
          public void mouseMoved(MouseEvent me){}
          public void mouseDragged(MouseEvent me){
            points.add(me.getPoint());
            DrawPanel.this.repaint();}});
      public void paintComponent(Graphics g)
        super.paintComponent(g);
        if(points.size() > 0)
          Point sPt = (Point)points.get(0);
          for(int x = 1, y = points.size(); x < y; x++)
            Point ePt = (Point)points.get(x);
            g.drawLine(sPt.x,sPt.y,ePt.x,ePt.y);
            sPt = ePt;
    }if you want a bit of advice - dump the gui builder

  • How do I get the screen to refresh when drawing a line larger than the art board

    How do I get the screen to refresh properly when drawing a line larger than the art board when the screen scrolls? Everything turns white in CS6, CS5 and CS4.

    Existing art - not the new art.  The new art just gets a proxy shape - seen in my example as the blue rectangle.  The existing art is what gets smeared as you drag past the edge of the screen.  If it's anything other than an Ilustrator thing, it's a Mac thing. I've never known it to be any other way other than maybe in the past showing blank white instead of stuttered art on probably 10 different macs over the years.
    Take any art that you've ever created.  Zoom in so that your art is bigger than your screen (so that there's somewhere to scroll).  Rectangle tool (or move, scale, rotate(?) something, or draw a line) Start your rectangle anywhere, drag so that you are at the edge of the screen, causing it to scroll.  The existing art will get all effed up.  The rectangle you're drawing will draw as you expect it to - that's not the issue.
    How does Wade take his videos?

  • I need to know how to edit a drawing - basically remove the arrows and text but at the same time match the background of the existing pic. then re add new text. how do i erase the arrows and text and arrows but match current background of pic. step by ste

    i need to know how to edit a drawing - basically remove the arrows and text but at the same time match the background of the existing pic. then re add new text. how do i erase the arrows and text and arrows but match current background of pic. step by step explanation please beginner

    Please post (a relevant section of) it right on this Forum.

  • I lost my HOME and REFRESH buttons and don't know why. Since I can't have them anymore please tell me in detail how I get rid of Mozilla Foxfire and let me know what all I'm going to lose in the process. Thanks, Neil

    I have used Mozilla Firefox for almost a year and it was good. Now I make on stupid mistake by upgrading to the new version and I lose my Home button, Refresh button and I don't know how many other buttons.
    Since I can't have WHAT I USED TO HAVE please explain in detail how I rid of Mozilla Firefox and what I'm all going to lose in the process.

    The home icon by default has moved to the right hand side of the navigation toolbar.
    In Firefox 4 by default the Stop, Go and Reload (Refresh) buttons are combined and attached to the right hand edge of the location bar.
    When you are typing in the location bar it will show the Go button. When a site is loading it shows the Stop button. At other times it shows the Reload button.
    If you want separate buttons stop/go/reload buttons, or want to move the home button, right-click on a toolbar and choose Customize, you can then drag and drop the buttons and place them elsewhere. If you place them in the order "Reload-Stop" on the right hand edge of the location bar they will be combined again. For more details on customizing the toolbar see https://support.mozilla.com/kb/How+to+customize+the+toolbar

  • How to use url to open report and refresh report's data,but the report's toolbar haven't "refresh data" button

    Post Author: madbird
    CA Forum: WebIntelligence Reporting
    HI,
    scenario is
    I hope use url to open the report,and refresh the report data,but I didn't the user use the "refresh data" button to refresh the report's data.How to do that?
    regards

    Post Author: madbird
    CA Forum: WebIntelligence Reporting
    Thank you for your attention, amr_foci .
    I created a Web Intelligence report,there will be more than 30 companies use.The company only allowed to see the Company Data. I want to use the url of the way, from my company in the development of the system to open report, and refresh reported Table data.but do not want users to use the toolbar of "data refresh" button to refresh the data .
    Now the question of identity authentication system, as well as statements by url open the question of Has been resolved, but it can not shield statements through the pages of "data refresh" button.
    In addition, I now used by the business object XI system is posted on the JAVA environment.
    Regards,

  • How to disable back and refresh buttons in browser

    Hi,
    I need to disable the back and refresh buttons of the browser on the click of a button in a jsp as the process takes some time to be completed and i want to prevent the user from refreshing the screen.
    How can this be done?
    Thank you

    hi ,
    Can you try with the value i.e
    String s1 = oapagecontext.getParameter("value"); or button event can also be handle this way
    if ("BUTTON_EVENT".equals(event))
    - business logic
    Which screen you 're working by the way ?? if i have an access i will check it out and tell you
    --Keerthi                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How to draw and modify double lines with Adobe Illustrator?

    I need tot draw roadmaps. This should be easy using the pen tool, but my problem is that I cannot find a way to draw double lines with this tool. I have seen many fancy border styles and patterns. Some do have double or even quadruple lines, but the problem is than that they have an offset from the vector line and the space in between the two lines (the edges of the road) cannot be filled. Somewere I also found some pens called 'Double line 1.1' to 'Double line 1.6' but they also had an offset from the vector and I could not chance the size of the lines and the interval in between them independently.
    What I am looking for is a way to draw two lines in parallel and have the option tot fill the space in between with a color or even a pattern.
    The color and size of the lines should be changeable to make a distinction between several types of road.
    Is there an existing set of pencils for this purpose? It would be nice to be able to draw not only roads, but also railways and rivers!
    I am surely not the first person who needs to do this?
    I use AI version 6

    Jacob,
    Thanks for the answer. I have been searching for a solutions for a long
    time, but today I found the solution on a forum (not on this one). That
    solution is exactly as you described below, i.e. using a coloured line and a
    narrower white line on top of the first one. My problem was that I did not
    know how to create a custom brush based on the two lines. Now I know how to
    do that. However, I still have the problem. I can now draw double lines and
    I can change the color of the background line (the coloured one) but I
    cannot change the white colour of the narrower line. I assume that I have to
    completely redefine a new brush when I need to change that colour too.
    Regards,
    Rob Kole
    Van: Jacob Bugge [email protected]
    Verzonden: donderdag 28 maart 2013 17:04
    Aan: RKOLE
    Onderwerp: How to draw and modify double lines with Adobe
    Illustrator?
    Re: How to draw and modify double lines with Adobe Illustrator?
    created by Jacob Bugge <http://forums.adobe.com/people/Jacob+Bugge>  in
    Illustrator - View the full discussion
    <http://forums.adobe.com/message/5186535#5186535

  • How to draw a globe with lines of lattitude and longitude?

    I'm using CS4 on a Mac.
    Can anyone tell me how to draw a globe with a grid? I need 7 lines of latitude and 40 lines of longitude (i.e. separated by 9 degrees). I would like to have each segment of the grid defined as shape so I can fill each one with a different color.

    Maybe this way can help.....

Maybe you are looking for

  • My structure, projects, albums disappeared

    I have about 23 projects and albums that i was happily working with till i mistakenly opened what is called vault.... now all my projects and albums have disappeared from the projects tag ( Inspector) and there is nothing i can do to get them back. I

  • Defining port for a proxy at runtime.

    HELLO FRIENDS... Is there anyway we can define the port for a proxy at runtime ? THANK PranaV.

  • Can I install CS6 from Creative cloud and still have my existing CS5 software?

    Basically, here is the deal.  I have been working on a couple projects in CS5 but just bought CS6 creative cloud as I want to start using it.  The question I have is, can I still use CS5 to finish up these projects and install CS6 at the same time so

  • [ASK] Cannot access tree after change IP

    Hi all, i have a problem after i change my IP.. hope that someone have an answer about my problem.. i have installed a server with netware in my office... now the server need to be moved to another office.. before the server moved, i could access the

  • How to capture key strokes

    Experts, For copy and paste functionality in oracle forms tree object for node using CTRL C and CTRL V. On KEY-OTHERS trigger I want to differentiate that the user either press CTRL C or CTRL V. Any solution to differentiate key strokes. Thanks,