我有小问题。主要是我有这样的事情:
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);
绘制窗口类
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();
}
}
我的问题是在取消注释//在Main中我的JTabbedPanel消失了。 我想用JTab画画。
http://forum.4programmers.net/Java/232952-jtabbedpanel_i_paint?mode=download&id=6326&lt; - 虽然有评论
http://forum.4programmers.net/Java/232952-jtabbedpanel_i_paint?mode=download&id=6327&lt; - 取消注释后。
Iam在Java中有点新手,所以我想得到简单的答案:P。
答案 0 :(得分:1)
HeJ小鼠,
替换此
JPanel tab1Panel = new JPanel();
用
JPanel tab1Panel = new DrawingWindow();
到目前为止,您已将DrawingPanel
添加到另一个JPanel
,但如果您想在您的标签上绘图,则添加创建一个JPanel,您将添加到{{1}与JTabbedPane
。