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

    Default Please help me figure this out

    when I press the button I expected to see the textfield (TestGroupLayer) but instead I do not see anything at all. It only shows an empty frame. I am trying to learn this GroupLayer since it best suites my needs so please someones help. here is the code :


    Java Code:
    package test.gui;
    
    
    
     
    import javax.swing.*;
    import static javax.swing.GroupLayout.Alignment.*;
    
    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)
               
                .addGroup(layout.createParallelGroup(LEADING)
                     .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(LEADING)
                       		) 
               
            )));
            layout.setVerticalGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(BASELINE)
                        .addComponent(textField1)
                     .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(BASELINE)
                          		) 
            )));
     
        }
     
    }
    Java Code:
    package test.gui;
    
    import static javax.swing.GroupLayout.Alignment.BASELINE;
    import static javax.swing.GroupLayout.Alignment.LEADING;
    
     
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;
    
    
    
    public class TestLayerOne extends JPanel {
    
    	TestLayerTwo layerTwo;
        private JButton btn;
        
        public TestLayerOne() {
            initComponents();
        }
    
      
        private void initComponents() {
            
        	btn = new JButton();
    
        	 btn.setText("Button");
             btn.addActionListener(new ActionListener() {
                 public void actionPerformed(ActionEvent evt) {
                     btnActionPerformed(evt);
                 }
             });
             add(btn, new GroupLayout(this));
         
        	
        	
            GroupLayout layout = new GroupLayout(this);
            this.setLayout(layout);
            layout.setAutoCreateGaps(true);
            layout.setAutoCreateContainerGaps(true);
    
            layout.setHorizontalGroup(layout.createSequentialGroup()
                .addComponent(btn)
               
                .addGroup(layout.createParallelGroup(LEADING)
                     .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(LEADING)
                       		) 
               
            )));
            layout.setVerticalGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(BASELINE)
                        .addComponent(btn)
                     .addGroup(layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(BASELINE)
                          		) 
            )));
     
        }
        
        private void btnActionPerformed(ActionEvent evt) {
            
     
        	TestGroupLayer groupLayer = new TestGroupLayer ();
        	removeAll ();
        	add (groupLayer, new GroupLayout (this));
        	validate ();
        	System.out.println("This is a Test");
        }
        
          
    }
    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 TestLayerOne());
    	    tp.addTab("Tab2", new TestGroupLayer()); 
    	    tp.addTab("Tab3", new TestGroupLayer()); 
    	 
    	    setPreferredSize(new Dimension(1360,768));
    	    pack();
    	    setVisible(true);
    	} 
    }
    Last edited by atrodeyo; 04-30-2012 at 05:42 AM.

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

    Default Re: Please me figure this out

    My suggestion: don't use GroupLayout as it is very difficult to code by hand. Instead use nested JPanels that each use simpler layouts to satisfy your needs.

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

    Default Re: Please me figure this out

    ok.. but I still would like to know about this problem tho since I think I am so close. So please someone explain it to me .. please please

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Please me figure this out

    Do you read the responses to your questions? Evidently not.
    What am I doing worng here? help please

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

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

    Default Re: Please me figure this out

    well this is a new issue tho. I was able to get rid of my exception problem with yr help and I was able to see the button and the textfield also but when I press the button it disapears also I was trying with GroupLayer.

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,193
    Rep Power
    19

    Default Re: Please me figure this out

    So once again you didn't click the link I posted.

    I sometimes wonder why I bother.

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

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

    Default Re: Please me figure this out

    if you are talking about the new members guide then yes I did read it but I read it after I posted this and I didnt want to start another thread by changing the title since thats violate one of the rule too.. sorry about that... also I know you mentioned about using different layout but I really want to finish this first so thought someone hopefully and probably will help and point me to the right direction.

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

    Default Re: Please me figure this out

    You may not get much help as not many folks I know use GroupLayout to hand code their layouts, so the pool of potential experts to help you in this subject is limited.

Similar Threads

  1. can't figure it out myself
    By Doyle Raymond in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 11-18-2011, 03:34 PM
  2. can someone help me to figure this out >.<
    By kissmeeq in forum New To Java
    Replies: 2
    Last Post: 08-01-2011, 03:19 PM
  3. Can't figure out
    By beauti477 in forum New To Java
    Replies: 3
    Last Post: 07-20-2011, 03:58 PM
  4. Need help - I can't figure it out.
    By Joshsmith in forum New To Java
    Replies: 2
    Last Post: 10-23-2009, 10:12 PM
  5. I can't figure this out
    By silvia in forum New To Java
    Replies: 3
    Last Post: 07-20-2007, 04:38 AM

Posting Permissions

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