Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: JFrame's opacity affects all painted image's opacity in a JPanel

  1. #1
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default JFrame's opacity affects all painted image's opacity in a JPanel

     import javax.swing.*;
    import java.awt.*;
     
    public class Frame {
     
        public Frame() {
     
            setUpWindow();
        }
     
        public void setUpWindow() {
     
            JFrame f = new JFrame();
            Panel p = new Panel();
     
            f.add(p);
            f.setUndecorated(true);
            f.setOpacity(.5f);
            f.setSize(400, 500);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
        }
     
        private class Panel extends JPanel {
     
            public void paint(Graphics g) {
     
                super.paint(g);
                Graphics2D g2d = (Graphics2D) g;
     
                g2d.setColor(Color.RED);
                g2d.fillRect(10, 10, 100, 100);
            }
        }
     
        public static void main(String[] args) {
     
            new Frame();
        }
    }

    i was looking for a way to create an Undecorated Frame with an Invisble Panel(got that by the Frame's opacity) but it affects all the images that i draw in the JPanel, (i just used a filled rect here to represent an image drawn in panel), i need to retain the opacity of the Images, frame and Panels should be invisible.. there are tons of codes and articles on net, that floods me again.. need help again please..
    ,it affects all the opacity of object in it..


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: JFrame's opacity affects all painted image's opacity in a JPanel

    Oooh fancy, Java 7 stuff! Have you looked at this tutorial: How to Create Translucent and Shaped Windows (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)

    It seems to have an example of what you're trying to do.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Java kindergarten chronoz13's Avatar
    Join Date
    Mar 2009
    Location
    Philippines
    Posts
    659
    Thanks
    177
    Thanked 30 Times in 28 Posts

    Default Re: JFrame's opacity affects all painted image's opacity in a JPanel

    Oooh fancy, Java 7 stuff!
    , so the current platform does really have a big impact on developers, i just downloaded the current version, and see some new stuffs, and it sounds like the transparency features been efficiently handled on 7, (i just take things for granted ), thanks but i already see that link, even the JLayer tutorial that shows how to manipulate some window effects and some listeners ,
    but the problem is when the JFrame's opacity has been manipulated, all the component that it handles is also affected by the opacity (even jpg/png images), even the buttons that is shown on that link is transparent.

    i searched and focus on containers generally on JPanels, until i found some articles that states that JPanels only control a particular color scheme which is RGB, not ARGB(does 'A' stands for alpha?), they say that JPanel's doesnt capable of manipulating its own alpha to reduce opacity, even the Robot approach that captures the background(.createScreenCapture()) that makes the JPanel look invisible, but it seems fancy to that one, my goal is to create a customized shaped frame(already done), transparent window(already done), but i need to maintain the opacity of the images or any components(buttons, etc...) inside the container(JFrame or JPanel), how can i do this? is there any resource out there that might be useful to implement this kind of approach? , i've been asking my friend google too much, but it seems like its impossible to look for some guidelines for this one..

Similar Threads

  1. [SOLVED] Painted component won't show up
    By Fermen in forum Object Oriented Programming
    Replies: 2
    Last Post: June 19th, 2011, 04:24 PM
  2. Add Image to JPanel
    By bgroenks96 in forum Java Theory & Questions
    Replies: 10
    Last Post: June 16th, 2011, 02:44 PM
  3. JPanel in JFrame
    By maele in forum AWT / Java Swing
    Replies: 2
    Last Post: March 8th, 2010, 04:12 AM
  4. How to copy image from one jpanel to another jpanel
    By ramanavarayuri1986 in forum AWT / Java Swing
    Replies: 0
    Last Post: February 15th, 2010, 02:36 AM
  5. Creating and displaying a JPanel inside another JPanel
    By JayDuck in forum AWT / Java Swing
    Replies: 1
    Last Post: April 7th, 2009, 08:02 AM