2

I am having an issue painting a JPanel. It paints correctly, however when I resize the parent container, the JPanel gets painted at the top left corner of the window, as well as in the correct position.

The JPanel has a custom paint method, that paints a set of components that don't belong to any JPanel (including it). These are added to the JPanel immediately before their paint method is called, and is removed immediately after:

  paintOnto.setIgnoreRepaint(true);
  paintOnto.add(getPaintableComponent());
  getPaintableComponent().paint(g);
  paintOnto.remove(getPaintableComponent());
  paintOnto.setIgnoreRepaint(false);

paintOnto is a reference to the JPanel, getPaintableComponent() returns a JComponent that is to be drawn. g is the Graphics object passed through from the JPanel paint method.

The add/remove code was not required in mac at all, but under windows without it the components didnt paint at all.

This issue is only present in windows and ubuntu, not mac. Other systems are untested.

Any ideas what could be causing it? I have checked the position of the JPanel whenever it is painted, and it never is positioned at the top left corner.

Thanks

4

1 回答 1

2

尝试保存之前AffineTransformgraphics并在绘画后恢复它。

于 2012-04-04T10:06:09.867 回答