Results 1 to 2 of 2

Thread: adding JLabels and JTextFields to a specific JtabbedPane [resolved]

Threaded View

  1. #1

    Thread Starter
    Fanatic Member zmerlinz's Avatar
    Join Date
    May 2000
    Location
    in a world where the sun always shines on the bloody tv!!
    Posts
    604

    Question adding JLabels and JTextFields to a specific JtabbedPane [resolved]

    hi,

    well i am have spent to long pulling my hair out over this one, so i thought i would ask someone who might know. I have four tabs on one main JTabbedpane, and what i want to do is add JButtons and Jlabels to specific Jtabs, everytime i do it seems to put the object in another tab and when i sort of managed to add a JLabel to a tab it overwrote all of the settings, here is the code that i have so far

    Code:
    //this needs to be protected so that the JTabbedPanel thing works, otherwise i get silly errors
    	protected Component makeTextPanel (String text)
    	{
    		JPanel panel = new JPanel (false);
    		JLabel filler = new JLabel (text);
    		filler.setHorizontalAlignment (JLabel.CENTER);
    		panel.setLayout (new GridLayout (1,1));
    		panel.add (filler);
    		return panel;
    	}
    
    	public PennysPapers()
    	{
    		super("Pennys Papers");
            this.setBounds(200,200,600,400);   // x, y offset, width, height
            this.getContentPane().setBackground(Color.yellow);
            WindowHandler w = new WindowHandler();
            this.addWindowListener(w);
    		getContentPane().setLayout (new BorderLayout ());
    
            JPanel mainPanel = new JPanel (new BorderLayout());
            JTabbedPane tabPane = new JTabbedPane();
    		ImageIcon Icon = new ImageIcon("welcome.jpg");
    
    		//adding the first tab to the thingy
    		Component panel1 = makeTextPanel("OMEGA");
            JPanel tabPanel1 = new JPanel(new BorderLayout());
    
            tabPane.addTab("Welcome", null, panel1, "Welcome to Pennys Papers");
            tabPane.setToolTipText("Welcome to Pennys Papers");
            tabPane.add(new JLabel(Icon),"Welcome");
            tabPane.setSelectedIndex(0);
            tabPane.add(new JButton("I AM WEASEL"));
    
    
            //adding the second panel
            Component panel2 = makeTextPanel("Publications");
    		tabPane.addTab("Publications", null, panel2, "Add and remove publications");
    
    		//adding the third panel
    		Component panel3 = makeTextPanel("Customers");
    		tabPane.addTab("Customers", null, panel3, "Add and remove customers");
    
    		//addinf the fourth panel
    		Component panel4 = makeTextPanel("Rounds");
    		tabPane.addTab("Rounds", null, panel4, "Organise paper rounds");
    
            tabPanel1.add(panel1, BorderLayout.CENTER);
            mainPanel.add(tabPanel1, BorderLayout.CENTER);
            mainPanel.add(tabPane, BorderLayout.CENTER);
    		getContentPane().add(mainPanel);
    		//this.pack(); OMG !!! Resistance is Futile :p
    
    	}
    thanks for any help with this

    Last edited by zmerlinz; Mar 9th, 2002 at 09:29 AM.

    Some people have told me they don't think a fat penguin really embodies the grace of Linux, which just tells me they have never seen a angry penguin charging at them in excess of 100mph. They'd be a lot more careful about what they say if they had.
    -- Linus Torvalds

    [Galahtech.com] | [My Site] | [Fishsponge] | [UnixForum.co.uk]

Posting Permissions

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



Click Here to Expand Forum to Full Width