0

I am just wondering... I saw many examples but they all dedicated for Java 7 only :( So my question is:

Is there a more or less optimal way to make transparent JWindow (or undecorated JFrame) with Java 6?

mKorbel
  • 109,525
  • 20
  • 134
  • 319
user592704
  • 3,674
  • 11
  • 70
  • 107
  • 1
    The transparent ability was introduced as of [1.6.0_10](http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html#6u10). If the users are using that version or lower, they are using an insecure JRE and should update it. – Andrew Thompson Sep 18 '13 at 20:44
  • @Diego C Nascimento I want transparent see question title ; I don't get it can it be made transparent by its paint method overriding? I couldn't find any related example... Can you advise some optimal way for JDK 1.6? – user592704 Sep 18 '13 at 20:47
  • Check out [window translucency](http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html) – toniedzwiedz Sep 18 '13 at 20:48
  • I think you should not base your code on java 6, better to use only java 7 – Gianmarco Sep 18 '13 at 20:49
  • @Tom I'd love to but the question is about having transparent JWindow with Java 6; I am interested in some at least code snippets in this area but as for now I couldn't find any my bad :S If you can share some that would be great ;) – user592704 Sep 18 '13 at 21:02
  • @user592704 I don't have any examples of my own as the days of Swing programming are long gone for me. The tutorial I linked to should provide you with a starting point. It covers the use of the `setOpacity(float)` method of the `Window` class. `JWindow` is a subclass of this very class so you should be just fine. – toniedzwiedz Sep 18 '13 at 21:08
  • yes there no issue, note in Java6 aren't unreasonably limits in compare with Java7 – mKorbel Sep 19 '13 at 06:16
  • @user592704 You seem to be ignoring both me and common sense. 1.6.0_10!! – Andrew Thompson Sep 19 '13 at 08:55
  • @Andrew Thompson I know what you saying and I do agree with you. I am going to use 1.6.0_10+ of course; The only annoying thing I can't use Java 7 that what really the question is about. All my googling gives tuts etc for java 7 :S Anyway thank you for correct jdk version recall it is a really helpful starting point I guess – user592704 Sep 19 '13 at 17:05

1 Answers1

1

Making a JWindow translucent is very simple. Window translucency has been available for as long as I can remember, even in a library as archaic as AWT.

The Swing JWindow is a subclass of the java.awt.Window class, which defines a method called setOpacity. All you need to do is pass a float value between 0 and 1.

Here's the most basic example imaginable:

JWindow window = new JWindow();
window.setSize(300,200);
window.setOpacity(0.5f); //this will make the window half-transparent

For a fully transparent window, call window.setOpacity(0.0f)

There are many more things you can do with the built in functionality. Read up on the subject here

toniedzwiedz
  • 17,895
  • 9
  • 86
  • 131
  • *"Window translucency has been available for as long as I can remember,.."* You must be young, because it was introduced in 1.6.0_10, as I stated in my first comment which pointed to the **same page** that you later linked. – Andrew Thompson Sep 19 '13 at 08:49
  • @AndrewThompson that is true, I am young – toniedzwiedz Sep 19 '13 at 08:59
  • @Andrew Thompson it is fine. I know that, too, it is available in Java 6 but the current googling gives Java 7 snippets in this area only. The point is I do remember a year or so ago I really could see some tutorials for jdk 1.6 describing how to make transparent jwindow or so; but as for now I have no "jwindow transparent" snippets for jdk 1.6 which I store locally so I really hope someone maybe has ones :) Tom digged out some related snippets which I am going to try a little bit later and I do appreciate his help :) – user592704 Sep 19 '13 at 16:29
  • @Tom thanks I'll try the code a little bit later and report my result – user592704 Sep 19 '13 at 16:34