0

Hi,

I have a problem in repainting in a JPanel.

Situation:

I have a ButPanel which extends JPanel.

In this panel I draw some sequences with some text along with it, by overriding paint() method.

Eventually the screen size exceeds as input increases

I use a CompareFrame which extends JFrame.

I've added a JScrollPane named ResultPanel.

In some event I do setViewPort of ResultPanel to ButPanel.

So what i do here is, I keep counting the width and height size of ButPanel and i update the ButPanel by calling, setSize(width,height) inside paint() method.

But when the output becomes scrollable. The Graphics in ButPanel distorts or dithers over draws and etc, when I minimize and maximize, it automatically redraws[Of course repaint() is called when component minimize and maximize].

So In order to avoid the problem I add AdjustmentListener to both scrollbars of ResultPane in which I call ButPanel's repaint() from adjustmentValueChanged().

And still the problem never solved. I've attached a snapshot of my problem and the code.

please help me with a solution.

Thanks in advance,

Gokul Rangarajan

--Abstract Code Here--

public class CompareFrame extends javax.swing.JFrame {

/** Creates new form CompareFrame */
public CompareFrame() {
    initComponents();
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
    setPreferredSize(new Dimension(screen.width, screen.height - 60));
    setSize(screen.width, screen.height - 60);
    BP = new ButPanel2(this);
    ResultPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() {

        public void adjustmentValueChanged(AdjustmentEvent ae) {
            BP.repaint();
            BP.validate();
        }
    });
    ResultPane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener()        {

        public void adjustmentValueChanged(AdjustmentEvent ae) {
            BP.repaint();
            BP.validate();
        }
    });

//Other constructor code
     }

//Other code
}

class ButPanel2 extends javax.swing.JPanel {

public ButPanel2(CompareFrame parent) {
    setLayout(new FlowLayout());
    sizeX = 900;
    sizeY = 600;
    setPreferredSize(new Dimension(sizeX, sizeY));
    setSize(sizeX, sizeY);
    this.parent = parent;
}

@Override
public void paint(Graphics G) {
    int i = 0, x = 1, y = 12;
    G.setColor(Color.red);
    int tX;
    tX = 5;
    G.setFont(new Font("Nimbus Roman No9 L", Font.PLAIN, 14));
    //SOme more code...
    .
    .
 }

 //Some more code...
}

Kindly see the attachment. It is the snapshot of my problem

Edited by Reverend Jim: Fixed formatting

Attachments Screenshot_1.png 61.89 KB Screenshot_2.png 64.9 KB
1
Contributor
1
Reply
2
Views
7 Years
Discussion Span
Last Post by gokul.raja
0

Hi,

i found solution.

I didn't add super.paint(G); in paint() method

Now problem solved
Thanks & regards,

Gokul Rangarajan

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.