开发者

How do I create a custom floating Swing component without a JFrame?

I'd like to create a custom swing component such as a desktop widget which does not require a JFrame (or to extend it) to be 开发者_JS百科printed on the screen.

I don't want to extend the JFrame because my component is really simple and JFrame implements a lot of functionality I dont need.

Who do I start? Which class should I extend?

Many Thanks

EDIT ---------------------------------------

Thanks guys!

I'll check the references you sent. Also, is it possible to java to draw on the screen without swing API?


If you don't want the functions a JFrame provides and just want floating graphics then use a JWindow. It does not have window decorations.

Example with plain label in a JWindow:

public static void main(String args[]) {
    JWindow w = new JWindow();
    w.add(new JLabel("Testing a Window!!!!!"));
    w.setLocation(300, 300);
    w.pack();
    w.setVisible(true);
}


All in all, you'll need to familiarize yourself with Java2D, as demonstrated by @trashgod's comment. In particular, Composting Graphics. And understand that using a top-level container to render Swing components is always required.

NOTE

If @trashgod provides an answer, I'll gladly remove mine and up-vote his accordingly.


Depend on what you need. Probably an undecorated JFrame is all you need. I don't really understand your argument about "all the functionality I don't need", because, at different levels you'll get it anyway, either by another component or by the underlaying OS. You can't get rid of that.

Now addressing your question you can always use a JDialog

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜