Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

transparent frame?  RSS feed

 
farrukh hassan phd
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi i am having trouble in making a transparent frame
i plan to make a media player type of a thing so i want to make the frame transparent and make a circular designed player,
so if any one could help me with both transparancy and circular player please help..
regards to all
farrukh hassan phd
 
Michael Morris
Ranch Hand
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting concept. Without throwing down some code and checking (which means this idea probably won't work) you might investigate using the "glassPane" which is a transparent Component that lies on the top of any Swing component. For a JFrame just call its getGlassPane() method. Of course this means you can't call the show() or pack() methods on the JFrame which means the glassPane probably won't be visible either.
Doubt this will help much but good luck
 
shawn larkin
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi there. You'll have to use some native code for that. There have been a few post on the subject, and some have links in them to the specific C++ code you need to reference.
 
arun mahajan
Ranch Hand
Posts: 305
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is no doubt an interesting and challenging idea. As a matter of fact even I was planning to do something same but could not sapre myself till today to start this project. But some people on this forum suggested for JInternalFrame in swing. java.sun.com has some example on same. No doubt people have achieved this in c++ and other language. In my opinion this is possible in java too, pehaps a bit difficult. Go ahead on this project and if you would like share your success in coming time...

All the best...
regards,
Arun
 
farrukh hassan phd
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks all for ur advices and interest.
i ve been trying all day ;
i havnt achieved sucess but i think may be alphacomposite could help somehow , what do u all say?
thanks again and i hope ill be able to do it if u keep suggesting me.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As far as I know there is no way to do this in JAVA. In order to show a component you have to have a frame. And java Frames (JWindow, JFrame, Frame, etc) rely on native API calls to the OS to draw them. You can do it in C++ and C# I know for sure. I did a test one in C#. There is a set opaqueness method of some sort that you can set to a double value to adjust how opague the window is. But until SUN provides a method to these native API's I don't believe there is a way to do this with straight JAVA.
 
Ajay Singhal
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi friends
i have the same problem of showing a transparent frame. Actually i want to show a transparent frame on top of my application so that i can draw something on that frame(transparent). if you comes across any solution then kindly reply for the answer. or send a mail to me at Ajay_k_singhal@yahoo.com
Thanx
 
farrukh hassan phd
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the internal frame could be transparent here is the code

import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;

public class Frame1 extends JFrame {
//Construct the frame
BorderLayout borderLayout1 = new BorderLayout();
JButton jButton1 = new JButton();
JDesktopPane jPane1 = new JDesktopPane();
public Frame1() {
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.getContentPane().setLayout(borderLayout1);
this.setSize(new Dimension(600, 450));
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
jButton1_actionPerformed(e);
}
});
this.setTitle("Frame Title");
this.getContentPane().add(jButton1, BorderLayout.SOUTH);
this.getContentPane().add(jPane1, BorderLayout.CENTER);
}
//Overriden so we can exit on System Close
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
void jButton1_actionPerformed(ActionEvent e) {
JInternalFrame f=new MyInternalFrame();
f.setVisible(true);
jPane1.add(f);
}
public static void main(String args[]) {
Frame1 frame1= new Frame1();
frame1.show();
}

}
import java.awt.*;
import java.awt.event.*;
import java.awt.geom.*;
import javax.swing.*;
class MyInternalFrame extends JInternalFrame {
Shape clipShape;
public MyInternalFrame() {
super("Hubba", true, true, true, true);
setSize(200,200);
}
public void setBounds(int x, int y, int w, int h) {
// The below looks better, as you can see (and use) the close window icon
// However it's unbelievably slow.
// The version with a plain ellipse is just slow.
/*
Area clipArea=new Area(new Ellipse2D.Float(0,0,w,h));
// Couldn't find any way to get menubar height, so I'm guessing.
int barh=20;
clipArea.add(new Area(new Rectangle(0,0,barh,barh)));
clipArea.add(new Area(new Rectangle(w-barh-1,0,barh,barh)));
clipShape=clipArea;
*/
clipShape=new Ellipse2D.Float(0,0,w,h);
super.setBounds(x, y, w, h);
}
public boolean contains(int x, int y) {
if (clipShape==null) return false;
return clipShape.contains(x, y);
}
public void paint(Graphics g) {
g.setClip(clipShape);
super.paint(g);
}
}

i hope u get ur answer
farrukh_phd
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!