Applet Painting and Repainting

I have two issues that I think to be related and hope that someone may be able to shed some light on this. I have a problem with an applet that is running within a JSP page. At initial loading, the applet randomly displays with a blank page. If I reload the jsp page from the browser the applet will recover and display appropriately. This happens on both Internet Exploder and Firefox browsers.
I also have a problem with Components within the applet that, I hope, are related. I have a JTable component that, when I make changes to it, it manages to refresh, but not completely. Some of the data that has changed doesn't refresh but the rest of it does. Again, if I refresh the applet pane the value restore to what is expected.
I have a repaint call in place at each instance, but that is not working. Are there any suggestions or maybe something else I can try to get this to work as expected. I am fairly inexperienced with applets so any advise and detail would be greatly appreciated.

You probably can't do this with threads. Rule #1 of threading is that you cannot determine the order of execution, and you basically have no control over this. If you need the images and sound to be displayed sequentially, then by all means download them or load them with separate threads. But you must display them in the same thread to get them displayed sequentially.
Alan

Similar Messages

  • PaintComponent, paint and repaint?

    Hi everybody,
    I am a little confused on the usage of these methods. I have two problems:
    I have a JPanel inside a Jframe. In order to draw a Line2D object on this panel, I have to overwrite the paintComponent() method of JPanel. This causes two problems for me:
    1) If I want to call removeAll() method upon click of a button inside the JPanel, and replace my drawing with something else, paintComponent() method gets called, and repaints my old drawing on the panel again. Meaning it would undo my removeAll() method. How can I have my class not call repaintComponent(), or how can I get rid of this problem.
    2) Whenever I move another window on top of the panel, paintComponent gets called, and for some reason, it makes multiple copies of my drawing all over the panel. It looks like whereever I am moving the new window, my drawing gets carried with it!!! This messes my whole drawing. How can I get rid of this?
    Thanks all.

    Well, I am seeing the same problem even incorporaring your suggestion. Here is my code:
    public void paintComponent(Graphics g){
    super.paintComponent(g);
    Line2D.Double line = null;
    Circle parent = null;
    Circle child = null;
    double x_child;
    double x_parent;
    double y_child;
    double y_parent;
    Graphics2D g2d = (Graphics2D)g;
    g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON);
    // save transform in use
    AffineTransform origTx = g2d.getTransform();
    ListIterator iterator = globalViewVect.listIterator();
    AffineTransform transform = new AffineTransform().getScaleInstance(50f, 50f).getTranslateInstance(10f, 10f);
    while(iterator.hasNext()){
    GlobalViewInfo gvi = (GlobalViewInfo)iterator.next();
    g2d.setPaint(Color.black);
    child = gvi.getChild();
    parent = gvi.getParent();
    x_child = child.getX() % 31 + 10;
    y_child = child.getY() % 31 + 10;
    if(parent == null) {//If this node is the root
    System.out.println("This is the root");
    else{
    x_parent = parent.getX() % 31 + 10;
    y_parent = parent.getY() % 31 + 10;
    line = new Line2D.Double(x_parent, y_parent, x_child, y_child);
    System.out.println("Line is : " + x_parent + " " + y_parent + " "
    + x_child + " " + y_child + " ");
    g2d.setTransform(transform);
    g2d.draw(line);
    g2d.setPaint(Color.red);
    g2d.setFont(new Font("Serif",Font.PLAIN,11)) ;
    Circle c = new Circle();
    c = child;
    c.setX(x_child);
    c.setY(y_child);
    c.draw(g2d, transform);
    g2d.setTransform(origTx);

  • Stuck with the paint and repaint methods

    I am supposed to create a JApplet with a button and a background color. When the button is clicked the first time a word is supposed to appear (I got that part), when the button is clicked the second time the word is supposed to appear again in a different color and in a different location on the Applet (I got that part).
    The problem is that the first name is supposed to disappear when the second word appears. So I know I have to repaint the screen when the button is clicked the second time and draw the first string in the same color as the background color to make it invisible.
    My problem is I am not sure how I can code to apply different settings each time the button is clicked. Can anyone help? Please let me know if my explanation sucks. I will try to explain better. However here is the code I have so far. I added a counter for the button just for testing purposes.
    I just need some hints on what to do and if there is a easier way than using that if statement please let me know. I probably make it harder than it is.
    Thanks in advance and Merry Christmas.
    import javax.swing.*;
       import java.awt.*;
       import java.awt.event.*;
        public class DisplayMyName extends JApplet
        implements ActionListener
          String myName = "DOG";
          String myName1 = "DOG";
          JButton moveButton = new JButton("Move It");
          Font smallFont = new Font("Arial", Font.BOLD, 12);
          Font largeFont = new Font("Lucida Sans", Font.ITALIC, 20);
          int numClicks = 0;
          JLabel label = new JLabel("Number of button clicks:" + numClicks);
           public void init()
             Container con = getContentPane();
             con.setBackground(Color.RED);
             con.setLayout( new FlowLayout() );
             con.add(moveButton);
             con.add(label);
             moveButton.addActionListener(this);
           public void paint(Graphics g)
             numClicks++;
             label.setText("Number of button clicks: " + numClicks);
             if (numClicks == 2)
             { g.setFont(smallFont);
                g.setColor(Color.BLUE);
                g.drawString(myName, 50, 100);
                   else
             if (numClicks == 3)
             { g.setFont(largeFont);
                g.setColor(Color.YELLOW);
                g.drawString(myName, 100, 200);
           public void actionPerformed(ActionEvent move)
             repaint();
       }

    You're putting your program logic in the paint method, something you should not do. For instance, try resizing your applet and see what effect that has on number of button clicks displayed. This is all a side effect of the logic being in the paint method.
    1) Don't override paint, override paintComponent.
    2) Don't draw/paint directly in the JApplet. Do this in a JPanel or JComponent, and then add this to the JApplet. In fact I'd add the button, the and the label to the JPanel and add the label to the JApplet's contentPane (which usually uses BorderLayout, so it should fill the applet).
    3) Logic needs to be outside of paint/paintComponent. the only code in the paintComponent should be the drawing/painting itself. The if statements can remain within the paintComponent method though.
    4) When calling repaint() make sure you do so on the JPanel rather than the applet itself.
    For instance where should numClicks++ go? Where should the code to change the label go? in the paint/paintComponent method? or in the button's actionlistener? which makes more sense?
    Edited by: Encephalopathic on Dec 24, 2008 9:37 AM

  • Paint and repaint

    Hi I've got a simple question how to you repaint somthing that's not a Component?
    When I get the string I want to paint it on screen but I need to repaint first, how?
    import java.awt.*;
    import java.io.*;
    public class myList
    public String[] name = new String[1000];
    int Counter = 0;
    public void getFile(String str)
      name[Counter] = str;
      Counter++;
      //Want repaint here
    public void paint(Graphics g)
      name[0] = "Hej";
      for(int i = 0;i < name.length; i++)
       if(name[i] != null)
       g.drawString(name,10,50 + 20*i);

    I do not belive this is swing related since I want to get the method of repainting the AWT version of paint.
    Once again I'll show some code (stripped down for you)
    import java.io.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.filechooser.*;
    import java.net.*;
    public class myPanel
    JPanel panel;
    JButton openButton;
    myList ml = new myList();
    public myPanel()
      panel = new JPanel()
       public void paintComponent(Graphics g)
        super.paintComponent(g);
        ml.paint(g);
      openButton.addActionListener(new ActionListener()
       public void actionPerformed(ActionEvent e)
         //the file variable I get from a JFileChooser
         //This is where a real application would open the file.
         ml.getFile(file.getName());
         panel.repaint();
         //I maybe want to repaint ml.paint() here
      panel.add(stopButton);
      panel.add(openButton);
      panel.add(saveButton);
    import java.awt.*;
    import java.io.*;
    public class myList
    public String[] name = new String[1000];
    int Counter = 0;
    public void getFile(String str)
      name[Counter] = str;
      Counter++;
      //Want a repaint here
    public void paint(Graphics g)
      for(int i = 0;i < name.length; i++)
       if(name[i] != null)
       g.drawString(name,10,50 + 20*i);
    //Or here

  • Paint(), update(), reducing flickering of applets.., not repaint()ing

    I made an applet which moves a square from one end to other end, but i used the public void paint(Graphics c)
    To reduce flickering one has to use the update() in place of paint() and call paint() at the end...well, when i do this the update() method doesnt repaint...
    Heres the code..
    import java.awt.*;
    import java.applet.*;
              public class appAniBox extends Applet implements Runnable{
                   int x = 0;
                                       public void init(){
                                            Thread t = new Thread(this);
                                                 t.start();
                                  public void run(){
                                       for(;;){
                                                 repaint();
                                                 try{
                                                 Thread.sleep(6);
                                            catch(Exception e){ }
                                       [u]public void update(Graphics g){
                                            g.setColor(Color.green);
                                                 g.fillRect(x,50,50,50);
                                                 x ++;
                                                 super.paint(g);
                                                 }[/u]                                             
              //<applet code = appAniBox height = 150 width = 700></applet>

    handy-dandy double buffering code...
    // Usage
    DoubleBuffer db = new DoubleBuffer(theComponent);
    public void paint(Graphics g) {
       Graphics dbg = this.db.getBuffer();
       // ... add painting code performed on dbg ...
       this.db.paint(g);
    // Class
    import java.awt.*;
    * <code>DoubleBuffer</code> is a utility class for creating and managing
    * a double buffer for drawing on a component.  For a given component,
    * create a DoubleBuffer object, call getBuffer to get the graphics object
    * to draw on, then call paint with the component's graphics object to
    * draw the buffer. 
    * @author sampbe
    public class DoubleBuffer
        //~ Instance fields --------------------------------------------------------
         * The component.
        private Component comp = null;
         * The buffer width.
        private int bufferWidth = -1;
         * The buffer height.
        private int bufferHeight = -1;
         * The buffer image.
        private Image bufferImage = null;
         * The buffer graphics.
        private Graphics bufferGraphics = null;
        //~ Constructors -----------------------------------------------------------
         * Creates a new <code>DoubleBuffer</code> object for the specified
         * component.
         * @param comp the component
        public DoubleBuffer(Component comp)
            if(comp == null)
                throw new NullPointerException();
            this.comp = comp;
        //~ Methods ----------------------------------------------------------------
         * Paints the buffer on the graphics object.
         * @param g the graphics object to paint on
        public void paint(Graphics g)
            paint(g, 0, 0);
         * Paints the buffer on the graphics object.
         * @param g the graphics object to paint on
         * @param x the x-coordinate
         * @param y the y-coordinate
        public void paint(Graphics g, int x, int y)
            if(bufferImage != null)
                g.drawImage(bufferImage, 0, 0, comp);
         * Gets the width.
         * @return the width
        public int getWidth()
            return bufferWidth;
         * Gets the height.
         * @return the height
        public int getHeight()
            return bufferHeight;
         * Gets the buffer's graphics object.
         * @return the buffer's graphics
        public Graphics getBuffer()
            // checks the buffersize with the current panelsize
            // or initialises the image with the first paint
            if ((bufferWidth != comp.getSize().width)
                    || (bufferHeight != comp.getSize().height)
                    || (bufferImage == null)
                    || (bufferGraphics == null))
                // always keep track of the image size
                bufferWidth = comp.getSize().width;
                bufferHeight = comp.getSize().height;
                // clean up the previous image
                if (bufferGraphics != null)
                    bufferGraphics.dispose();
                    bufferGraphics = null;
                if (bufferImage != null)
                    bufferImage.flush();
                    bufferImage = null;
                // create the new image with the size of the panel
                bufferImage = comp.createImage(bufferWidth, bufferHeight);
                bufferGraphics = bufferImage.getGraphics();
            return bufferGraphics;
    }

  • Custom paint() and rare repainting

    I have made custom paint() method like this:
    @Override
              public void paint(Graphics  g){
                   int time;               
                   if(renderer != null)
                        renderer.updateImage();
                   time = Simulation.getCurrentStepTime();          
                   if(time>=0)          labelCurrentTimeVal.setText(""+time);
                   else              labelCurrentTimeVal.setText("-");
                   time = Simulation.getAverageStepTime();          
                   if(time>=0)          labelAvgTimeVal.setText(""+time);
                   else              labelAvgTimeVal.setText("-");
                   super.paint(g);
              }     I have some calculations going on in the background (separate thread). 'renderer' is responsible for repainting the JLabel holding an ImageIcon (which gets changed by the calculations). The case is that my background calculations take a few seconds. After they're done I call the repaint() method, which updates the image and paints the whole thing.
    My problem is that I want to have up-to-date info on how much the iteration is taking so I`ve made the labelCurrentTimeVal JLabel to display it. The label only repaints when I call the repaint() method. However when I keep moving some slider in this panel repaint gets called all the time (I can see the labelCurrentTimeVal value changing constantly as I move the knob).
    So what should I do to make the repaint() method get called often enough (20-30 times /sec to get about 20-30 fps)? I tried creating a different thread that calls repaint all the time (just to test it) and it doesn't solve the case.new Runnable() {
                public void run() {
                     while(true)
                          if(MainWindow.instance != null)
                               MainWindow.instance.repaint();
              };

    I`ve made same code to represent the problem. The calculationThread does the calculations - in this case sets the iteration counter and the repaintThread is supposed to update the GUI and repaint it once in a while. GUI doesn't update at all and I don't get why?
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class Main extends JFrame{     
         private JPanel panel;
         private JLabel label;
         public static Main window;
         private Runnable calcThread,repaintThread;
         private static int it;
         public static void main(String[] args) {
              new Main();
         private void createComponents(){
              window = this;
              panel = new JPanel();
              label = new JLabel("iteration:");
              panel.setPreferredSize(new Dimension(200,200));
              panel.add(label);
              this.add(panel);
              this.pack();
              this.setVisible(true);
         public Main(){
              createComponents();
              calcThread = new Runnable(){
                   public void run(){
                        int i=0;                    
                        while(true){                         
                             Main.it = i;
                             System.out.println("check - iteration: "+i);
                             i++;
              repaintThread = new Runnable(){
                   public void run(){
                        while(true){
                             try{
                                  wait(30);
                                  label.setText("iteration: "+it);     
                                  window.repaint();
                             }catch(InterruptedException e){}
              calcThread.run();
              repaintThread.run();
    }

  • Java Applet painting outside it's borders?!

    Hello all, I have a java applet that is painting outside of it's bordors in Firefox and IE, only when scrolling does this occur. I have been searching around and found a bug which was submitted in 2006 for the same issue but cannot see any resolution or further issues. I imagine there must be a workaround as this would be quite a major issue if it was always the case. It only happens when scrolling and the applet is being repainted. Any ideas?
    Thanks
    Dori

    here we go!
    package main;
    import javax.swing.JApplet;
    public class Test extends JApplet
         private GamePanel gamePanel;
        public Test()
        public void init()
        public void start()
            //create a new GamePanel
             gamePanel = new GamePanel();
             //add the panel to the contentPane
             this.getContentPane().add(gamePanel);
        }//EOM
        public void stop()
             gamePanel.stopTimer();
        public void destroy()
            System.out.println("preparing for unloading...");
    }and
    package main;
    import java.awt.Dimension;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.util.Timer;
    import java.util.TimerTask;
    import javax.swing.JPanel;
    public class GamePanel extends JPanel{
         private static final int PWIDTH = 400;
         private static final int PHEIGHT = 400;
         private StringBuffer buffer;
         private int clickCounter = 0;
         private static final int FONTSIZE = 100;
         //timer period in ms
         private static final int PERIOD = 100;
         //game length (seconds)
         private static final int GAME_LENGTH = 5;
         //for the timer
         private long startTime;
         //image for Double buffering
         private Image dbImage = null;
         //timer
         Timer t = null;
         private boolean debug = true;
         private boolean gameRunning = false;
         public GamePanel(){
              setBackground(Color.gray);
              setSize( new Dimension(PWIDTH, PHEIGHT));
              setFocusable(true); //to receive key events
             requestFocus();
             addMouseListener( new MouseAdapter() {
                public void mousePressed(MouseEvent e)
                { doMouseAction(); }
             setUpNewGame();
         }//EOC
         public void setUpNewGame(){
             //set gameRunning to true, affects click actions
             gameRunning = true;
             //set counter to 0
             clickCounter = 0;
            MyTimerTask task = new MyTimerTask();
            t = new Timer();
            t.scheduleAtFixedRate(task,0,PERIOD);
            //for the timer
            startTime = System.currentTimeMillis();
        }//EOM
          private void doMouseAction(){
             if(gameRunning == true){
                  incrementCounter();
             else if(gameRunning == false){
                  setUpNewGame();
         }//EOM
          public void stopTimer(){
               t.cancel();
              System.out.println("Timer stopped!");
          public void timesUp(){
             //stop the timer
             stopTimer();
             //set game running to false
             gameRunning = false;
             //show gameover message
             //overwrite dbimage with score
            Graphics dbg = dbImage.getGraphics();
             //clear the image
             dbg.setColor(Color.gray);
             dbg.fillRect(0, 0, getWidth(), getHeight());
             //write the score
             dbg.setColor(Color.white);
             dbg.drawString("Your score was "+clickCounter+" clicks in "+GAME_LENGTH+" secs", 10, 40);
             //draw this to screen
             repaint();
         public void paintComponent(Graphics g)
            super.paintComponent(g);
             g.drawImage(dbImage, 0, 0, null);
        //draw to dbImage
        public void renderImage(){
             //for debug only
            long startRenderTime = System.nanoTime();
             //this will be removed, on init it should take the attributes from the html
             //and create the dbimage only once with these params
            //out(""+dbImage);
             dbImage = createImage(getWidth(), getHeight());
             out(dbImage+","+getWidth()+","+getHeight());
             Graphics dbg = dbImage.getGraphics();
             //this code should be here
             dbg.setColor(Color.gray);
             dbg.fillRect(0,0, getWidth(), getHeight());
             dbg.setColor(Color.white);
            dbg.setFont(new Font("ARIAL BOLD",Font.PLAIN,FONTSIZE));
            dbg.drawString(""+clickCounter,(getWidth()/2),(getHeight()/2));
            //draw timer
            dbg.setFont(new Font("ARIAL",Font.PLAIN,15));
            //calc time
            long currentTime = System.currentTimeMillis() - startTime;
            //for display in secs
            float floatTime = (float)((int)(currentTime/100f))/10f;
            dbg.drawString(""+floatTime, 10, getHeight()-10);
            //dbg.dispose();//test
            if(false){ //test for game over here
                 //draw game over stuff here
            if(debug){
                 //in ms
                 long totalRenderTime = (System.nanoTime() - startRenderTime)/1000000L;
                 System.out.println("Total Render Time = "+totalRenderTime+" ms, allowed "+PERIOD+"ms");
        }//EOM
        public void incrementCounter(){
             clickCounter++;
         private class MyTimerTask extends TimerTask{     
             public void run(){
                  renderImage();
                  repaint();
                  if(System.currentTimeMillis()-startTime >= GAME_LENGTH*1000){
                       //stop the game
                       timesUp();
        }//End of inner class
          * Debugging method
          * @param out
         private void out(String out){
              System.out.println(out);
    }//End of class

  • Painting and using different Layers

    Hi,
    I have to develop a Swing interface where i have to do lot of painting,
    Like there will be a background which will be showing some strips with different colors, which will be stable,
    On this background I have to draw some rectangle , off different size,
    and add the function so the user can click on the rectangle and drag it and drop it
    I have to develop a kind of scheduling , like microsoft scheduler or take a look at the following example
    http://www.ilog.com/products/jviews/demos/activitychart/index.cfm
    I need some help in finding some tutorial on how to use different panes in JApplet , like th layered panes, the glass panes etc
    Any advice on developing such an Applet
    Ashish

    Hi Shannon,
    I already have subclassed JPanel and override the paintComponent method to do all the painting , but the problem i am having is there is a lot of painting and when ever i move the mouse over it repaint method is called and so there is chance that the applet will not work if the graphics card of the user is not good,
    Can u point me to some example where a RepaintManager() is used,
    also i want to use layers so i can avoid the repainting of the background even if the user clicks on it, or drap and drops the rectangle drawn
    Ashish

  • Non-modal JDialog is not painted and blocks the GUI

    I have developed a GUI that's basically a JFrame with a JDesktopPane.
    The user can, via a menu item, pop up a JDialog that contains some JLists and then select some value from it. Once he/she has done the selection and clicks on OK, the dialog disappears (data processing is then done in the main GUI) and comes back once a specific event has happened. The user then selects other data and so on, until he/she clicks on Cancel, which definitely disposes of the JDialog.
    The graphics of the JDialog are build in the class constructor, which does a pack() but does not make the dialog visible yet. The dialog appears only when doSelection() is called.
         /** Called the first time when user selects the menu item, and then
         when a specific event has happened. */
         public Data[] doSelection() {
              dialog.setVisible(true);
              // ... Code that reacts to user's input. Basically, the ActionListener
              // added to the buttons retrieves the user's selection and calls
              // dialog.setVisible(false) if OK is clicked, or calls dialog.dispose()
              // if Cancel is clicked.
         }Now, everything works fine if the JDialog is modal, but if I make it non-modal only the window decorations of the JDialog are painted, and the control doesn't return to the main GUI. Calling doLayout() or repaint() on the doSelection() has no effect. How can this be fixed?
    I hope I have been able to explain the problem satisfactorily, I could not create a suitable SSCCEE to show you. Thanks in advance for any hint.

    Ok, I've taken some time to think about this problem and I've modified the code a bit.
    Now the dialog shows itself and is responsive (i.e. its JLists can be operated), but the Ok button does not close the dialog as I'd want. I believe that I'm messing up things about threading, and the operations in actionPerformed() should be carried out in another thread, if possible.
    Thanks in advance for any hint / suggestion / comment / insult.
         private Data[] selection;
         /** Constructor */
         public MyDialog() {
              // ... Here is the code that builds the dialog...
              dialog.setModal(false);
              dialog.pack();
              // Note that the dialog is not visible yet
         public Data[] doSelection() {
              operatorAnswer = NONE_YET;
              dialog.setVisible(true);          
              while (operatorAnswer == NONE_YET) {
                   try {
                        wait();
                   } catch (InterruptedException e) { }
              return (operatorAnswer == OK ? selection : null);
         public void actionPerformed(ActionEvent evt) {
              if (okButton.equals(evt.getSource())) {
                   operatorAnswer = OK;
                   retrieveSelection();
                   dialog.setVisible(false);
              else if (cancelButton.equals(evt.getSource())) {               
                   operatorAnswer = CANCEL;
                   dialog.dispose();
         private void retrieveSelection() {
              // ... Here is the code that retrieves selected data from the dialog's JLists
              // and stores it in the "selection" private array...
              notifyAll();
         }

  • Component resize, paint and AffineTransform

    Hello,
    I am resizing a JInternalFrame that contains a JPanel.
    When I call:
    MyJPanel.repaint();The paint function gets the dimensions of the JPanel
    using getWidth() and getHeight(), once, at the start of the
    paint function. The function then proceeds to plot some lines and
    points on a graph. Everything appears to work fine for lines and points (ie: drawOval).
    The function then goes on to draw some text for the axes of the graph. The Y axis
    text plots fine. The X axis text is rotated using AffineTransform and plots intermittently
    with the correct and incorrect position.
    Calling repaint() for the JPanel, without resizing,
    everything renders in the proper place
    via the overridden paint() procedure for that panel.
    When I resize the JInternalFrame, thus causing the
    JPanel to also automatically resize and repaint, the JPanel
    paints all lines and points in the correct locations
    with respect to the bounds of the JPanel. The
    Y axis text, drawn using drawText() plots in the correct place.
    The X axis text then plots in the wrong place after AffineTransform
    positioning in a location that would indicate it is transforming based on the
    coordinate system of the JInternalFrame rather than the JPanel (??).
    To create the text transform I am calling the following function:
    public void drawRotatedText(Graphics g, String text, int xoff, int yoff, double angle_degrees){
                        Graphics2D g2d=(Graphics2D)g;
                        AffineTransform old_at=((Graphics2D)g).getTransform();
                        AffineTransform at = new AffineTransform(old_at);
                        at.setToTranslation(xoff, yoff);
                        at.rotate((angle_degrees/360.0)*Math.PI*2.0);
                        g2d.setTransform(at);
                        g2d.drawString(text, 0, 0);
                        g2d.setTransform(old_at);
                    }The parameter Graphics g is the Graphics passed from public void MyJPanel.paint(Graphics g) .
    Why would AffineTransform get confused regarding which component the Graphics is coming from?
    More importantly, how can I avoid the problem?
    Thanks,
    P

    >
    To create the text transform I am calling the following function:
    public void drawRotatedText(Graphics g, String text, int xoff, int yoff, double angle_degrees){
    Graphics2D g2d=(Graphics2D)g;
    AffineTransform old_at=((Graphics2D)g).getTransform();
    AffineTransform at = new AffineTransform(old_at);
    at.setToTranslation(xoff, yoff);
    at.rotate((angle_degrees/360.0)*Math.PI*2.0);
    g2d.setTransform(at);
    g2d.drawString(text, 0, 0);
    g2d.setTransform(old_at);
    The problem is with the use of at.setToTranslation(xoff, yoff); instead of at.translate(xoff, yoff).
    After changing that the problem cleared up.
    P

  • What's the difference between paint and paintComponent?

    can any body tell me the difference between paint and paintComponent?and when i should use paint and when use paintComponent?
    I know that when I use repaint,it will clear all the objects and then paint again?
    is there a method similar to repaint?
    thanks in advance!

    and when i should use paint and when use paintComponent?Simple answer:
    a) override paint() when doing custom painting on an AWT component
    b) override paintComponent() when doing custom painting on a Swing component
    Detailed answer:
    Read the article on [url http://java.sun.com/products/jfc/tsc/articles/painting/index.html]Painting in AWT and Swing.
    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/14painting/index.html]Custom Painting.

  • Applet paint over-writing...

    Hello,
    Im new to applet programming, I have done quite a bit of java - console based. Anyway my problem is:
    I have an applet which has some buttons and some drawing things on it. I want inside this applet some like sub interfaces - my first thing that comes to mind is either a panel or canvas. How can this panel or canvas to re-paint by itself without overwritting the main applet paint method

    create a thread, that is the best way and gives you lots of design flexibility. But be careful about thread handling...all the best

  • Question about drawLIne(x1,y1,x2,y2) and repaint()

    i am doing this project, which i suppose to use drawLine and repaint() to generate graphs. my problem is, every time i hit a new button it will call the repaint() then my old graph is gone, only the new graph is left.
    for example
    i have 4 buttons. movesouth() movenorth() moveeast() movewest()
    when i hit movesouth two times there should be a staight line, when i hit movewest() my old graph is gone() it only left me with 1 unit to west cuz i have repaint() inside my actionPerformed function, my question is: is there a way that i can redraw these line without calling repaint () ? cuz repaint is kinda like redraw the new stuff and forget about the old ones, however i would like to keep the old one while adding the new graph to it.
    your suggestions would be great appreciated.

    well of course, your Graphics-Object is of the type Graphics2D, you just need a cast so that the compiler is happy ;-)
    Its the same Graphics2D object/instance as withought the cast...
    lg Clemens

  • I have Photoshop CS6 Extended Students and Teachers Edition.  When I go into the Filter/Oil paint and try to use Oil paint a notice comes up "This feature requires graphics processor acceleration.  Please check Performance Preferences and verify that "Use

    I have Photoshop CS6 Extended Students and Teachers Edition.  when I go into the Filter/Oil paint and try to use Oil Paint a notice comes up "This feature requires graphics processor acceleration.  Please Check Performance Preferences and verify that "Use Graphics Processor" is enabled.  When I go into Performance Preferences I get a notice "No GPU available with Photoshop Standard.  Is there any way I can add this feature to my Photoshop either by purchasing an addition or downloading something?

    Does you display adapter have a supported  GPU with at least 512MB of Vram? And do you have the latest device drivers install with Open GL support.  Use CS6 menu Help>System Info... use its copy button and paste the information in here.

  • Report painter  and drill down reports

    Hi SAP gurus,
                   Can any froward configuration of  report painter  and drill down reports.
       iassign points

    Hiii Sai Krishna,
    can u forward the same documentation to me..plsss
    my mail id - [email protected]
    thanks in advance
    regards
    ramki

Maybe you are looking for

  • How do I change the background color in pages on iOS?

    Hello, I am using Pages on my iPhone and am wondering how to set a background color. I know there are easy to do It on the Mac version, but I am not usually on my Mac editing documents (I have iCloud Drive). I have iOS 8.0.2 and the latest version of

  • How to Capitalize the first letter in a text field?

    I have a text field of first_name and one of last_name.  I want to make sure not matter what format the user inputs the the first letter is Capitalized and the rest is lower case.  Can someone tell me how this is done?  Thanks!

  • 20" iMac Fan Noise - Revisited

    So I just received my new fans from Apple, and I am still receiving the same "buzz/whirl" from the fan immediately next to the hard drive fan. On the 20" Rev B, all my other fans are acceptable; exept the fan right next to the hard drive. Model BFB08

  • Data error (invalid data type 17) in a Remote Function Call

    Hi, I am passing 2 select-option tables to RFC. Tables have structures -    Table1  SIGN(C1)                OPTION(C2)                HIGH(C6)                LOW(C6)    Table2  SIGN(C1)                OPTION(C2)                HIGH(C20)              

  • I want to create three graphs in web template

    dear all I want to create three graphs in web template the graphs's type is lines top 1 and worst 3 will display in graph first is seven days data second is seven weeks data last is six months data how to create those pls give me some advice thanks