Results 1 to 11 of 11
  1. #1
    oomrichie is offline Member
    Join Date
    Feb 2011
    Posts
    31
    Rep Power
    0

    Default Customized JFrame

    Hey ppl i'm trying to accomplish this


    I was able to do this with the following code


    Java Code:
    import com.sun.awt.AWTUtilities;
    import java.awt.AlphaComposite;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GraphicsConfiguration;
    import java.awt.Rectangle;
    import java.awt.RenderingHints;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseMotionAdapter;
    import java.awt.geom.RoundRectangle2D;
    import java.awt.image.BufferedImage;
    import javax.swing.BorderFactory;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.border.EtchedBorder;
    
    public class OomrichieFrame extends JFrame {
    
        //Declarations
        private int x, y, width = 800, height = 600;
        private JPanel panelCenter = new JPanel();
        private Icon iconApplication1 =  new ImageIcon(this.getClass().getResource("Application1.png"));
        private Icon iconApplication2 =  new ImageIcon(this.getClass().getResource("Application2.png"));
        private Icon iconApplication3 =  new ImageIcon(this.getClass().getResource("Application3.png"));
        private Icon iconExit1 =  new ImageIcon(this.getClass().getResource("Exit1.png"));
        private Icon iconExit2 =  new ImageIcon(this.getClass().getResource("Exit2.png"));
        private Icon iconExit3 =  new ImageIcon(this.getClass().getResource("Exit3.png"));
        private Icon iconMax1 =  new ImageIcon(this.getClass().getResource("Max1.png"));
        private Icon iconMax2 =  new ImageIcon(this.getClass().getResource("Max2.png"));
        private Icon iconMax3 =  new ImageIcon(this.getClass().getResource("Max3.png"));
        private Icon iconMin1 =  new ImageIcon(this.getClass().getResource("Min1.png"));
        private Icon iconMin2 =  new ImageIcon(this.getClass().getResource("Min2.png"));
        private Icon iconMin3 =  new ImageIcon(this.getClass().getResource("Min3.png"));
        private JButton buttonApplication = new JButton();
        private JButton buttonExit = new JButton();
        private JButton buttonMax = new JButton();
        private JButton buttonMin = new JButton();
    
        private void jbInit() throws Exception {
            //Object Properties
            this.setUndecorated(true);
            this.setBounds(100, 100, 800, 600);
            this.setDefaultCloseOperation(EXIT_ON_CLOSE);
            this.setLayout(null);
            this.getContentPane().add(panelCenter, null);     
            this.getContentPane().setLayout(null);
            //panelCenter.setBounds(14, 64, width - 28, height - 79);
            panelCenter.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
            panelCenter.setBounds(new Rectangle(0, 50, 800, 525));
            panelCenter.setBounds(14, 34, width - 28,height - 49);        
            
            buttonApplication.setBounds(16, 5, 99, 20);
            buttonMin.setBounds(width - 115, 5, 26, 20);
            buttonMax.setBounds(width - 89, 5, 26, 20);
            buttonExit.setBounds(width - 64, 5, 50, 20);
            this.getContentPane().add(buttonApplication,null);  
            this.getContentPane().add(buttonExit,null); 
            this.getContentPane().add(buttonMax,null); 
            this.getContentPane().add(buttonMin,null);     
            buttonApplication.setFocusPainted(false);
            buttonApplication.setBorderPainted(false);
            buttonApplication.setOpaque(false);
            buttonApplication.setIcon(iconApplication1);
            buttonApplication.setDefaultCapable(false);
            buttonApplication.setContentAreaFilled(false);
            buttonApplication.setDoubleBuffered(true);
            buttonApplication.setPressedIcon(iconApplication3);
            buttonApplication.setRolloverIcon(iconApplication2); 
            buttonExit.setFocusPainted(false);
            buttonExit.setBorderPainted(false);
            buttonExit.setOpaque(false);
            buttonExit.setIcon(iconExit1);
            buttonExit.setDefaultCapable(false);
            buttonExit.setContentAreaFilled(false);
            buttonExit.setDoubleBuffered(true);
            buttonExit.setPressedIcon(iconExit3);
            buttonExit.setRolloverIcon(iconExit2);
            buttonMax.setFocusPainted(false);
            buttonMax.setBorderPainted(false);
            buttonMax.setOpaque(false);
            buttonMax.setIcon(iconMax1);
            buttonMax.setDefaultCapable(false);
            buttonMax.setContentAreaFilled(false);
            buttonMax.setDoubleBuffered(true);
            buttonMax.setPressedIcon(iconMax3);
            buttonMax.setRolloverIcon(iconMax2);        
            buttonMin.setFocusPainted(false);
            buttonMin.setBorderPainted(false);
            buttonMin.setOpaque(false);
            buttonMin.setIcon(iconMin1);
            buttonMin.setDefaultCapable(false);
            buttonMin.setContentAreaFilled(false);
            buttonMin.setDoubleBuffered(true);
            buttonMin.setPressedIcon(iconMin3);
            buttonMin.setRolloverIcon(iconMin2);
            
            AWTUtilities.setWindowOpaque(this, false);
            AWTUtilities.setWindowShape(this,new RoundRectangle2D.Double(0, 0, width, height, 15, 15));
            this.setVisible(true);
    
            //Events  
            buttonMax.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {  
                        setBounds(-5, -5, width, height);
                    }
                });
            buttonMin.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        setState(JFrame.ICONIFIED);
                    }
                });
            
            buttonExit.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        System.exit(EXIT_ON_CLOSE);
                    }
                });     
            this.addMouseListener(new MouseAdapter() {
                    public void mousePressed(MouseEvent e) {
                        //Set begging x,y cordinates
                        x = e.getX();
                        y = e.getY();
                    }
                });
            this.addMouseMotionListener(new MouseMotionAdapter() {
                    public void mouseDragged(MouseEvent e) {
                        int xf = x - e.getX();
                        int yf = y - e.getY();
                        setBounds(getX() - xf, getY() - yf, width, height);
                    }
                });       
        }
        
        /**
         * @param g
         */
        public void paint(Graphics g) {
            super.paint(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setComposite(AlphaComposite.getInstance(AlphaComposite.DST_OVER,1.0f));                     
            g2.drawImage(createBackround(Colors.White.alpha(0.6f), Colors.Black.alpha(0.6f), Colors.Black.alpha(0.1f),width,height), null, 0, 0);         
            g2.dispose();
        }
        
        
        private BufferedImage createBackround(Color outer,Color inner,Color center,int Width, int Height){        
            //Create a buffered image with the borders painted on it
            BufferedImage backround = new BufferedImage(width,height,BufferedImage.TYPE_INT_ARGB);
            Graphics2D g2d = (Graphics2D)backround.getGraphics();
            g2d.addRenderingHints(new RenderingHints(RenderingHints.KEY_ANTIALIASING,
            RenderingHints.VALUE_ANTIALIAS_ON));
            g2d.setBackground(Colors.Black.alpha(0));
            g2d.setColor(center);
            g2d.fillRoundRect(5, 5, Width - 11, Height - 11, 15, 15);
            g2d.setColor(outer);
            g2d.drawRoundRect(5, 5, Width - 11, Height - 11, 15, 15);
            g2d.setColor(inner);
            g2d.drawRoundRect(6, 6, Width - 13, Height - 13, 15, 15);  
                
            g2d.setColor(inner);
            g2d.drawRoundRect(15, 0, 100, 25, 10, 10);
            g2d.setColor(outer);
            g2d.drawRoundRect(14, 0, 102, 26, 10, 10); 
                
            g2d.setColor(inner);
            g2d.drawRoundRect(width - 115, 0, 100, 25, 10, 10);
            g2d.setColor(outer);
            g2d.drawRoundRect(width - 116, 0, 102, 26, 10, 10); 
            g2d.clearRect(0, 0, width, 5);
            g2d.dispose();
            return backround;
        }
    
        /**
         * @param string
         * @param graphicsConfiguration
         */
        public OomrichieFrame(String string,
                              GraphicsConfiguration graphicsConfiguration) {
            super(string, graphicsConfiguration);
            try {
                jbInit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        /**
         * @param string
         */
        public OomrichieFrame(String string) {
            super(string);
            try {
                jbInit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        /**
         * @param graphicsConfiguration
         */
        public OomrichieFrame(GraphicsConfiguration graphicsConfiguration) {
            super(graphicsConfiguration);
            try {
                jbInit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        public OomrichieFrame() {
            super();
            try {
                jbInit();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            new OomrichieFrame();
        }
    }
    l
    Last edited by oomrichie; 04-28-2011 at 07:37 AM.

  2. #2
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    After much tinkering drawing some random images and translating those Colors to Color, it worked. I gotta say that I never thought it could be possible! Good job!

  3. #3
    oomrichie is offline Member
    Join Date
    Feb 2011
    Posts
    31
    Rep Power
    0

    Default

    Ok this is the entire project

    When i use new Robot().createScreenCapture(screenRect); to capture a image of the background, it captures the current frame as well, i would like to only capture the content behind the JFrame and then apply the SwingX GaussianBlurFilter.java to it to achieve the blur transparency look. and then another problem is repainting the entire frame every sec or so will make the application lag, i think. so how will i go about this.

    Then i would like to extend the oomrichieFrame and when the add(Component) method is called, i would like the component to be added to the pannelCenter and not the frame. I know you can just set the components bounds to wherever but i would like it to be this way, especially if you add, lets say a menubar, it should be painted,or added to the top of the pannelCenter not the top of the Frame.

    Third i would like the user to drag the border of the frame to re size it.

    The reasons for me creating this frame is:
    01: I want to be able to add buttons to the titilebar
    02: I would like to set the color of the titlebar text
    03: I would like the titlebar to be thicker

    So if there is an easier way to accomplish this, please let me know, maby by creating a custom look and feel, or what not
    Attached Files Attached Files

  4. #4
    oomrichie is offline Member
    Join Date
    Feb 2011
    Posts
    31
    Rep Power
    0

    Default

    For More Cool GUI Stuff Check Out UI's and Java Swing

  5. #5
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

    Default

    You could probably achieve the blur by increase the opaque-ness of the JFrame.

  6. #6
    oomrichie is offline Member
    Join Date
    Feb 2011
    Posts
    31
    Rep Power
    0

    Default

    Quote Originally Posted by ra4king View Post
    You could probably achieve the blur by increase the opaque-ness of the JFrame.
    No that wont provide the desired affect.
    I found this but i am struggling to implement it on a jframe Blurred Background for Dialogs (Extreme GUI Makeover 2007) – Romain Guy

  7. #7
    oomrichie is offline Member
    Join Date
    Feb 2011
    Posts
    31
    Rep Power
    0

    Default

    PLEASE I NEED HELP, the link is a zip with my progress.

    http://dl.dropbox.com/u/21666209/SwingJ.zip

    The part i need help with is the blur effect of the transparency. i am using Robot() to capture a image of the screen and then applying the SwingX GaussianBlurFilter to the image then i use the Graphics2D TexturePaint to paint the blurred image to the frame. however i need help with updating the frame if it moves and when something in the background moves, if this is not possible i might want to update is every second or so.

    if i call the frame's repaint method it does not clear everything painted and starts over, if i minimize the window and show it again the blur is updated. i would like to recreate this effect.:confused:

  8. #8
    dlorde is offline Senior Member
    Join Date
    Jun 2008
    Posts
    339
    Rep Power
    7

    Default

    Quote Originally Posted by oomrichie View Post
    if i call the frame's repaint method it does not clear everything painted and starts over, if i minimize the window and show it again the blur is updated. i would like to recreate this effect.:confused:
    Not entirely sure what you're saying here, but when repaint (or update) calls paint, the graphics object passed in will have a clip rectangle set to the area that needs repainting. You may be able to adjust that clip rectangle to paint the parts you want. Just a thought.

  9. #9
    oomrichie is offline Member
    Join Date
    Feb 2011
    Posts
    31
    Rep Power
    0

    Default

    Quote Originally Posted by dlorde View Post
    Not entirely sure what you're saying here, but when repaint (or update) calls paint, the graphics object passed in will have a clip rectangle set to the area that needs repainting. You may be able to adjust that clip rectangle to paint the parts you want. Just a thought.
    how would i go about doing this.

  10. #10
    oomrichie is offline Member
    Join Date
    Feb 2011
    Posts
    31
    Rep Power
    0

    Default

    never mind i am now looking into creating my own swing Look and feel. however this looks to be a daunting task.

  11. #11
    ra4king's Avatar
    ra4king is offline Senior Member
    Join Date
    Apr 2011
    Location
    Atlanta, Georgia, US
    Posts
    396
    Rep Power
    4

Similar Threads

  1. Adding a jpanel to a customized Jpanel Class
    By trishtren in forum AWT / Swing
    Replies: 7
    Last Post: 04-05-2011, 06:52 PM
  2. Customized Radio Button
    By Javified in forum AWT / Swing
    Replies: 6
    Last Post: 12-13-2010, 07:06 AM
  3. A customized dialog box
    By radhi in forum AWT / Swing
    Replies: 9
    Last Post: 09-27-2010, 08:06 AM
  4. Create customized ColorChooser
    By LianaN in forum AWT / Swing
    Replies: 1
    Last Post: 08-26-2010, 08:24 PM
  5. How to create a customized layout manager
    By Java Tip in forum javax.swing
    Replies: 0
    Last Post: 06-26-2008, 07:41 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •