Results 1 to 13 of 13
Thread: transparent jframe?
- 01-22-2009, 04:08 PM #1
Member
- Join Date
- Jan 2009
- Posts
- 5
- Rep Power
- 0
transparent jframe?
Hello,
how to get transparent frame, i cannot find the way how to make transparent frame, maybe someone have the solution for that and can share it
few things:
netbeans6.5m + swing + frames
i'm new to java, i used to programming in c++builder (vcl) and little in M$ VS
thank you in advance,
michael
- 01-23-2009, 05:19 AM #2
Senior Member
- Join Date
- Dec 2008
- Location
- Hong Kong
- Posts
- 473
- Rep Power
- 5
how "transparent" do you want?
- 01-23-2009, 04:32 PM #3
Member
- Join Date
- Jan 2009
- Posts
- 5
- Rep Power
- 0
i'm looking for frame that I can see through, where i only have the borders of this frame and 100% transparent background - I can click and other things, like in borland c++ builder, there you have Transparency (0-255) and if you set 255 for your form, form is invisible, only visual components are visible.
of course if you will print a code with transparency on, on some level of transparency i think i will find the way to change this level for my own ;), i'm programmer for last few years so i think this won't be a problem, problem is to just ON transparency
- 01-23-2009, 05:04 PM #4
Try setUndecorated(true); getContentPane.setOpaque(false);
- 01-23-2009, 05:47 PM #5
Member
- Join Date
- Jan 2009
- Posts
- 5
- Rep Power
- 0
first one - setUndercorated(true) - if true - the borders of frame are invisible, if false nothing change
second one - getContentPane(). and there's no function like setOpaque or any like that, i've tried to set opaque to false in every element by myself and nothing happened
btw thanks for helping, i'm still looking for solution, now i'm on the level: click chaotically, maybe you will have unbelievable luck ;d
next one is: crying, begging compilator and pray(edited by me(author) coz mistake) to god, (btw in polish we have something very funny: God = Bóg, ó and u - two form of 'u', so somethimes we pray to Bóg, but for me its still praying to Bug ;d)Last edited by majkel; 01-24-2009 at 12:43 AM. Reason: mistake
- 01-23-2009, 06:04 PM #6
Member
- Join Date
- Aug 2008
- Posts
- 58
- Rep Power
- 0
Native or not-native?
In case of not-native then the following article might useful.
(I haven't tried it )
Hacking Swing: Translucent Windows | O'Reilly Media
- 01-23-2009, 06:58 PM #7
Member
- Join Date
- Jan 2009
- Posts
- 5
- Rep Power
- 0
thanks a lot for that!! i've implemented it, i think i will change it to my problem and solve it ;d, thanks very much, this is what i was looking for, maybe it's not transparent but its very very usefull ;d
one more time thanks a lot "playwin2" ;d
ps: i think the thread could be closed, the solution given by "playwin2" is solving the problem!!
- 01-23-2009, 07:07 PM #8
Sorry about the setOpaque(), that doesn't apply to Container.
The old screen shot trick, eh? The easiest one is to make a screen shot of the entire desktop, save the image, and set the image as the background. Copy all the icons to a folder. Suddenly, the "desktop" icons don't work!
By the way, "pray" to God, "prey" on victims. I liked the Bug part.
- 01-24-2009, 12:20 AM #9
Hmm... prey on bugs? Insectivorous? ;)
- 03-08-2009, 12:59 AM #10
Member
- Join Date
- Mar 2009
- Posts
- 1
- Rep Power
- 0
Hi majkel,
well, I did as you were told to do, creating a screenshot and using it as a background.
The problem is that every time you change something on your screen the JFrame has to refresh resulting in hiding the window several times in order to take the new snapshots. I can easily say that I'm not satisfied with this. it is seemed as you have found a way to solve that problem... I will be forever in your debt if you'll tell me how...
- 03-09-2009, 12:12 AM #11
Member
- Join Date
- Jan 2009
- Posts
- 5
- Rep Power
- 0
answer
hi,
so I must tell you that this solution isn't very clever, I just copied it from the link above, editing it a little and that's all
it doesn't work on another screen - it works on the screen where it's window appeared, if you'll move window to other screen it will be white (maybe someone will repair it ;d), when you move window you will see the screen like water - this is super extra fast java ;p, for me this was enough, i had to show my employer that i can do that in case that they need it
so the code =>
feel free to tell us how you improve it ;d, maybe in future someone will need something like this but little upgraded ;)Java Code:/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package starter; import java.awt.event.*; import javax.swing.*; import java.awt.*; import java.util.Date; public class TransparentBackground extends JComponent implements ComponentListener, WindowFocusListener, Runnable { private static final long serialVersionUID = 1L; private JFrame frame; private Image background; private long lastupdate = 0; public boolean refreshRequested = true; public TransparentBackground(JFrame frame) { this.frame = frame; updateBackground( ); frame.addComponentListener(this); frame.addWindowFocusListener(this); new Thread(this).start( ); } public void componentShown(ComponentEvent evt) { repaint( ); } public void componentResized(ComponentEvent evt) { repaint( ); } public void componentMoved(ComponentEvent evt) { repaint( ); } public void componentHidden(ComponentEvent evt) { } public void windowGainedFocus(WindowEvent evt) { refresh( ); } public void windowLostFocus(WindowEvent evt) { refresh( ); } public void refresh( ) { if(frame.isVisible( )) { repaint( ); refreshRequested = true; lastupdate = new Date( ).getTime( ); } } public void run( ) { try { while(true) { Thread.sleep(250); long now = new Date( ).getTime( ); if(refreshRequested && ((now - lastupdate) > 1000)) { if(frame.isVisible( )) { Point location = frame.getLocation( ); frame.hide( ); updateBackground( ); frame.show( ); frame.setLocation(location); refresh( ); } lastupdate = now; refreshRequested = false; } } } catch (Exception ex) { // p(ex.toString( )); ex.printStackTrace( ); } } public void updateBackground( ) { try { Robot rbt = new Robot( ); Toolkit tk = Toolkit.getDefaultToolkit( ); Dimension dim = tk.getScreenSize( ); background = rbt.createScreenCapture( new Rectangle(0,0,(int)dim.getWidth( ), (int)dim.getHeight( ))); } catch (Exception ex) { //p(ex.toString( )); ex.printStackTrace( ); } } @Override public void paintComponent(Graphics g) { Point pos = this.getLocationOnScreen( ); Point offset = new Point(-pos.x,-pos.y); g.drawImage(background,offset.x,offset.y,null); } public static void main(String[] args) { JFrame frame = new JFrame("Transparent Window"); TransparentBackground bg = new TransparentBackground(frame); bg.setLayout(new BorderLayout( )); //JButton button = new JButton("This is a button"); //bg.add("North",button); JLabel label = new JLabel("This is a label"); bg.add("South",label); frame.getContentPane( ).add("Center",bg); frame.pack( ); frame.setSize(150,100); frame.show( ); } }
cheers,
michael
- 10-09-2010, 02:41 PM #12
Member
- Join Date
- Oct 2010
- Posts
- 1
- Rep Power
- 0
isn't better just use:
com.sun.awt.AWTUtilities.setWindowOpacity(<any component>, 0.5f);
<any component> - i think that any :) i tried with JWindow and JFrame and both work :)
Java Code:import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JWindow; public class Main { public static void main(String[] args) { JFrame frame = new JFrame("The Frame"); frame.setSize(300, 300); frame.setLocation(100, 200); JWindow window = new JWindow(); window.setSize(300, 300); window.setLocation(500, 200); com.sun.awt.AWTUtilities.setWindowOpacity(window, 0.5f); com.sun.awt.AWTUtilities.setWindowOpacity(frame, 0.5f); JPanel pan = new JPanel(); JPanel pan2 = new JPanel(); window.add(pan, "Center"); frame.getContentPane().add(pan2); pan.setLayout(new FlowLayout()); pan.add(new JButton("Hello")); pan2.setLayout(new FlowLayout()); pan2.add(new JButton("Hello")); frame.setVisible(true); window.setVisible(true); } }
- 10-09-2010, 05:06 PM #13
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,429
- Blog Entries
- 7
- Rep Power
- 17
Similar Threads
-
Java SWT Transparent Buttons
By ynnorj in forum AWT / SwingReplies: 7Last Post: 11-25-2009, 05:48 AM -
SWT Transparent button
By ynnorj in forum SWT / JFaceReplies: 2Last Post: 03-04-2009, 06:33 AM -
Making an Image transparent?
By audinue in forum Java 2DReplies: 3Last Post: 01-03-2009, 07:32 PM -
How can I get a transparent pixel from an image
By samson in forum Java 2DReplies: 1Last Post: 07-17-2007, 04:10 AM -
Transparent JTextPane
By Ada in forum AWT / SwingReplies: 1Last Post: 05-31-2007, 09:50 PM


LinkBack URL
About LinkBacks


Bookmarks