T
Twisted
Suppose I want to make a Swing component that contains objects that
need to show selection effects and control handles (e.g. resize or
rotate handles)? Or one that contains a child component, which paints
itself somehow, and needs to show an overlaying grid with one square
selected? How would this best be accomplished?
I can think of a couple alternatives:
* Override paint. Put paintComponent after paintChildren, and draw
selection related stuff in paintComponent; handles etc. appear in front
of children.
* Selection stuff gets added as children, which may present a
management headache but keeps paint from needing to be overridden.
* Something I haven't thought of yet.
In the first case, would one's paint override just be like this?:
public void paint (Graphics g) {
paintChildren(g);
paintComponent(g);
paintBorder(g);
}
or are there other things that should be done inside paint besides
these three calls? (And should they get a copy of the Graphics object,
rather than the same one passed to paint?)
The ideal thing would really be to have two layers, one for the
selection related stuff in front of one for the "real" children.
Also, should such a component subclass JComponent directly, or JPanel
or even JScrollPane or similar?
What do the experienced Swing programmers among you say?
need to show selection effects and control handles (e.g. resize or
rotate handles)? Or one that contains a child component, which paints
itself somehow, and needs to show an overlaying grid with one square
selected? How would this best be accomplished?
I can think of a couple alternatives:
* Override paint. Put paintComponent after paintChildren, and draw
selection related stuff in paintComponent; handles etc. appear in front
of children.
* Selection stuff gets added as children, which may present a
management headache but keeps paint from needing to be overridden.
* Something I haven't thought of yet.
In the first case, would one's paint override just be like this?:
public void paint (Graphics g) {
paintChildren(g);
paintComponent(g);
paintBorder(g);
}
or are there other things that should be done inside paint besides
these three calls? (And should they get a copy of the Graphics object,
rather than the same one passed to paint?)
The ideal thing would really be to have two layers, one for the
selection related stuff in front of one for the "real" children.
Also, should such a component subclass JComponent directly, or JPanel
or even JScrollPane or similar?
What do the experienced Swing programmers among you say?