Skip to main content

[JAVA2D] [cplyon928@COMCAST.NET: Re: [JAVA2D] Transparent internal frames]

4 replies [Last post]
Anonymous

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Anonymous
Clifford Lyon

Perfect. Thanks Scott!

----- Original Message -----
From: "Scott Violet"
To: "Clifford Lyon"
Cc: "Scott Violet" ;
; ;

Sent: Tuesday, August 17, 2004 4:52 PM
Subject: Re: [cplyon928@COMCAST.NET: Re: [JAVA2D] Transparent internal
frames]

> On Mon, Aug 16, 2004 at 10:36:07PM -0400, Clifford Lyon wrote:
> > Hi Scott - Right on. Only thing I had to do was cast the Containter to
a
> > JComponent to get to the setOpaque method, worked like a charm.
> >
> > Is there any way to get a clean repaint with using a background color
with
> > alpha < 255? That's the real objective - if you have seen a TIVo menu,
> > that's the effect I'm going for, more or less.
>
> Nothing out of the box:( Unfortunately JComponent's meaning of opaque
> is overloaded: it means whether or not the background is paintined in
> a completely opaque color and whether or not the background should be
> painted. As you are asking, these don't always go hand in hand. What
> you can do is set opaque to false and override paintComponent and fill
> in the background color, eg:
>
> public class MyPanel extends JPanel {
> protected void paintComponent(Graphics g) {
> g.setColor(getBackground());
> g.fillRect(0, 0, getWidth(), getHeight());
> super.paintComponent(g);
> }
> }
>
> We have talked about introducing a separate property that indicates
> whether or not the background is painted, but haven't yet added it.
>
> -Scott
>
> > ----- Original Message -----
> > From: "Scott Violet"
> > To:
> > Cc: "Scott Violet" ;
> >
> > Sent: Monday, August 16, 2004 11:01 AM
> > Subject: Re: [cplyon928@COMCAST.NET: Re: [JAVA2D] Transparent internal
> > frames]
> >
> >
> > > Sure thing.
> > > Hi Cliff.
> > > The problem lies with setting the background color to a transparent
> > > color. JComponent offers two very closely related properties: opaque
> > > and background. The opaque property is used an optimization in
> > > Swing's painting infrastructure to know where painting needs to
> > > originate from. If opaque is true, a JComponent must fill in it's
> > > background in an opaque color, otherwise painting artifacts will
> > > result. The reason your code isn't working is because the content
> > > pane of the internal frame inherits the background color of the
> > > internal frame, a translucent color in your case, but the content
> > > panes opaque property is true. So, to get this code to work invoke
> > > getContentPane().setOpaque(false) and no artifacts will result:)
> > > Additionally you don't need to set the background color to translucent
> > > here, if opaque is false JComponent's generally don't fill in their
> > > background.
> > >
> > > -Scott
> > >
> > > On Sat, Aug 14, 2004 at 03:43:26PM -0700, Dmitri Trembovetski wrote:
> > > >
> > > > Hi Scott,
> > > >
> > > > could you please take a look ?
> > > >
> > > > Dmitri
> > > >
> > > >
> > > > ----- Forwarded message from Clifford Lyon
-----
> > > >
> > > > From: Clifford Lyon
> > > > Date: Sat, 14 Aug 2004 17:11:13 -0400
> > > > To: JAVA2D-INTEREST@JAVA.SUN.COM
> > > > Subject: Re: [JAVA2D] Transparent internal frames
> > > > Reply-to: Clifford Lyon
> > > > X-Mailer: Microsoft Outlook Express 6.00.2800.1409
> > > >
> > > > It seems to me when clicking on the slider, the JInternalFrame is
> > repainted from the place where the contentPane starts, instead of where
the
> > menu bar starts.
> > > > ----- Original Message -----
> > > > From: Clifford Lyon
> > > > To: JAVA2D-INTEREST@JAVA.SUN.COM
> > > > Sent: Saturday, August 14, 2004 3:46 PM
> > > > Subject: Re: [JAVA2D] Transparent internal frames
> > > >
> > > >
> > > > Here is a short piece of code that demonstrates the effect.
First, if
> > I click on the slider, the Internal Frame gets repainted on its own
content
> > frame. Then, if I move the slider, I see knob artifacts. The latter is
> > easy to fix by repainting in the actionListener; the former I have not
> > figured out, but I'm probably doing something wrong with the layered
pane.
> > > >
> > > > Thanks - also feel free to steer me to another interest group.
> > > >
> > > > Cliff
> > > >
> > > > /*****************************/
> > > >
> > > > import java.awt.*;
> > > > import java.awt.image.BufferedImage;
> > > > import java.io.File;
> > > > import javax.imageio.ImageIO;
> > > > import javax.swing.*;
> > > >
> > > > public class TestJFrame
> > > > { public static void main (String args[])
> > > > { try
> > > > { JFrame frame = new JFrame();
> > > > BufferedImage image = ImageIO.read(new File(args[0]));
> > > > ImageScreen imageScreen = new ImageScreen(image);
> > > > SliderFrame sliderFrame = new SliderFrame();
> > > >
> > sliderFrame.setBounds(0,0,image.getWidth()/2,image.getHeight()/2);
> > > > sliderFrame.setVisible(true);
> > > > frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> > > > frame.getContentPane().add(imageScreen);
> > > >
> > frame.getLayeredPane().add(sliderFrame,JLayeredPane.DEFAULT_LAYER);
> > > > frame.pack();
> > > > frame.setSize(image.getWidth(),image.getHeight());
> > > > frame.show();
> > > > } catch ( Exception e )
> > > > { e.printStackTrace();
> > > > }
> > > > }
> > > > }
> > > > class ImageScreen extends JComponent
> > > > { BufferedImage image;
> > > > public ImageScreen(BufferedImage bi){
> > > > super();
> > > > image = bi;
> > > > }
> > > > public void paintComponent(Graphics g){
> > > > Rectangle r = this.getBounds();
> > > > if (image != null )
> > > > g.drawImage(image,0,0,r.width,r.height,this);
> > > > }
> > > > }
> > > > class SliderFrame extends JInternalFrame
> > > > { JSlider slider = new JSlider();
> > > > public SliderFrame()
> > > > { super();
> > > > slider.setOpaque(false);
> > > > this.setOpaque(false);
> > > > slider.setBackground(new Color(0,0,0,0));
> > > > this.setBackground(new Color(0,0,0,0));
> > > > this.getContentPane().add(slider);
> > > > }
> > > > }
> > > >
> > > > ----- Original Message -----
> > > > From: "Chet Haase"
> > > > To:
> > > > Sent: Friday, August 13, 2004 9:56 AM
> > > > Subject: Re: [JAVA2D] Transparent internal frames
> > > >
> > > >
> > > > > Hi,
> > > > >
> > > > > It's pretty difficult to know from your quick description where
the
> > > > > problem would lie.
> > > > > There is no inherent problem with using transparent internal
frames
> > in
> > > > > Swing, but
> > > > > you need to make sure to set and use the opacity property of the
> > > > > component(s)
> > > > > appropriately and to do the right thing during paintComponent().
> > Other than
> > > > > that very high-level suggestion, it's hard to know what else to
say.
> > > > > There could
> > > > > be a bug lurking here in how we implement scrolling
(devCopyArea) on
> > > > > translucent
> > > > > components, but a test case would sure help...
> > > > >
> > > > > Chet.
> > > > >
> > > > >
> > > > > Clifford Lyon wrote:
> > > > >
> > > > > > Hello list, I have a Java 2D application where I show an
image,
> > and
> > > > > > then display a transparent internal frame over the image that
> > exposes
> > > > > > controls to the user for adjusting parameters. Everything
works
> > fine,
> > > > > > except when moving the knob on my JSlider, the internal frame
> > > > > > background fills with random stuff. Any way around that?
Custom
> > > > > > painting?
> > > > > >
> > > > > > tia
> > > > > >
> >
===========================================================================
> > > > > > To unsubscribe, send email to listserv@java.sun.com and
include in
> > the
> > > > > > body of the message "signoff JAVA2D-INTEREST". For general
help,
> > send
> > > > > > email to listserv@java.sun.com and include in the body of the
> > message
> > > > > > "help".
> > > > >
> > > > >
> >
===========================================================================
> > > > > To unsubscribe, send email to listserv@java.sun.com and include
in
> > the body
> > > > > of the message "signoff JAVA2D-INTEREST". For general help,
send
> > email to
> > > > > listserv@java.sun.com and include in the body of the message
"help".
> >
===========================================================================
> > To unsubscribe, send email to listserv@java.sun.com and include in the
body
> > of the message "signoff JAVA2D-INTEREST". For general help, send email
to
> > listserv@java.sun.com and include in the body of the message "help".
> > > >
> > > >
> >
===========================================================================
> > > > To unsubscribe, send email to listserv@java.sun.com and include in
the
> > body
> > > > of the message "signoff JAVA2D-INTEREST". For general help, send
email
> > to
> > > > listserv@java.sun.com and include in the body of the message "help".
> > > >
> > > > ----- End forwarded message -----
> >

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".

Anonymous
Clifford Lyon

Hi Scott - Right on. Only thing I had to do was cast the Containter to a
JComponent to get to the setOpaque method, worked like a charm.

Is there any way to get a clean repaint with using a background color with
alpha < 255? That's the real objective - if you have seen a TIVo menu,
that's the effect I'm going for, more or less.

Thanks,

Cliff

----- Original Message -----
From: "Scott Violet"
To:
Cc: "Scott Violet" ;

Sent: Monday, August 16, 2004 11:01 AM
Subject: Re: [cplyon928@COMCAST.NET: Re: [JAVA2D] Transparent internal
frames]

> Sure thing.
> Hi Cliff.
> The problem lies with setting the background color to a transparent
> color. JComponent offers two very closely related properties: opaque
> and background. The opaque property is used an optimization in
> Swing's painting infrastructure to know where painting needs to
> originate from. If opaque is true, a JComponent must fill in it's
> background in an opaque color, otherwise painting artifacts will
> result. The reason your code isn't working is because the content
> pane of the internal frame inherits the background color of the
> internal frame, a translucent color in your case, but the content
> panes opaque property is true. So, to get this code to work invoke
> getContentPane().setOpaque(false) and no artifacts will result:)
> Additionally you don't need to set the background color to translucent
> here, if opaque is false JComponent's generally don't fill in their
> background.
>
> -Scott
>
> On Sat, Aug 14, 2004 at 03:43:26PM -0700, Dmitri Trembovetski wrote:
> >
> > Hi Scott,
> >
> > could you please take a look ?
> >
> > Dmitri
> >
> >
> > ----- Forwarded message from Clifford Lyon -----
> >
> > From: Clifford Lyon
> > Date: Sat, 14 Aug 2004 17:11:13 -0400
> > To: JAVA2D-INTEREST@JAVA.SUN.COM
> > Subject: Re: [JAVA2D] Transparent internal frames
> > Reply-to: Clifford Lyon
> > X-Mailer: Microsoft Outlook Express 6.00.2800.1409
> >
> > It seems to me when clicking on the slider, the JInternalFrame is
repainted from the place where the contentPane starts, instead of where the
menu bar starts.
> > ----- Original Message -----
> > From: Clifford Lyon
> > To: JAVA2D-INTEREST@JAVA.SUN.COM
> > Sent: Saturday, August 14, 2004 3:46 PM
> > Subject: Re: [JAVA2D] Transparent internal frames
> >
> >
> > Here is a short piece of code that demonstrates the effect. First, if
I click on the slider, the Internal Frame gets repainted on its own content
frame. Then, if I move the slider, I see knob artifacts. The latter is
easy to fix by repainting in the actionListener; the former I have not
figured out, but I'm probably doing something wrong with the layered pane.
> >
> > Thanks - also feel free to steer me to another interest group.
> >
> > Cliff
> >
> > /*****************************/
> >
> > import java.awt.*;
> > import java.awt.image.BufferedImage;
> > import java.io.File;
> > import javax.imageio.ImageIO;
> > import javax.swing.*;
> >
> > public class TestJFrame
> > { public static void main (String args[])
> > { try
> > { JFrame frame = new JFrame();
> > BufferedImage image = ImageIO.read(new File(args[0]));
> > ImageScreen imageScreen = new ImageScreen(image);
> > SliderFrame sliderFrame = new SliderFrame();
> >
sliderFrame.setBounds(0,0,image.getWidth()/2,image.getHeight()/2);
> > sliderFrame.setVisible(true);
> > frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
> > frame.getContentPane().add(imageScreen);
> >
frame.getLayeredPane().add(sliderFrame,JLayeredPane.DEFAULT_LAYER);
> > frame.pack();
> > frame.setSize(image.getWidth(),image.getHeight());
> > frame.show();
> > } catch ( Exception e )
> > { e.printStackTrace();
> > }
> > }
> > }
> > class ImageScreen extends JComponent
> > { BufferedImage image;
> > public ImageScreen(BufferedImage bi){
> > super();
> > image = bi;
> > }
> > public void paintComponent(Graphics g){
> > Rectangle r = this.getBounds();
> > if (image != null )
> > g.drawImage(image,0,0,r.width,r.height,this);
> > }
> > }
> > class SliderFrame extends JInternalFrame
> > { JSlider slider = new JSlider();
> > public SliderFrame()
> > { super();
> > slider.setOpaque(false);
> > this.setOpaque(false);
> > slider.setBackground(new Color(0,0,0,0));
> > this.setBackground(new Color(0,0,0,0));
> > this.getContentPane().add(slider);
> > }
> > }
> >
> > ----- Original Message -----
> > From: "Chet Haase"
> > To:
> > Sent: Friday, August 13, 2004 9:56 AM
> > Subject: Re: [JAVA2D] Transparent internal frames
> >
> >
> > > Hi,
> > >
> > > It's pretty difficult to know from your quick description where the
> > > problem would lie.
> > > There is no inherent problem with using transparent internal frames
in
> > > Swing, but
> > > you need to make sure to set and use the opacity property of the
> > > component(s)
> > > appropriately and to do the right thing during paintComponent().
Other than
> > > that very high-level suggestion, it's hard to know what else to say.
> > > There could
> > > be a bug lurking here in how we implement scrolling (devCopyArea) on
> > > translucent
> > > components, but a test case would sure help...
> > >
> > > Chet.
> > >
> > >
> > > Clifford Lyon wrote:
> > >
> > > > Hello list, I have a Java 2D application where I show an image,
and
> > > > then display a transparent internal frame over the image that
exposes
> > > > controls to the user for adjusting parameters. Everything works
fine,
> > > > except when moving the knob on my JSlider, the internal frame
> > > > background fills with random stuff. Any way around that? Custom
> > > > painting?
> > > >
> > > > tia
> > > >
===========================================================================
> > > > To unsubscribe, send email to listserv@java.sun.com and include in
the
> > > > body of the message "signoff JAVA2D-INTEREST". For general help,
send
> > > > email to listserv@java.sun.com and include in the body of the
message
> > > > "help".
> > >
> > >
===========================================================================
> > > To unsubscribe, send email to listserv@java.sun.com and include in
the body
> > > of the message "signoff JAVA2D-INTEREST". For general help, send
email to
> > > listserv@java.sun.com and include in the body of the message "help".
===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".
> >
> >
===========================================================================
> > To unsubscribe, send email to listserv@java.sun.com and include in the
body
> > of the message "signoff JAVA2D-INTEREST". For general help, send email
to
> > listserv@java.sun.com and include in the body of the message "help".
> >
> > ----- End forwarded message -----

===========================================================================
To unsubscribe, send email to listserv@java.sun.com and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
listserv@java.sun.com and include in the body of the message "help".