0 Replies - 533 Views - Last Post: 11 February 2009 - 07:39 PM Rate Topic: -----

#1 nick2price  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 562
  • View blog
  • Posts: 2,826
  • Joined: 23-November 07

Shaped GUI window update

Posted 11 February 2009 - 07:39 PM

Just thought i would post to show the progress of my triangle shaped gui window. This one is using transparancy. I know the components are not added in a very logical way at the moment, its just a prototype. Feel free to check it out, and make improvements if you fancy it. (p.s. If your worried, this isnt homework. My tutor just set me a challenge that i couldnt do this!)
import java.awt.*;
import javax.swing.*;

public class ShapedWindow extends JFrame {
	
	private JPanel north;
	
	public ShapedWindow() {
		super("Nicks Triangle");
		createUserInterface();
	}
	
	private void createUserInterface()
	{
		arrangeCompenents();
		setLocation(new Point(0, 0)); 
		setVisible(true); 		
		setSize(500, 500);			
		setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 
	}
	
	private void arrangeCompenents(){  
	
		north = new JPanel();		
		this.setLayout(new BorderLayout());
		this.add(north, BorderLayout.PAGE_START);
		north.setLayout(new FlowLayout());
		north.setBorder(BorderFactory.createRaisedBevelBorder());
		north.setPreferredSize(new Dimension(500, 60)); 
		north.add(new JTextField(25));
		north.add(new JButton("Enter"));
	}
	
	public static void main(String[] args) {
		JFrame.setDefaultLookAndFeelDecorated(true);
		final int npoints = 3;
		final int[] xpoints = {0, 250, 500};
		final int[] ypoints = {0, 500, 0};
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				Window w = new ShapedWindow();
				w.setVisible(true);
				com.sun.awt.AWTUtilities
						.setWindowShape(w, new Polygon(xpoints, ypoints, npoints));
			}
		});
	}

}




Actually, one thing of interest would be whether i could set a boundary around the new shape, so that components cannot go out of this area. Because its transparant, this can currently happen.

This post has been edited by nick2price: 11 February 2009 - 07:41 PM


Is This A Good Question/Topic? 0
  • +

Page 1 of 1