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

    Default What am I doing wrong here? please help

    I am trying to call my TabPanels Class and display a button in one of the Tabs. I am able to display all the tabs but I can not see the button. what am I doing wrong here? please help.

    Java Code:
    // TabPanels Class
    package test.gui;
    
    
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    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 JPanel()); 
    	    tp.addTab("Tab2", new JPanel()); 
    	    tp.addTab("Tab3", new JPanel()); 
    	 
    	    setPreferredSize(new Dimension(1360,768));
    	    //   myFrame.setPreferredSize(new Dimension(1360,768)); 
    	    pack();
    	    setVisible(true);
    	} 
    }
    
    
    // layerOne class
    package test.gui;
    
    import javax.swing.*;
    
    
    public class layerOne extends JPanel {
    
    		
    	public static void main(String [] args)  {  
    	    new layerOne(); 
    	} 
    	
    	private JButton btn1;
        	private JButton btn2;
        	private JButton btn3;
        	private JButton btn4;
        
    	private JPanel myPanel;
    	TabPanels tabs;
    	
        public layerOne() {
            initComponents();
        }
    
       
        private void initComponents() {
    
        	tabs = new TabPanels (); // create new tab panels;
        	
            btn1 = new JButton();
               
            myPanel = new JPanel ();
            
    
            btn1.setText("Test");
    
      
            GroupLayout layout = new GroupLayout(myPanel);
            myPanel.setLayout(layout);
            layout.setHorizontalGroup(
                    layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap(236, Short.MAX_VALUE)
                        .addComponent(btn1)
                        .addGap(234, 234, 234))
                );
                layout.setVerticalGroup(
                    layout.createParallelGroup(GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(137, 137, 137)
                        .addComponent(btn1)
                        .addContainerGap(214, Short.MAX_VALUE))
                );
            tabs.add(myPanel);
        }
        
           
    }
    Last edited by atrodeyo; 04-26-2012 at 05:40 PM.

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,559
    Rep Power
    25

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

    Is that generated code? Try getting rid of that and writing the GUI layout yourself.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    k1ng is offline Member
    Join Date
    Apr 2012
    Posts
    59
    Rep Power
    0

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

    You are creating tabs, adding newly created JPanels to them which do don't have a variable to access them through, i.e. JPanel myPanel = new JPanel(); then you have a seperate class that extends JPanel() which is never used. Did you mean to do

    Java Code:
      tp.addTab("Tab1",new layerOne());
      tp.addTab("Tab2", new layerOne());
      tp.addTab("Tab3", new layerOne());
    Last edited by k1ng; 04-26-2012 at 06:08 PM. Reason: fixed some uglyness

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

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

    thanks it worked.

  5. #5
    k1ng is offline Member
    Join Date
    Apr 2012
    Posts
    59
    Rep Power
    0

Similar Threads

  1. Replies: 4
    Last Post: 06-11-2013, 01:37 AM
  2. What am I doing wrong?
    By javajen in forum New To Java
    Replies: 3
    Last Post: 04-11-2011, 05:35 PM
  3. What did I do wrong?
    By GoingThroAPhase in forum New To Java
    Replies: 4
    Last Post: 04-03-2010, 04:51 AM
  4. what's wrong here ?
    By doha786 in forum New To Java
    Replies: 6
    Last Post: 03-26-2010, 12:21 PM
  5. Please help, what am I doing wrong?
    By mmac1218 in forum New To Java
    Replies: 2
    Last Post: 09-01-2009, 11:21 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
  •