Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By DarrylBurke

Thread: What am I doing worng here? help please

  1. #1
    atrodeyo is offline Member
    Join Date
    Apr 2012
    Posts
    41
    Rep Power
    0

    Default What am I doing worng here? help please

    what am I doing wrong here I cant figure out why my code is not compiling please help.
    Here is my TestGroupLayer
    Java Code:
    package test.gui;
    
    
    import javax.swing.*;
    
    
    public class TestGroupLayer extends JPanel {
    	
    	JTextField textField1;
        public TestGroupLayer() {
           
        	textField1 = new JTextField ();
    
            GroupLayout layout = new GroupLayout(this);
            this.setLayout(layout);
            layout.setAutoCreateGaps(true);
            layout.setAutoCreateContainerGaps(true);
    
            layout.setHorizontalGroup(layout.createSequentialGroup()
                .addComponent(textField1));
        }    
    }
    here is my TabPanels code
    Java Code:
    package test.gui;
    
    
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JTabbedPane;
    
    
    
    public class TabPanels extends JFrame{ 
    
    	JFrame myFrame = null;
    	// main to run and test this part of the program
    
    public static void main(String [] args)  {  
        new TabPanels(); 
    } 
    	
    	public TabPanels() { 
    	    JTabbedPane tp = new JTabbedPane(); 
    	    add(tp); 
    	 
    	    tp.addTab("Tab1", new TestGroupLayer());
    	    tp.addTab("Tab2", new TestGroupLayer()); 
    	    tp.addTab("Tab3", new TestGroupLayer()); 
    	 
    	    setPreferredSize(new Dimension(1360,768));
    	    pack();
    	    setVisible(true);
    	} 
    }

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,301
    Rep Power
    20

    Default Re: What am I doing worng here? help please

    Please read the Forum Rules, particularly the third paragraph, and also the Guide For New Members.

    Would you like to tell us what error the compiler threw at you, and from which line, or is this a guessing game?

    Quite apart from any compilation errors you may have, Swing components should be constructed and accessed/modified only on the EDT -- not on the main Thread. Find and go through the Oracle tutorial on Concurrency in Swing to know how to do this correctly.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    atrodeyo is offline Member
    Join Date
    Apr 2012
    Posts
    41
    Rep Power
    0

    Default Re: What am I doing worng here? help please

    its probably really easy for you but since I am brand new and trying to learn so lot of things really doesnt make sense to me and thats why I added here at "new to java. I did read the oracle page and thats how I came up with that portion of the code. And I might be slow but I really want to learn and I am sure there are someone who would be nice and kind to explain it to me.

    this is what I get when I try to compile:

    Exception in thread "main" java.lang.IllegalStateException: javax.swing.JTextField[,0,0,0x0,invalid,layout=javax.swing.plaf.basic.Bas icTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0 .0,border=javax.swing.plaf.BorderUIResource$Compou ndBorderUIResource@46a7041a,flags=296,maximumSize= ,minimumSize=,preferredSize=,caretColor=sun.swing. PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResourc e[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIRes ource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=0,columnWidth=0,command=,horizontalAlignm ent=LEADING] is not attached to a vertical group
    at javax.swing.GroupLayout.checkComponents(Unknown Source)
    at javax.swing.GroupLayout.prepare(Unknown Source)
    at javax.swing.GroupLayout.layoutContainer(Unknown Source)
    at java.awt.Container.layout(Unknown Source)
    at java.awt.Container.doLayout(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validate(Unknown Source)
    at java.awt.Container.validateUnconditionally(Unknown Source)
    at java.awt.Window.pack(Unknown Source)
    at test.gui.TabPanels.<init>(TabPanels.java:28)
    at test.gui.TabPanels.main(TabPanels.java:16)
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: javax.swing.JTextField[,0,0,0x0,invalid,layout=javax.swing.plaf.basic.Bas icTextUI$UpdateHandler,alignmentX=0.0,alignmentY=0 .0,border=javax.swing.plaf.BorderUIResource$Compou ndBorderUIResource@46a7041a,flags=296,maximumSize= ,minimumSize=,preferredSize=,caretColor=sun.swing. PrintColorUIResource[r=51,g=51,b=51],disabledTextColor=javax.swing.plaf.ColorUIResourc e[r=184,g=207,b=229],editable=true,margin=javax.swing.plaf.InsetsUIRes ource[top=0,left=0,bottom=0,right=0],selectedTextColor=sun.swing.PrintColorUIResource[r=51,g=51,b=51],selectionColor=javax.swing.plaf.ColorUIResource[r=184,g=207,b=229],columns=0,columnWidth=0,command=,horizontalAlignm ent=LEADING] is not attached to a vertical group
    at javax.swing.GroupLayout.checkComponents(Unknown Source)
    at javax.swing.GroupLayout.prepare(Unknown Source)
    at javax.swing.GroupLayout.layoutContainer(Unknown Source)
    at java.awt.Container.layout(Unknown Source)
    at java.awt.Container.doLayout(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validateTree(Unknown Source)
    at java.awt.Container.validate(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,301
    Rep Power
    20

    Default Re: What am I doing worng here? help please

    Don't use a visual designer. They're advanced tools. As a matter of fact, too advanced for me.

    Go through those Oracle tutorials and learn to hand-code your GUI. It's a few orders of magnitude easier than having to understand all the quirks of the visual designer.

    GroupLayout wasn't designed for human consumption. Choose another layout for hand-coding.

    db
    Fubarable likes this.
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,301
    Rep Power
    20

    Default Re: What am I doing worng here? help please

    To get rid of the exception, you need to set a vertical group.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  6. #6
    atrodeyo is offline Member
    Join Date
    Apr 2012
    Posts
    41
    Rep Power
    0

    Default Re: What am I doing worng here? help please

    Thanks I got it

Posting Permissions

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