Question

I have small issue. In main i have such thing:

    JTabbedPane tabsPane = new JTabbedPane();
    add(tabsPane,BorderLayout.CENTER);
    JPanel tab1Panel = new JPanel();
    JPanel tab2Panel = new JPanel();

    //DrawingWindow drawingWindow= new DrawingWindow();
    //add(drawingWindow);


    tabsPane.addTab("Animacja", tab1Panel); 
    tabsPane.addTab("Wykresy", tab2Panel);
    JButton test = new JButton("Press");
    tab2Panel.add(test);

Drawing Window class

public class DrawingWindow extends JPanel {

/**
 * 
 */
private static final long serialVersionUID = 1L;
public static Balls balls=new Balls();

public DrawingWindow() {

    MakeBall();
}




private void MakeBall()
{    
        balls=new Balls(10,205,5,10);


}

public void paint(Graphics gg){
    super.paint(gg);

    Graphics2D g = (Graphics2D) gg;    
    g.setColor(Color.GRAY);
    g.fillRect(0,70,515,410);
    g.setColor(Color.WHITE);
    g.drawLine(10, 285, 57, 265);
    g.drawLine(10, 285, 57, 305);

    g.drawLine(515, 285, 458, 265);
    g.drawLine(515, 285, 458, 305);
    for(int ii=0;ii<Parameters.numberOfCovers;ii++)
    {
        if(Parameters.whatCovers[ii]==0)
        {
            g.setColor(Color.YELLOW);
            g.fillRect(132+(57*2*ii), 205, 29+2*Parameters.cmCovers[ii], 150 );
        }
        if(Parameters.whatCovers[ii]==1)
        {
            g.setColor(Color.GREEN);
            g.fillRect(132+(57*2*ii), 205, 29+2*Parameters.cmCovers[ii], 150 );
        }
    //    Ellipse2D.Double shape = new Ellipse2D.Double(balls.getX(), balls.getY(), balls.getVelocity(),balls.getRadius());
    //    g.fill(shape);
        repaint();
    } 
}
public void funkcja()
{
    repaint();
}
}

And my question is after uncommenting the // in Main my JTabbedPanel disappears. I want paint to draw in JTab.

http://forum.4programmers.net/Java/232952-jtabbedpanel_i_paint?mode=download&id=6326 <-- While it is commented

http://forum.4programmers.net/Java/232952-jtabbedpanel_i_paint?mode=download&id=6327 <-- After uncommenting.

Iam kinda newbie in Java so I would like to get easy answers :P.

Was it helpful?

Solution

Hej,

replace this

JPanel tab1Panel = new JPanel();

with that

JPanel tab1Panel = new DrawingWindow();

up to now, you add the DrawingPanel to another JPanel, but if you want to draw on your Tab, then add create a JPanel, which you'll add to your JTabbedPane with addTab().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top