开发者

A class in Swing or AWT Library that has flexible size

开发者 https://www.devze.com 2023-03-20 10:48 出处:网络
I\'m looking for a class in javax.swing or java.awt that gives flexible size to the object. Say that 开发者_JAVA技巧we name this class MyClass. When I add MyClass to MyPanel, it will be shaped with th

I'm looking for a class in javax.swing or java.awt that gives flexible size to the object. Say that 开发者_JAVA技巧we name this class MyClass. When I add MyClass to MyPanel, it will be shaped with the objects that lie within it. To be more specific, if I draw a Rectangle, MyClass's size will be that of rectangle's, if I draw a circle, MyClass's size will be that of circle's, etc.

So far I've seen some classes but all are rectangular in shape: Container, Canvas, JLayeredPane, etc.

Any suggestions?


Given a suitable layout, any class that implements the Shape interface is a good candidate. You can use the createTransformedShape() method of AffineTransform to transform it, as seen in this example.


You can simply use another JPanel, but the key is in what layout managers that the containers (perhaps another JPanel) use and how the components are placed into the containers -- with what constraints, if any. For more on this, please read the tutorials on how to use the various more user-friendly layout managers: Laying Out Components Within a Container.

Now as to your second issue, that of drawing shapes, you'll have to give more information to solve it. Are the curves allowed limitless? Or are just rectangles and ovals allowed?


by follows this tutorial I can image that by creating un-decorated fully translucent JFrame / JDialog, my favorite would be just JWindow which is un-decorated by default(heavens this Container lost from Swing tutorial!, or am I blind???)

to this fully translucent you have to add parent JPanel or better would be JLabel. There you should adds any of possible sharpes

I think that you can pretty to forgot for usage of AWT Components, all possible start with "J" == Swing JComponents

0

精彩评论

暂无评论...
验证码 换一张
取 消