Results 1 to 2 of 2

Thread: Advanced GUI

  1. #1
    Join Date
    Feb 2005
    Middle Village, NY

    Advanced GUI

    hey guys, i was wonderig what else i could use beside the basic grid flow and border layouts, cause these are just not doing wha i need them to do. i started using netbeans application to design forms, but i dont like that im not writing the code. i saw they used groupLayout for there layout , but im not sure how they did it. does someone have any suggestions for me, or a tutorial would ben ice.

  2. #2
    Join Date
    Apr 2005
    Perth, Australia
    What your after I think, is the gridbag layout manager.

    There is a big conceptual leap between the simple and the advanced layout managers. If you can use the standard managers they are usually easier but once they arent good enough your pretty much forced to use gridbag, its the most complicated and at times its very very hard to use. You can set a null layout and then just position things with pixels positions, but it usually wont do becuase its not dynamic and you dont get full control over things, and then of course small differences between peoples different look and feels (as in default windows mac and unix) will throw off calculations, so really its better for components to be postioned relative to each other.

    If you search it up im sure you will find plentifull amounts of examples and tutorials, here is a quick reference of it in practice, the mainframe constructor for my poker game which pretty much uses gridbag everywhere.

    I have found that once I know the manager its the most capable and predictable so ive just begun to use it everywhere.

    	//Layout Variables//
    	private GridBagLayout 			_FrameLayout;
    	private GridBagConstraints 		_FrameLayoutConstraints;
    	//Panel Variables//
    	protected CardsPanel			_playerOneCardPanel;
    	protected CheckPanel			_playerOneCheckPanel;
    	protected CardsPanel			_playerTwoCardPanel;
    	protected CheckPanel			_playerTwoCheckPanel;
    	protected ButtonPanel 			_buttonPanel;
    	//Game Logic Object//
    	protected Logic 			_logic;
    	protected Container 			_c;
       //MainFrame Constructor//
       public MainFrame()
       	setTitle("Waylander's Vs Poker");
        	addWindowListener(new MyWindowListener());
        	_FrameLayout 		    = new GridBagLayout();
        	_FrameLayoutConstraints = new GridBagConstraints();
        	_c = getContentPane();
        	_FrameLayoutConstraints.fill = GridBagConstraints.HORIZONTAL;
        	_FrameLayoutConstraints.gridy 		= 0;
        	_FrameLayoutConstraints.insets 		= new Insets(10,0,0,0);
        	addComponent(_playerOneCardPanel  	= new CardsPanel());
        	_FrameLayoutConstraints.gridy 		= 1;
        	_FrameLayoutConstraints.insets 		= new Insets(0,0,0,0);
        	addComponent(_playerOneCheckPanel 	= new CheckPanel());
        	_FrameLayoutConstraints.gridy 		= 2;
        	_FrameLayoutConstraints.insets 		= new Insets(15,0,0,0);
        	addComponent(_playerTwoCardPanel 	= new CardsPanel());
        	_FrameLayoutConstraints.gridy 		= 3;
        	_FrameLayoutConstraints.insets 		= new Insets(0,0,0,0);
        	addComponent(_playerTwoCheckPanel 	= new CheckPanel());	  
        	_FrameLayoutConstraints.gridy 		= 4;
        	_FrameLayoutConstraints.insets 		= new Insets(15,0,0,0);
        	addComponent(_buttonPanel 		= new ButtonPanel());	
        	_logic = new Logic();
    //Apply constraints and add components
    protected void addComponent(Component component)
    	_FrameLayout.setConstraints( component, _FrameLayoutConstraints);
    Basically you define a constraints object, which has many properties I think around 20 the ones I dont set I know what the defaults are and havent bothered setting them.

    Once you define the constraints for the component you apply the constraints to it and then add it to the container. You use the same constraints object each time so you have to set things back after you use them, the complications come from knowing what each property does and whats even more complicated is how they react with each other.

    Last edited by Waylander; 12-20-2005 at 06:17 PM.
    Perth Web Development
    Web Developer
    Perth, Western Australia

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Recent Articles