Results 1 to 6 of 6
  1. #1
    Join Date
    Nov 2009
    Posts
    23
    Rep Power
    0

    Default Anyone know how GroupLayout works?

    Following Code is not working...gives me this error:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: ............... is not attached to a horizontal group

    I followed the exampledirectly from sun's toturial on GroupLayouts.

    any ideas? Thanks

    Java Code:
    		GroupLayout layout = new GroupLayout(controls);
    		controls.setLayout(layout);
    		layout.setAutoCreateGaps(true);
    		layout.setAutoCreateContainerGaps(true);
    		
    		layout.setHorizontalGroup(layout.createSequentialGroup()
    				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addComponent(text1)
    						.addComponent(text2))
    				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addComponent(search)
    						.addComponent(find)
    						.addComponent(rb1)
    						.addComponent(rb2)
    						.addComponent(rb3)
    						.addComponent(new JScrollPane(output)))
    				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addComponent(finder)
    						.addComponent(searcher)
    						.addComponent(new JScrollPane(content)))
    		);
    		layout.linkSize(SwingConstants.HORIZONTAL, finder, searcher);
    		layout.setVerticalGroup(layout.createSequentialGroup()
    				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
    						.addComponent(text1)
    						.addComponent(find)
    						.addComponent(finder))
    				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
    						.addComponent(text2)
    						.addComponent(search)
    						.addComponent(searcher))
    				.addComponent(rb1)
    				.addComponent(rb2)
    				.addComponent(rb3)
    				.addGroup(layout.createParallelGroup(GroupLayout.Alignment.LEADING)
    						.addComponent(new JScrollPane(output))
    						.addComponent(new JScrollPane(content)))
    				);

  2. #2
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Also posted at Sun Forums

  3. #3
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Most folk I know don't try to hand-code GroupLayout but rather if they use it, they use as it was designed to be used: to be generated and maintained by an IDE.

    Those that do hand-coding of Swing layouts (myself included) generally use the more people-friendly layouts.

    Edit: please do not cross-post without notifying us that you are doing so. Not only is this counter to the agreement you signed on entering this forum, but the volunteers here risk wasting our own valuable time trying to explain things that have already been explained in other fora. It is for this reason that folks who repeatedly cross-post without notification often get ignored here and elsewhere.

    Thanks for your cooperation.

  4. #4
    pbrockway2 is offline Moderator
    Join Date
    Feb 2009
    Location
    New Zealand
    Posts
    4,565
    Rep Power
    12

    Default

    Consider posting a SSCCE - something brief that compiles and shows the runtime error. The code you posted makes reference to all sorts of other components which can only obscure the problem.

    If you post at multiple places it is a very good idea to be up front about this. Many people will consider the effort they might make to think and reply to have been wasted if the actual conversation is being carried on elsewhere.

  5. #5
    Join Date
    Nov 2009
    Posts
    23
    Rep Power
    0

    Default

    @ Fubarable

    Which layouts would you recommend?
    Sorry for the cross post. I will notify you guys in the future if I do this.
    Yes GroupLayout seems like it might be a lost cause haha but all the tutorials make it looks so aesthetic.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by ProgrammingPup View Post
    @ Fubarable
    Which layouts would you recommend?
    Whichever works best for the situation. Myself, I use BorderLayout, GridLayout, BoxLayout, and FlowLayout quite a bit (though less FlowLayout). I use GridBagLayout when I have to, and I have sometimes delved into the non-standard layouts such as the excellent MigLayout.

    The key thing about layout managers, the tip that gives most of us the "aha" moment, is that you often don't use just one, but rather you often nest JPanels, each using their own layout. For instance, I commonly use BorderLayout for the main JPanel that holds everything and then I sometimes add a JPanel that holds JButtons and uses GridLayout in the main panel's BorderLayout.SOUTH, etc...

    Sorry for the cross post. I will notify you guys in the future if I do this.
    and we very much appreciate this!

    Yes GroupLayout seems like it might be a lost cause haha but all the tutorials make it looks so aesthetic.
    anesthetic is more like it.

    Much luck!

Similar Threads

  1. what is and how works the first ?, example.com/details?page=4
    By lse123 in forum JavaServer Pages (JSP) and JSTL
    Replies: 4
    Last Post: 10-29-2009, 02:18 PM
  2. Doubt with GroupLayout
    By emylyano3 in forum AWT / Swing
    Replies: 1
    Last Post: 06-28-2009, 02:16 AM
  3. help about class GroupLayout
    By MaHa in forum NetBeans
    Replies: 2
    Last Post: 09-07-2008, 11:25 PM
  4. [SOLVED] Alignment in GroupLayout
    By nanou in forum AWT / Swing
    Replies: 8
    Last Post: 09-03-2008, 03:14 AM
  5. Replies: 6
    Last Post: 07-10-2008, 07:28 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
  •