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: Gradient Translucent Window

  1. #1
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Gradient Translucent Window

    hey there guys...
    I've been working on this code for the past 2 days and just seems like i cant get it to work.

    import java.awt.*;
    import javax.swing.*;
     
    public class test extends JFrame {
        public test() {
            super("GradientTranslucentWindow");
     
            setBackground(new Color(0,0,0,0));
            setSize(new Dimension(300,200));
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     
            JPanel panel = new JPanel() {
                @Override
                protected void paintComponent(Graphics g) {
                    if (g instanceof Graphics2D) {
                        final int R = 240;
                        final int G = 240;
                        final int B = 240;
     
                        Paint p = new GradientPaint(0.0f, 0.0f, new Color(R, G, B, 0),
                                					0.0f, getHeight(), new Color(R, G, B, 255), true);
                        Graphics2D g2d = (Graphics2D)g;
                        g2d.setPaint(p);
                        g2d.fillRect(0, 0, getWidth(), getHeight());
                    }
                }
            };
            setContentPane(panel);
            setLayout(new GridBagLayout());
            add(new JButton("I am a Button"));
        }
     
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                	test t = new test();
                    t.setVisible(true);
                }
            });
        }
    }

    please can someone help... i need some sleep.


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Gradient Translucent Window

    just seems like i cant get it to work.
    What is not working about it? Does it compile? Are there exceptions? Does it misbehave?

  3. #3
    Junior Member
    Join Date
    Mar 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Gradient Translucent Window

    Sorry, should have specify that. Think its the lack of sleep...
    But pulling a third day without sleep i finally sort it out.

    when compiled, one should see a gradient transparent effect from right to left on a JPanel placed on a JForm, without effecting other components and the JFrame as Undecorated.

     
    import java.awt.*;
    import javax.swing.*;
     
    public class Test extends JFrame{
     
    	private JPanel  Panel1;
    	private JButton Button1;
     
    	Test() {		
    		Panel1 = new JPanel() { 
    			public void paintComponent(Graphics grh) {
    				int H = this.getHeight();
    				int W = this.getWidth();
     
    				Paint p = new GradientPaint(0.0f, 0.0f, new Color(240, 240, 240, 0),
    											0, H, new Color(0, 0, 240, 255));
     
    				Graphics2D g2d = (Graphics2D) grh;
    		        g2d.setPaint(p);
    		        g2d.fillRect(0, 0, W, H);
    			}
    		};
     
    		Button1 = new JButton("Click me");
    		Button1.setBounds(30, 30, 200, 200);
     
    		Panel1.setOpaque(false);
    		Panel1.setDoubleBuffered(false);
    		Panel1.setBackground(new Color(240, 240, 240, 128));	
    		Panel1.add(Button1);
    		this.getContentPane().add(Panel1);
     
    		this.setUndecorated(true);
    		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		this.setSize(400, 400);
    		this.setLocationRelativeTo(null);
    		this.setVisible(true);
    	}
     
    	public static void main(String[] args) {
    		Test t = new Test();
    		com.sun.awt.AWTUtilities.setWindowOpaque(t, false);
    	}
     
    }

    Thanks for having a look and trying...
    at least i can go sleep now...

Similar Threads

  1. Craating non active window ,and inputing to the non active window.
    By java-beginner in forum Java Theory & Questions
    Replies: 0
    Last Post: February 25th, 2011, 10:13 PM
  2. New Window from a Servlet
    By RookieServletPrgmer in forum Java Servlet
    Replies: 6
    Last Post: December 2nd, 2010, 08:52 AM
  3. Thread for a given time window
    By zu1u in forum Threads
    Replies: 1
    Last Post: November 9th, 2010, 12:57 PM
  4. cmd.exe DOS Window
    By Curious in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: March 1st, 2010, 10:30 AM
  5. Navigating from one window to another
    By visharaddhavle83 in forum AWT / Java Swing
    Replies: 2
    Last Post: August 6th, 2009, 07:55 AM