Repaint() not working!

When I call repaint(), paint() never gets called, thus nothing gets drawn.
package graph;
import java.awt.*;
import javax.swing.*;
import java.util.ArrayList;
public class Line extends JComponent {
     //======================================================================
     //DATA FIELDS
     //======================================================================
     private int width, height, gap, numRate;
     private int lineThickness;
     private Color lineColor;
     private ArrayList x, y;
     private int cnt;
     private boolean draw;
     //======================================================================
     //CONSTRUCTER
     //======================================================================
     public Line(int w, int h, int gap, int numRate, int thick, Color color) {
          width = w;
          height = h;
          this.gap = gap;
          this.numRate = numRate;
          lineThickness = thick / 2;
          lineColor = color;
          x = new ArrayList();
          y = new ArrayList();
          cnt = 0;
          draw = false;
     //======================================================================
     //MODIFIERS
     //======================================================================
     public void setDraw(boolean draw) {
          this.draw = draw;
          System.out.println("Drawing " + draw);
          repaint();
     //======================================================================
     //OPERATIONS
     //======================================================================
     public void addPoint(float x, float y) {
          this.x.add(new Integer(convertX(x)));
          this.y.add(new Integer(convertY(y)));
          //System.out.println(" CNT: " + cnt + " x: " + this.x.get(cnt) + " y: " + this.x.get(cnt));
          cnt++;
     public void paint(Graphics g) {
          System.out.println("p");
          if (draw)
               drawLine(g);
     public void drawLine(Graphics g) {
          g.setColor(lineColor);
          for (int i = 0; i < width - 1; i++)
               int x1 = convertToInt((Integer) x.get(i));
               int y1 = convertToInt((Integer) y.get(i));;
               int x2 = convertToInt((Integer) x.get(i+1));
               int y2 = convertToInt((Integer) y.get(i+1));
               g.drawLine(x1,y1,x2,y2);
               g.drawLine(x1, y2 - lineThickness, x1, y2 + lineThickness);
     public int convertToInt(Integer i) {
          return i.intValue();
     public int convertX(float x) {
          if (x < 0)
               x *= -1;
               x *= gap / numRate;
               return width / 2 - (int) x;
          } else
               x *= gap / numRate;
               return width / 2 + (int) x;
     public int convertY(float y) {
          if (y < 0)
               y *= -1;
               y *= gap / numRate;
               return width / 2 + (int) y;
          } else
               y *= gap / numRate;
               return width / 2 - (int) y;
}The console output is:
Drawing true
Where it should be atleast:
Drawing true
p
Thanks in advance for your help

Maybe you should try to use g.drawString()
instead...
Regards,
GuidoAre you talking about the System.out? I'm just trying to use that to see if the method is being called at all. If it is, a "p" should appear in the console window, it doesn't! I need help figuring out why!
Thanks in advance!

Similar Messages

  • Traffic light  repaint not working via button

    I created a traffic light, a button is pressed and the colors should cycle yellow>green>yellow>red etc.. as a normal traffic light would
    when i press the start button, the repaint(); doesnt work, system.output shows me the number which corresponds to the light changes but somehow the graphics/paint is not updated.
    what am i doing wrong?
    package test2;<br />
    <br />
    import java.awt.event.ActionEvent;<br />
    import java.awt.event.ActionListener;<br />
    import javax.swing.JButton;<br />
    import javax.swing.JOptionPane;<br />
    import javax.swing.JPanel;<br />
    <br />
    public class Traffic_Lights extends JPanel implements ActionListener {<br />
    <br />
    private Light_Controller LightController;<br />
    private JButton jStart, jStop;<br />
    <br />
    public Traffic_Lights() {<br />
    jStart = new JButton("START");<br />
    jStop = new JButton("EXIT");<br />
    <br />
    // Register Listeners with buttons<br />
    jStart.addActionListener(this);<br />
    jStop.addActionListener(this);<br />
    LightController = new Light_Controller();<br />
    this.add(jStart);<br />
    this.add(jStop);<br />
    }<br />
    // Adding the traffic light<br />
    <br />
    <br />
    /**<br />
    * This method traps the button click events<br />
    */<br />
    public void actionPerformed(ActionEvent e) {<br />
    // Rotate button is clicked<br />
    if (e.getSource() == jStart) {<br />
    // Change the color displayed<br />
    LightController.changeColor();<br />
    package test2;<br />
    import java.awt.*;<br />
    import java.awt.geom.Rectangle2D;<br />
    import javax.swing.JComponent;<br />
    import javax.swing.JPanel;<br />
    <br />
    <br />
    public class Light_Controller extends JPanel {<br />
    <br />
    private int lightState = 1;<br />
    <br />
    <br />
    public void changeColor() {<br />
    lightState++;<br />
    System.out.println(lightState);<br />
    if (lightState > 5) {<br />
    lightState = 2;<br />
    <br />
    }<br />
    <br />
    this.repaint();<br />
    <br />
    }<br />
    <br />
    /**<br />
    * This method draws the traffic light on the screen<br />
    */<br />
    public void paintComponent(Graphics g) {<br />
    super.paintComponent(g);<br />
    <br />
    Graphics2D g1 = (Graphics2D) g;<br />
    // Draws the traffic light<br />
    // Draw out white frame<br />
    g.setColor(new Color(255,255,255));<br />
    g.fillRoundRect(35,15,120,225,30,30);<br />
    <br />
    // Draw inner black frame<br />
    g.setColor(new Color(0,0,0));<br />
    g.fillRoundRect(50,30,90,195,30,30);<br />
    g.drawRoundRect(35,15,120,225,30,30);<br />
    <br />
    // RED dim<br />
    g.setColor(new Color(100,0,0));<br />
    g.fillOval(70,40,50,50);<br />
    <br />
    // YELLOW dim<br />
    g.setColor(new Color(100,100,0));<br />
    g.fillOval(70,100,50,50);<br />
    <br />
    // GREEN dim<br />
    g.setColor(new Color(0,100,0));<br />
    g.fillOval(70,160,50,50);<br />
    <br />
    // Draw traffic light stand<br />
    g.setColor(new Color(50,50,50));<br />
    g.fillRect(80,240,30,30);<br />
    <br />
    switch(lightState) {<br />
    case 1:<br />
    // red glows<br />
    g.setColor(new Color(255, 0, 0));<br />
    g.fillOval(70, 40, 50, 50);<br />
    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
    break;<br />
    <br />
    case 2:<br />
    // yellow glows<br />
    g.setColor(new Color(255, 255, 0));<br />
    g.fillOval(70, 100, 50, 50);<br />
    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
    break;<br />
    <br />
    case 3:<br />
    // green glows<br />
    g.setColor(new Color(0, 255, 0));<br />
    g.fillOval(70, 160, 50, 50);<br />
    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
    break;<br />
    <br />
    case 4:<br />
    // back to yellow glows<br />
    g.setColor(new Color(255, 255, 0));<br />
    g.fillOval(70, 100, 50, 50);<br />
    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
    break;<br />
    <br />
    case 5:<br />
    // back to red glows<br />
    g.setColor(new Color(255, 0, 0));<br />
    g.fillOval(70, 40, 50, 50);<br />
    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));<br />
    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));<br />
    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));<br />
    break;<br />
    }<br />
    }<br />
    } <br />

    Code continued...
    class Light_Controller extends JPanel {
        private int lightState = 1;
        public void changeColor() {
            lightState++;
            System.out.println(lightState);
            if (lightState > 5) {
                lightState = 2;
            this.repaint();
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g1 = (Graphics2D) g;
            g.setColor(new Color(255, 255, 255));
            g.fillRoundRect(35, 15, 120, 225, 30, 30);
            g.setColor(new Color(0, 0, 0));
            g.fillRoundRect(50, 30, 90, 195, 30, 30);
            g.drawRoundRect(35, 15, 120, 225, 30, 30);
            g.setColor(new Color(100, 0, 0));
            g.fillOval(70, 40, 50, 50);
            g.setColor(new Color(100, 100, 0));
            g.fillOval(70, 100, 50, 50);
            g.setColor(new Color(0, 100, 0));
            g.fillOval(70, 160, 50, 50);
            g.setColor(new Color(50, 50, 50));
            g.fillRect(80, 240, 30, 30);
            switch (lightState) {
                case 1:
                    g.setColor(new Color(255, 0, 0));
                    g.fillOval(70, 40, 50, 50);
                    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                    break;
                case 2:
                    g.setColor(new Color(255, 255, 0));
                    g.fillOval(70, 100, 50, 50);
                    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                    break;
                case 3:
                    g.setColor(new Color(0, 255, 0));
                    g.fillOval(70, 160, 50, 50);
                    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                    break;
                case 4:
                    g.setColor(new Color(255, 255, 0));
                    g.fillOval(70, 100, 50, 50);
                    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                    break;
                case 5:
                    g.setColor(new Color(255, 0, 0));
                    g.fillOval(70, 40, 50, 50);
                    g1.fill(new Rectangle2D.Double(440, 450, 60, 5));
                    g1.fill(new Rectangle2D.Double(350, 240, 60, 5));
                    g1.fill(new Rectangle2D.Double(345, 360, 5, 80));
                    g1.fill(new Rectangle2D.Double(500, 250, 5, 90));
                    break;
    }

  • Repaint() not working on Nokia 9210 communicator

    Hi all,
    I have created an application in J2ME using MIDP1.0
    I created a class that extended Canvas and displayed a board on the screen.
    and a Timer class that repaints this screen every 1 second.
    and changes the coordinates of this board.
    I built it and run it on Wireless Toolkit 2.2 and created a package of it(.jar and .jad files).
    Now I ported these two files in the Nokia 9210i Communicator.
    When I opened this application, it showed me nothing on the screen, though everything else was working fine.
    To test it, I made another application that just changed the coordinates of a cube in this way.
    This time it showed me the static cube but not the moving cube.
    Please help me!!!!!!
    Its urgent.

    You won't be able to get it working.
    Planet 3 is only available on three branded handsets. They block all access to users of sim free handsets.
    It's a sneaky tactic that they use and there is no way around it on an E90 as three don't sell this model.
    Message Edited by psychomania on 23-Jun-2008 05:57 PM

  • AWT repaint() not Working

    The Cdoe Given Below is not responding to the action of okBtn
    It removes the center1Panel
    but does not adds or repaints the added center2Panel
    Wher am I wrong?
    Help Me
    import java.awt.BorderLayout;
    import java.awt.Button;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Frame;
    import java.awt.Panel;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    public class ExamFrame extends Frame implements ActionListener{
         Button okBtn= new Button("OK");
         Panel mainPanel = new Panel();
         Panel southPanel = new Panel();
         Panel northPanel = new Panel();
         Panel centerPanel = new Panel();
         Panel center1Panel = new Panel();
         Panel center2Panel;
         public ExamFrame() {
              super("Exam");
              setBackground(Color.gray);
              southPanel.add(okBtn);
              mainPanel.setLayout(new BorderLayout());
              mainPanel.add(southPanel,BorderLayout.SOUTH);
              mainPanel.add(northPanel,BorderLayout.NORTH);
              mainPanel.add(centerPanel,BorderLayout.CENTER);
              centerPanel.setPreferredSize(new Dimension(400,600));
              southPanel.setBackground(Color.red);
              center1Panel.setBackground(Color.blue);
              center1Panel.setPreferredSize(new Dimension(400,600));
              center2Panel = new Panel();
              center2Panel.setBackground(Color.green);
              center2Panel.setPreferredSize(new Dimension(400,600));
              centerPanel.add(center1Panel);
              centerPanel.add(center2Panel);
              okBtn.addActionListener(this);
              add(mainPanel);
              this.addWindowListener(new WindowAdapter() {
                   public void windowClosing(WindowEvent e) {
                        System.exit(0);
         public void actionPerformed(ActionEvent ae) {
              // TODO Auto-generated method stub
              if(ae.getSource()==okBtn){
                   centerPanel.removeAll();
                   repaint();
                   center2Panel= new Panel();
                   center2Panel.setBackground(Color.green);
                   center2Panel.setPreferredSize(new Dimension(400,600));
                   centerPanel.add(center2Panel);
                   centerPanel.repaint();
                   repaint();
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              ExamFrame frame= new ExamFrame();
              frame.setSize(new Dimension(600,400));
              frame.setVisible(true);
    }

    You need to usecenterPanel.validate();instead ofcenterPanel.repaint();db

  • Repaint() method is not working in MAC IE

    Hi All
    why repaint method is not working in MAC IE ? What i am doing is in one class which is inheriting Canvas class getting the keybord input then adding it to main applet.
    Please help me i am trying it for whole week and i couldn't find any solution. I didn't put my code but if anyone is willing to help me i can post it.
    Thanks in advancs
    Shan

    Hi
    Thanks for your reply. Actually i wrote simple applets and those are working well.
    So i did debug the code and i found that when i am running the following code in Apple MAC IE, nothing is happening in handleEvent method. Especially it is not going into the if statement (if (evt.id==401)). here i am checking for KEY_PRESS. I also tried with keyDown method but same problem in MAC IE.
    I am pasting the code that is giving me problem.
    import java.awt.*;
    import java.applet.*;
    public class testApplet extends Applet
    public void init()
    setLayout(new BorderLayout());
    editableArea = new EditableArea();
    editableArea.setBackground(Color.yellow);
    add("Center", editableArea);
    EditableArea editableArea;
    import java.awt.*;
    public class EditableArea extends Canvas
    String s = "";
    public boolean handleEvent(Event evt)
    if (evt.id==401)
    if(evt.key >= 32 && evt.key <= 255)
    char c = (char)evt.key;
    s = s + c;
    repaint();
    return super.handleEvent(evt);
    public void paint( Graphics g )
    g.setColor(Color.blue);
    g.drawString( s,5,15);
    --------------------------------------------------------------------

  • WHY I called "repaint(),invalidate(),paintImmediately()..." NOT WORK!!!

    Hi,I have a Panel,its structure is like this:
    JPanel [JScrollPane
                 [JPanel
                      [JLayeredPane
    mains: the whole panel contains a scrollpanel,the scrollpanel's
    view port is a background panel,the background panel contains
    a layeredpanel,I put nodes onto the layered panel.
    When something occurs,I would call "wholePanel.getContentPanel.removeAll()"
    that would call the layeredPanel's removeAll() method.
    But nothing happened when I call removeAll.I have called repaint() ,invalidate(),paintImmediately() after removeAll() .but still not work!!!
    Why ,I am very confused.......:(
    private void constructWholePanel() {
    setLayout(new BorderLayout());
    jsp = new JScrollPane();
    ImageIcon icon = new ImageIcon(Tools.getImage("background.png"));
    JPanel bgp = new BGPanel(icon.getImage());
    jsp.setViewportView(bgp);
    this.add(jsp, BorderLayout.CENTER);
    JLayeredPane contentPanel = new MapCanvas();
    contentPanel.setOpaque(false);
    contentPanel.setPreferredSize(bgp.getPreferredSize());
    contentPanel.setLayout(null);
    bgp.add(contentPanel);

    After you add/remove components to/from a container you have to call revalidate() on the container.
    Sven

  • Repaint() method 's not work but paint(getGraphics()) does, why?

    I've just read the following code ( in the Core Java 2 advance features vol 2 book):
      import java.awt.*;
      import java.awt.event.*;
       import java.awt.geom.*;
       import java.util.*;
       import javax.swing.*;
          Shows an animated bouncing ball.
      public class Bounce
         public static void main(String[] args)
            JFrame frame = new BounceFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.show();
         The frame with canvas and buttons.
      class BounceFrame extends JFrame
            Constructs the frame with the canvas for showing the
            bouncing ball and Start and Close buttons
         public BounceFrame()
            setSize(WIDTH, HEIGHT);
            setTitle("Bounce");
            Container contentPane = getContentPane();
            canvas = new BallCanvas();
            contentPane.add(canvas, BorderLayout.CENTER);
            JPanel buttonPanel = new JPanel();
            addButton(buttonPanel, "Start",
               new ActionListener()
                     public void actionPerformed(ActionEvent evt)
                        addBall();
            addButton(buttonPanel, "Close",
               new ActionListener()
                     public void actionPerformed(ActionEvent evt)
                       System.exit(0);
            contentPane.add(buttonPanel, BorderLayout.SOUTH);
            Adds a button to a container.
            @param c the container
            @param title the button title
            @param listener the action listener for the button
         public void addButton(Container c, String title,
            ActionListener listener)
            JButton button = new JButton(title);
            c.add(button);
            button.addActionListener(listener);
            Adds a bouncing ball to the canvas and makes
            it bounce 1,000 times.
         public void addBall()
            try
               Ball b = new Ball(canvas);
               canvas.add(b);
               for (int i = 1; i <= 1000; i++)
                  b.move();
                  Thread.sleep(5);
            catch (InterruptedException exception)
         private BallCanvas canvas;
         public static final int WIDTH = 450;
         public static final int HEIGHT = 350;
        The canvas that draws the balls.
    class BallCanvas extends JPanel
            Add a ball to the canvas.
            @param b the ball to add
       public void add(Ball b)
           balls.add(b);
        public void update(Graphics g) {
             super.update(g);
             System.out.println("Test");
        public void paintComponent(Graphics g)
          super.paintComponent(g);
          Graphics2D g2 = (Graphics2D)g;
          for (int i = 0; i < balls.size(); i++)
             Ball b = (Ball)balls.get(i);
             b.draw(g2);
            // System.out.println("Test");
        private ArrayList balls = new ArrayList();
        A ball that moves and bounces off the edges of a
       component
    class Ball
            Constructs a ball in the upper left corner
            @c the component in which the ball bounces
        public Ball(Component c) { canvas = c; }
           Draws the ball at its current position
           @param g2 the graphics context
        public void draw(Graphics2D g2)
           g2.fill(new Ellipse2D.Double(x, y, XSIZE, YSIZE));
          Moves the ball to the next position, reversing direction
          if it hits one of the edges
       public void move()
          x += dx;
          y += dy;
           if (x < 0)
              x = 0;
              dx = -dx;
         if (x + XSIZE >= canvas.getWidth())
             x = canvas.getWidth() - XSIZE;
              dx = -dx;
           if (y < 0)
             y = 0;
              dy = -dy;
           if (y + YSIZE >= canvas.getHeight())
              y = canvas.getHeight() - YSIZE;
              dy = -dy;
           //canvas.paint(canvas.getGraphics());//this would OK.
           canvas.repaint();//This not work, please tell me why?
        private Component canvas;
        private static final int XSIZE = 15;
       private static final int YSIZE = 15;
       private int x = 0;
       private int y = 0;
       private int dx = 2;
       private int dy = 2;
    }this program create a GUI containing a "add ball" button to creat a ball and make it bounce inside the window. ( this seems to be stupid example but it is just an example of why we should use Thread for the purpose ).
    Note: in the move() method, if i use canvas.repaint() then the ball is not redrawn after each movement. but if i use canvas.paint(canvas.getGraphics()) then everythings seem to be OK.
    Another question: Still the above programe, but If I create the ball and let it bounce in a separate thread, then canvas.repaint() in the move method work OK.
    Any one can tell me why? Thanks alot !!!

    I don't know why the one method works. Based on my Swing knowledge neither method should work. Did you notice that the JButton wasn't repainted until after the ball stopped bouncing. That is because of the following code:
    for (int i = 1; i <= 1000; i++)
        b.move();
        Thread.sleep(5);
    }This code is attempting to move the ball and then sleep for 5 milliseconds. The problem with this code is that you are telling the Event Thread to sleep. Normally painting events are added to the end of the Event Thread to allow for multiple painting requests to be combined into one for painting efficiency. When you tell the Thread to sleep then the GUI doesn't get a chance to repaint itself.
    More details about the EventThread can be found in the Swing tutorial:
    http://java.sun.com/docs/books/tutorial/uiswing/misc/threads.html
    This explains why the button isn't repainted, but it doesn't explain why the ball bounces. I don't know the answer to this for sure, but I do know that there is a method called paintImmediately(...) which causes the painting to be performed immediately without being added to the end of the Event Thread. This means the painting can be done before the Thread sleeps. Maybe the canvas.paint(....) is somehow invoking this method.
    When you click on the button this code is executed in the EvWell in Swing, all GUI painting is done on the Event Thread

  • NVIDIA Tools now not working with PS CC, is there any other add-on besides NVIDIA that will open .DDS files in photoshop?

    I had no problems with CS6 PS, but since I upgraded to PS CC, NVIDIA Tools is now not working and crashes when I try to reinstall the plug-in into PS CC. I checked NVIDIA's forums and found ZIP from them about this problem. So I am asking in here, is there another plug-in that will open .DDS files in PS? I am using Windows 7 Ultimate x64 for the OS, and I know the PS CC is 32 bit. Until I can resolve this issue, I am unable to do repaints of PMDG aircraft for my VA. Any suggestions would be greatly appreciated.

    I had a similar issue but i solved it following the instructions explained here https://wiki.archlinux.org/index.php/Bu … l.2FNVIDIA.
    I also reccomend you to install the bbswitch package which disables NVIDIA discrete graphics card when isn't used.

  • Why table getWidth and setWidth is not working when resize column the table

    hi all,
    i want to know why the setWidth is not working in the following code,
    try to uncomment the code in columnMarginChanged method and run it wont resize the table.
    i cont set width(using setWidth) of the other table column using getWidth of the main table column.
    and i want to resize the right side columns only (you can check when you resize the any column the left and right side columns also resizing)
    any suggestions could be helpful.
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JTable;
    import javax.swing.SwingUtilities;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ListSelectionEvent;
    import javax.swing.event.TableColumnModelEvent;
    import javax.swing.event.TableColumnModelListener;
    import javax.swing.table.TableColumnModel;
    public class SynTableResize extends JFrame implements TableColumnModelListener, ActionListener
        JTable  table1       = new JTable(5, 5);
        JTable  table2       = new JTable(5, 5);
        JTable  table3       = new JTable(5, 5);
        JButton btn          = new JButton("refresh");
        JPanel  pnlcontainer = new JPanel();
        public SynTableResize()
            setLayout(new BorderLayout());
            pnlcontainer.setLayout(new BoxLayout(pnlcontainer, BoxLayout.Y_AXIS));
            pnlcontainer.add(table1.getTableHeader());
            pnlcontainer.add(Box.createVerticalStrut(5));
            pnlcontainer.add(table2);
            pnlcontainer.add(Box.createVerticalStrut(5));
            pnlcontainer.add(table3);
            table2.setTableHeader(null);
            table3.setTableHeader(null);
            table1.getColumnModel().addColumnModelListener(this);
            table3.setColumnModel(table1.getColumnModel());
            table2.setColumnModel(table1.getColumnModel());
            table2.getColumnModel().addColumnModelListener(table1);
            table3.getColumnModel().addColumnModelListener(table1);
            btn.addActionListener(this);
            getContentPane().add(pnlcontainer, BorderLayout.CENTER);
            getContentPane().add(btn, BorderLayout.SOUTH);
            setSize(new Dimension(400, 400));
            setVisible(true);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        public static void main(String[] args)
            new SynTableResize();
        public void columnAdded(TableColumnModelEvent e)
        public void columnMarginChanged(ChangeEvent e)
            TableColumnModel tcm = table1.getColumnModel();
            int columns = tcm.getColumnCount();
            for (int i = 0; i < columns; i++)
                table2.getColumnModel().getColumn(i).setPreferredWidth(tcm.getColumn(i).getWidth());
                table3.getColumnModel().getColumn(i).setPreferredWidth(tcm.getColumn(i).getWidth());
                // the following commented code wont work.
    //            table2.getColumnModel().getColumn(i).setPreferredWidth(tcm.getColumn(i).getPreferredWidth());
    //            table3.getColumnModel().getColumn(i).setPreferredWidth(tcm.getColumn(i).getPreferredWidth());
    //            table2.getColumnModel().getColumn(i).setWidth(tcm.getColumn(i).getWidth());
    //            table3.getColumnModel().getColumn(i).setWidth(tcm.getColumn(i).getWidth());
            SwingUtilities.invokeLater(new Runnable()
                public void run()
                    table2.revalidate();
                    table3.revalidate();
        public void columnMoved(TableColumnModelEvent e)
        public void columnRemoved(TableColumnModelEvent e)
        public void columnSelectionChanged(ListSelectionEvent e)
        public void actionPerformed(ActionEvent e)
            JTable table = new JTable(5, 5);
            table.setColumnModel(table1.getColumnModel());
            table.getColumnModel().addColumnModelListener(table1);
            pnlcontainer.add(Box.createVerticalStrut(5));
            pnlcontainer.add(table);
            pnlcontainer.validate();
            pnlcontainer.repaint();
    }thanks
    dayananda b v

    hi,
    thanks for your replay,
    yes i know that, you can check the following code it works fine.
    actually what i want is, when i resize table column it shold not automaticaly reszie when table resized and i dont want horizontal scroll bar, meaning that all table columns should resize with in the table size(say width 300)
    if i make table autoresize off than horizontal scroll bar will appear and the other columns moved and i want scroll to view other columns.
    please suggest me some way doing it, i tried with doLayout() no help,
    doLayout() method only can be used when table resizes. first off all i want to restrict table resizing with in the limited size
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.event.ChangeEvent;
    import javax.swing.table.TableColumnModel;
    public class TempSycnTable extends JFrame
        JTable  table1       = new JTable(5, 5);
        MyTable table2       = new MyTable(5, 5);
        MyTable table3       = new MyTable(5, 5);
        JPanel  pnlcontainer = new JPanel();
        public TempSycnTable()
            JScrollPane src2 = new JScrollPane(table2);
            JScrollPane src3 = new JScrollPane(table3);
    //        table1.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    //        table2.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    //        table3.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    //        src2.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    //        src3.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            table2.setTableHeader(null);
            table3.setTableHeader(null);
            table3.setColumnModel(table1.getColumnModel());
            table2.setColumnModel(table1.getColumnModel());
            table2.getColumnModel().addColumnModelListener(table1);
            table3.getColumnModel().addColumnModelListener(table1);
            table2.setTableHeader(null);
            table3.setTableHeader(null);
            setLayout(new BorderLayout());
            pnlcontainer.setLayout(new BoxLayout(pnlcontainer, BoxLayout.Y_AXIS));
            pnlcontainer.add(table1.getTableHeader());
            pnlcontainer.add(Box.createVerticalStrut(5));
            pnlcontainer.add(src2);
            pnlcontainer.add(Box.createVerticalStrut(5));
            pnlcontainer.add(src3);
            getContentPane().add(pnlcontainer, BorderLayout.CENTER);
            setSize(new Dimension(300, 300));
            setVisible(true);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        public static void main(String[] args)
            new TempSycnTable();
        class MyTable extends JTable
            public MyTable()
                super();
            public MyTable(int numRows, int numColumns)
                super(numRows, numColumns);
            public void columnMarginChanged(ChangeEvent event)
                final TableColumnModel eventModel = table1.getColumnModel();
                final TableColumnModel thisModel = getColumnModel();
                final int columnCount = eventModel.getColumnCount();
                for (int i = 0; i < columnCount; i++)
                    thisModel.getColumn(i).setWidth(eventModel.getColumn(i).getWidth());
                repaint();
    }thanks
    daya

  • My repaint() doesnt work

    Hope somebody can help. I had posted this qtn on another site and got a response pointing to a java sun site talking about paint in general. unfortunately did not help.
    the issue is as follows:
    Heres the problem
    Have this drawing application with menus and stuff. so i draw box/lines/ circle etc. and when the mouse is released, i add the positions etc to an array, in my paint program, i parse thru the array and show the stuff. Now whatever i draw, doesnt appear immediately (although i have a repaint() (also tried validate, revalidate and every command i have learnt/come across).
    funny thing is, if i press my alt key, the "file" menu option will appear to be selected, when i press escape, the drawing window gets focus and immediately all my drawings appear. So my question, how do i make it do that.
    Additionally (while i am on the roll here) in my menu option i have a File/New when this is selected, i clear the array and do a repaint(). that works beautifully and all the drawing are gone. but if i click on a icon (designated as "new") that wont do anything until i go thru that pressing alt (or switching to another application using alt+tab and then coming back to my paint program).
    Any ideas?
    To add further this is how my code looks
    there is a frame called drawingWindow (my highest level).
    got a container Container drawBoard = getContentPane(); which is added to my frame.
    i got menubar and toolbar created and added to the drawingWindow
    Then i got this class which contains the paintcomponent routine.
    JPanel drawingArea = new DrawGraphics();
    and this is added to the container.
    drawBoard.add(drawingArea,BorderLayout.CENTER);
    as i mentioned earlier: when i draw something, the repaint doesnt show the stuff immediately. instead i have to switch to some other applications that overlaps this java program and when i switch back i will see my paint.
    why so and how can i ever get it to work.
    Thank you in advance.

    The same kind of problem I was also having some time back but what i did was sounding funny to me, but i did it.... as there is no way.Just do resize kind of operation.
    After calling repaint method , just get the current size of window, set it to next size and again set it back to original size.Screen will flicker for a fraction of second.It was working very well to me.Maybe it will help you too.......

  • Dynamic resizing in JDialog using setSize not working properly on solaris

    can anyone help..
    Dynamic resizing in JDialog using setSize is not working properly on solaris, its work fine on windows.
    i have set Jdialog size to setSize(768,364),
    when i dynamically resizing it to setSize(768,575); it doesn't get change but when i move dialog using mouse it gets refreshed.
    this problem is only happening on solaris not on windows.

    Hi,
    It's only an approach but try a call of validate() or repaint() after re-setting the size of your dialog.
    Cheers, Mathias

  • 'NAVIGATE_ABSOLUTE' method is not working in UWL

    We are working on Portal 7.0.
    Recently We have upgraded from SP 13-0 To 13-5.
    After this upgradation We are facing some problems, following is the scenario:
    1.     We have a ABAP Web DynPro Application say 'A', which has button "View Details".
    2.     On Clicking of "View_Details"  We navigate to other ABAP Web DynPro Application say 'B' .
         This was done using the 'NAVIGATE_ABSOLUTE' method of the 'IF_WD_PORTAL_INTEGRATION'.
    3.     Now The Same Application 'A' is being send as the Workitem to Approver's inbox.
    4.     Approver also was able to click on 'View_Details' button and  Application 'B' used to call using 'NAVIGATE_ABSOLUTE'.
    5.     After upgradation, Point 2 is working fine. but point 4 is not working i.e. 'NAVIGATE_ABSOLUTE' functionality is not working when the application is send as workitem.
    Please guide us for the above problem. Points assured for best solution.

    Hi
    Thanks for your reply. Actually i wrote simple applets and those are working well.
    So i did debug the code and i found that when i am running the following code in Apple MAC IE, nothing is happening in handleEvent method. Especially it is not going into the if statement (if (evt.id==401)). here i am checking for KEY_PRESS. I also tried with keyDown method but same problem in MAC IE.
    I am pasting the code that is giving me problem.
    import java.awt.*;
    import java.applet.*;
    public class testApplet extends Applet
    public void init()
    setLayout(new BorderLayout());
    editableArea = new EditableArea();
    editableArea.setBackground(Color.yellow);
    add("Center", editableArea);
    EditableArea editableArea;
    import java.awt.*;
    public class EditableArea extends Canvas
    String s = "";
    public boolean handleEvent(Event evt)
    if (evt.id==401)
    if(evt.key >= 32 && evt.key <= 255)
    char c = (char)evt.key;
    s = s + c;
    repaint();
    return super.handleEvent(evt);
    public void paint( Graphics g )
    g.setColor(Color.blue);
    g.drawString( s,5,15);
    --------------------------------------------------------------------

  • RHTML 8 WebHelp Search in Chrome not working

    We are running RoboHTML 8, with output to WebHelp. The project does include PDF files. I mention
    this because of other Discussions I've read looking for a solution.
    The output is delivered to customers in a WAR and it serves just fine from the server in IE, FireFox,
    and, even though technically not supported, in Chrome. However, in Chrome, while the TOC and Index
    are ok, Search does not work from the server. (I did notice repainting issues when selecting multiple
    entries in succession in the Index - as noted in another Discussion.)
    What I mean by "does not work" is that when I type in a word ("expression", for example) and click Search, nothing happens.
    The Search field is highlighted in a thin red line, so perhaps it is related to a security issue?
    I have used Peter Grainge's Snippet to run the help output locally in Chrome and it runs fine. However,
    Search does not work in Chrome when running the help locally.
    I tried deleting the CPD and then opening the project and regenerating, but that did not
    make any difference.
    I saw another Post that said to try RH 10, but our manager said that upgrading is
    not a first choice if another way to fix can be found.
    Can anyone help please? 

    Always difficult to answer when the question is phrased as you have put it. Rh9 and 10 are supported for Chrome and searching does work. It is always possible that something in your project or environment may cause a problem so no one will say for sure it will work. It should but the only sure way is to download the trial and check it out.
    See www.grainge.org for RoboHelp and Authoring tips
    @petergrainge

  • Hanns-G 28" HG281DJB Not Working

    I am upgrading from a external 19" DVI LCD screen to a 28" HG281DJB that has a connection for HDMI or VGA. I am familiar with setting up an external display, yet the screen gives me a message that there is no signal avail. My connections and adapters are as follows: 1st- the DVI-D to DVI, then theres a DVI to HDMI cable that plugs into the 28". Yet no worky, arrrggh. If the other adapter, the DVI-D to VGA works why would there be a difference. With the other external display I was able to use a DVI-D to DVI and then another adapter that converted DVI to HDMI FEMale then I used a male to male HDMI to another female HDMI to DVI which then connected to the display. Please help, this just doesn't make sense. I believe my graphics card is sufficient, there doesn't seem to be any info on any of the websites, like: ATI, Hanns-g. The only thing I could think of is there is a different model that Hanns-G sells and the difference is the connection, it is a DVI connection instead of HDMI, I am at a loss. Again if the other connection were to work, why?
    John

    public void nextPiece()
          nextPiece.eraseNext(nextTable);
           //controller.repaint(); //do not work and I dont know why
                   for (int i = 0; i  < 30; i++)
                       for (int j = 0; j < 80; j++)
                        nextTable[j] = Color.black;
              //I may miss some tables for setting them to black
         nextPiece.drawNext(nextTable);
    I am sorry that I have not fixed your eraseNext method.
    Do you realize that the piece in preview is vertical inverted to the data in nextTable ?
    Edited by: evilknighthk on Jun 11, 2008 8:13 PM

  • Chechbox header : deselect all not working

    folks,
    I have a jtable generated from my database. IT has 3 columns . The 3rd column has checkboxes in it. I am implementing a "CHECK ALL"
    checkbox on the header for selection and deselection of checkboxes. the below code works for selection of all boxes.. IT DOES NOT
    WORK WHEN IT IS DESELECTED ? i want to make it work for deselection also
    I call the custom table renderer from main program as follows :
    tc = table.getColumnModel().getColumn(3);
    tc.setHeaderRenderer(new CustomTableCellRenderer1(new MyItemListener(),Name));
    this is item listner in main program for checkbox "check all" present in the table header :
    class MyItemListener implements ItemListener
    public void itemStateChanged(ItemEvent e) {
    Object source = e.getSource();
    if (source instanceof AbstractButton == false) return;
    boolean checked=e.getStateChange() == ItemEvent.SELECTED;
    for(int x = 0, y = table.getRowCount(); x < y; x++)
    table.setValueAt(new Boolean(checked),x,3);
    if (e.getStateChange() == ItemEvent.DESELECTED) // dosent work
    System.out.println("deselect all"); // may b code for deselection
    this is CustomTableCellRenderer1 class below:
    package moxaclient;
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.event.*;
    class CustomTableCellRenderer1 extends JCheckBox
    implements TableCellRenderer, MouseListener {
    private static final long serialVersionUID = 1L;
    protected CustomTableCellRenderer1 rendererComponent;
    protected int column;
    String Name;
    private JTable table1;
    Object abc=null;
    protected boolean mousePressed = false;
    public CustomTableCellRenderer1(ItemListener itemListener,String name) {
    rendererComponent = this;
    rendererComponent.addItemListener(itemListener);
    this.Name=name;
    public Component getTableCellRendererComponent(
    JTable table, Object value,
    boolean isSelected, boolean hasFocus, int row, int column) {
    if (table != null) {
    JTableHeader header = table.getTableHeader();
    this.table1=table;
    if (header != null) {
    rendererComponent.setForeground(header.getForegrou nd());
    rendererComponent.setBackground(header.getBackgrou nd());
    rendererComponent.setFont(header.getFont());
    header.addMouseListener(rendererComponent);
    setColumn(column);
    rendererComponent.setText("Check All");
    setBorder(UIManager.getBorder("TableHeader.cellBor der"));
    return rendererComponent;
    protected void setColumn(int column) {
    this.column = column;
    public int getColumn() {
    return column;
    protected void handleClickEvent(MouseEvent e) {
    if (mousePressed) {
    mousePressed=false;
    JTableHeader header = (JTableHeader)(e.getSource());
    JTable tableView = header.getTable();
    TableColumnModel columnModel = tableView.getColumnModel();
    int viewColumn = columnModel.getColumnIndexAtX(e.getX());
    int column = tableView.convertColumnIndexToModel(viewColumn);
    if (viewColumn == this.column && e.getClickCount() == 1 && column != -1) {
    doClick();
    int row=table1.getRowCount();
    if(row!=0)
    for(int i=0;i<=row-1;i++)
    String Sensor =(String) table1.getValueAt(i, column-3); // // when checkbox selectedthis code gets all value present in table and stores in string abc
    Double Value =(Double) table1.getValueAt(i, column-2);
    String Date =(String) table1.getValueAt(i, column-1);
    abc += Sensor+"\t"+Value+"\t"+Name+"\t"+Date+"\t";
    public void mouseClicked(MouseEvent e) {
    handleClickEvent(e);
    ((JTableHeader)e.getSource()).repaint();
    public void mousePressed(MouseEvent e) {
    mousePressed = true;
    public void mouseReleased(MouseEvent e) {
    public void mouseEntered(MouseEvent e) {
    public void mouseExited(MouseEvent e) {
    plzz help.

    please add tags around the code in your posts.
    Dinud123 wrote:
    IT DOES NOT
    WORK WHEN IT IS DESELECTED ? i want to make it work for deselection alsoI don't know any user interface where I would toggle "select all" and "deselect all" via the same control. That may be for a reason.
    So my suggestion is: provide a second button for "deselect all".
    bye
    TPD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Maybe you are looking for

  • ITunes deleted apps from my touch

    Coincidental or not, before syncing my touch I upgraded the OS to 3.1.1. Previously my iTunes wasn't backing up my apps; my touch is a couple weeks old, and I hadn't set up iTunes to do so. Tonight I set up iTunes to back up the apps. When I synced,

  • Basics of Email Report Output as an Attachment

    I need to have a report emailed as an attachement upon completion. I have seen the many messages on the topic but they discuss topics beyond where I need them to start in the developement process. Is anyone aware of documentation on how to do this fr

  • Deski Report cannot open in Infoview

    Hi we have recently upgraded BOXI R2 SP1 to SP5 and after upgrade we found that few deski reports are not opening from Infoview. It takes much longer time and eventually it times out.We tried changing the option in the report not to refresh when open

  • Cannot add users to the Calendar Node error 0x13209

    I cannot add new users to the Calendar node. I am receiving error 0x13209. Any advice??

  • Pass dynamic Command line arguments

    Hi, I tried to pass dynamic command line argument to Web start using the method : "javaws URL -D foo -D bar" as explained in the "Unofficial JWS/JNLP FAQ" that " You can pass your own system properties to your app using -D switch ....", but I got the