Sponsors: Michael Fertik - Best JAVA Web hosting Company & 30% off


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-20-2009, 09:19 AM
Member
 
Join Date: Nov 2009
Posts: 1
Rep Power: 0
Mahaveer is on a distinguished road
Unhappy add tabbed pane to the frame on a button click
Hi, i have some problem in my code.In this code i have made two Panels(p1 and p2) and one tabbed pane(tp) in which i have added
second panel(p2). on panel 1 i have one button(Go to Tabbed Pane). I want, when i will click on this button,
then the tabbed pane should be added to the frame like this (f.getContentPane().add(tabbed pane); )
but at the same time i want panel 1 to be invisible. in short on the button click i want :
f.getContentPane().add(tabbed pane);
tabbed pane.setVisible(true);
panel_1.setVisible(false);
please do some changes in my code and send me . thank you very much

import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;

public class MultiPanel implements ActionListener
{
JFrame f;
JTabbedPane tp;
JPanel p1,p2;
JLabel l1,l2;
JPasswordField pf;
JButton btn1,btn2;
SpringLayout sl;

MultiPanel()
{
f=new JFrame("Multi Panel Working...");
tp=new JTabbedPane();
tp.setTabPlacement(JTabbedPane.TOP);
p1=new JPanel();
p2=new JPanel();
l1=new JLabel("Enter Password:");
l2=new JLabel("Welcome To Tabbed Pane:");
pf=new JPasswordField(12);
btn1=new JButton("Go to Tabbed Pane");
btn2=new JButton("Go to Panel 1");
sl= new SpringLayout();
}

void dis()
{
f.getContentPane().add(p1);
p1.setLayout(sl);
p2.setLayout(sl);
p1.add(l1);
p1.add(pf);
p2.add(l2);
p1.add(btn1);
p2.add(btn2);

sl.putConstraint(SpringLayout.WEST, l1,375, SpringLayout.WEST, p1 );
sl.putConstraint(SpringLayout.NORTH,l1,200, SpringLayout.NORTH, p1 );

sl.putConstraint(SpringLayout.WEST, pf,475, SpringLayout.WEST, p1 );
sl.putConstraint(SpringLayout.NORTH,pf,200, SpringLayout.NORTH, p1 );

sl.putConstraint(SpringLayout.WEST, btn1,500,SpringLayout.WEST, p1 );
sl.putConstraint(SpringLayout.NORTH,btn1,300,Sprin gLayout.NORTH,p1 );

sl.putConstraint(SpringLayout.WEST, l2, 375, SpringLayout.WEST, p2 );
sl.putConstraint(SpringLayout.NORTH,l2, 200, SpringLayout.NORTH,p2 );

sl.putConstraint(SpringLayout.WEST, btn2,500, SpringLayout.WEST,p2 );
sl.putConstraint(SpringLayout.NORTH,btn2,300,Sprin gLayout.NORTH,p2 );

tp.addTab("COmpany Info",null,p2,"Company Information");
f.setSize(1024,738);
f.setResizable(false);
f.setVisible(true);
btn1.addActionListener(this);
}
public static void main(String z[])
{
MultiPanel mp=new MultiPanel();
mp.dis();
}

public void actionPerformed(ActionEvent ae)
{
Object obj=ae.getSource();
if(obj==btn1)
{
try
{
String str=pf.getText();
String arr[] = {"montu","shenu","lala"};
if((str.equals(arr[0]))||(str.equals(arr[1]))||(str.equals(arr[2])))
{
/*Here i want Tabbed pane( tp) to be Visible and panel_1 ( p1) to be invisible */
}
else
{
JOptionPane.showMessageDialog(p2,"Invalid Password");
}
}
catch(Exception ex)
{
JOptionPane.showMessageDialog(p2,"Exp Caught");
}
}
}
}
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with JEditor Pane while resizing the frame sidharth SWT / JFace 5 11-13-2009 05:43 AM
tabbed Pane . programmer_007 AWT / Swing 2 09-03-2009 08:52 PM
JTree and Tabbed Pane paluee AWT / Swing 1 03-30-2009 06:03 AM
How to add a jbutton to tabbed pane headder? Melki AWT / Swing 12 10-15-2008 08:16 PM
Tabbed pane using struts 2.x......? prabhurangan Web Frameworks 2 07-19-2008 06:48 AM


Java Forums is supported by the best jsp hosting.

All times are GMT +2. The time now is 05:05 AM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org