Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 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?

like image 936
Mikhas Avatar asked May 30 '26 13:05

Mikhas


1 Answers

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);
}
like image 196
jzd Avatar answered Jun 01 '26 03:06

jzd



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!