【问题标题】:Graphics2d and JpanelGraphics2d 和 Jpanel
【发布时间】:2012-06-20 13:08:06
【问题描述】:

我有 JFrame 和一些组件,而 JPanel 将是图形对象。 我正在尝试在 JPanel 上添加 Line

DrawingPanel()
{
    DrawCellsComponent drawCellsComponent = new DrawCellsComponent();
    add(drawCellsComponent);
}

这是组件的代码。

public void paintConponent(Graphics g)
{
    Graphics2D g2 = (Graphics2D) g;
    g2.setPaint(Color.RED);
    g2.draw(new Line2D.Double(0, 0, 250, 250));
}

JPanel 上没有任何线路。有什么问题?

【问题讨论】:

    标签: jpanel graphics2d


    【解决方案1】:

    问题解决了。只在 JPanel 中而不是在 JComponent 中绘制

    【讨论】:

      猜你喜欢
      • 2014-04-19
      • 2017-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-05
      相关资源
      最近更新 更多