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 4 of 4

Thread: Setting background color to translucent?!?!

  1. #1
    Junior Member
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Setting background color to translucent?!?!

    I'm trying to make all my panels translucent but cannot seem to make it work. I've made x1 blue and it worked as shown. I've looked up hints in my ide but it doesn't give me enough information.

    The last line of code below is not running correctly. I've looked up ways to do this but they are extremely extensive in code. I was hoping for a more condensed example on how to use it. Any ideas?

    JPanel x1 = new JPanel(new GridLayout(1,1));
            x1.setBackground(Color.decode("0x0000FF"));
            JPanel x2 = new JPanel(new GridLayout(1,1));
            x2.setBackground(Color.TRANSLUCENT);
    Attached Images Attached Images


  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: Setting background color to translucent?!?!

    Why not just use setOpaque(false)?

    If you want help, you'll have to pose an SSCCE that demonstrates exactly what you're doing.
    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
    Junior Member
    Join Date
    Jul 2013
    Posts
    13
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Setting background color to translucent?!?!

    I'm trying to create a GUI that looks like my terminal window you see in my attached screenshot. You can see that my terminal window is clear which brings a glassy look to the user. You can see stuff in the background in other words.

    Here is my code I have already. It contains a frame and a panel. I added a few other features which can be ignored for now. I tried doing the setOpaque(false) and I can see what it does but it's not giving me the functionality I'm looking for. Any ideas on how I could generate this glassy look.

    Attachment 2276

    import java.awt.Color;
    import java.awt.GridLayout;
    import javax.swing.*;
    import javax.swing.border.TitledBorder;
     
     
    public class RESISTOR_2 extends javax.swing.JFrame
    {
     
        public javax.swing.JPanel test;
        public javax.swing.JPanel p1;
     
        public RESISTOR_2()
        {
            initializeComponents();
        }//End "public RESISTOR_2()"
     
        private void initializeComponents()
        {
            test = new JPanel(new GridLayout(1,1));
            test.setBorder(new TitledBorder("testing"));
            test.setBackground(Color.decode("0x66CCFF"));
     
            //test.setOpaque(true);
     
            p1 = new JPanel(new GridLayout(1,1));
            p1.setBorder(new TitledBorder("p1 testing"));
            p1.setOpaque(true);
     
            add(test);
            test.add(p1);
     
        }//End "private void initializeComponents()'
     
        public static void main(String args[])
        {
            JFrame resFrame = new RESISTOR_2();
            resFrame.setSize(500, 800);
            resFrame.setLocationRelativeTo(null);
            resFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            resFrame.setVisible(true);
     
     
        }//End "public static void main"
     
    }//End "Public Class RESISTOR_2

  4. #4
    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: Setting background color to translucent?!?!

    Setting a JPanel to be transparent or even non-opaque won't make the JFrame itself transparent.

    Recommended reading: How to Create Translucent and Shaped Windows (The Java™ Tutorials > Creating a GUI With JFC/Swing > Using Other Swing Features)
    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!

Similar Threads

  1. removing image background color using java??
    By game06 in forum Java Theory & Questions
    Replies: 2
    Last Post: March 23rd, 2013, 07:19 AM
  2. Replies: 3
    Last Post: July 17th, 2012, 11:59 PM
  3. mode.addRow with background color
    By nsyncpilu in forum AWT / Java Swing
    Replies: 3
    Last Post: December 15th, 2011, 09:50 AM
  4. set Background Excel cell color using POI API
    By ngamal in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 26th, 2011, 11:20 AM
  5. Gradient Translucent Window
    By Duvan in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 4th, 2011, 01:43 PM