Listener on JToolBar or JButton

I want to display three different tabs at time on click at each button of toolbar so which listener i can use.

My problem scenario

I have Three buttons in JToolBar when i click on one button it will be dispaly three tabs in each button.

I am trying to do this from 4 day ago i did not get any solution so if any one have solution so give me with code.

[377 byte] By [m_m_muddua] at [2007-11-27 9:31:01]
# 1

> I want to display three different tabs at time on

> click at each button of toolbar so which listener i

> can use.

>

> My problem scenario

>

> I have Three buttons in JToolBar when i click on one

> button it will be dispaly three tabs in each button.

If i've understood your question properly (which I doubt) why don't you just use the standard action listener on the buttons which calls a method to add tabs to a jTabbedPane?

c0demonk3ya at 2007-7-12 22:44:42 > top of Java-index,Desktop,Core GUI APIs...
# 2

tanks for ur reply but i alredy use but problem is that

if

i click on one button for eg " button one " and it will show "tabbedapane one "

if

i click on another button for eg "button two " and it will show both tabbedpane "one and two" so this is my actual problem which i suffer.

If u have solution then reply me

m_m_muddua at 2007-7-12 22:44:42 > top of Java-index,Desktop,Core GUI APIs...
# 3
Your exact problem still isn't clear...You need to reate a "Short, Self Contained, Compilable and Executable, Example Program (SSCCE)",see http://homepage1.nifty.com/algafield/sscce.html,that demonstrates the incorrect behaviour
c0demonk3ya at 2007-7-12 22:44:42 > top of Java-index,Desktop,Core GUI APIs...
# 4
shall i give my code to you can u understand thatif yes pls give ur email id
m_m_muddua at 2007-7-12 22:44:42 > top of Java-index,Desktop,Core GUI APIs...
# 5
> shall i give my code to you can u understand that> if yes > pls give ur email idJust post your code here...Make sure you use the code formatting tags so the code retains it's original formatting
c0demonk3ya at 2007-7-12 22:44:42 > top of Java-index,Desktop,Core GUI APIs...
# 6

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class mainScreen extends JFrame implements ActionListener

{

JPanel p1,p2;

JButton jbnMain,jbnArchive,jbnSearch,jbnTask,jbnAlerts,jbnExit;

Container con;

public mainScreen()

{

super("PiConnect -> Main Screen");

super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

con = getContentPane();

p1 = new JPanel();

p1.setLayout(new FlowLayout());

JToolBar jtbMainToolbar = new JToolBar();

jtbMainToolbar.setFloatable(false);

jbnMain = new JButton("Main");

jbnMain.addActionListener(this);

jtbMainToolbar.add(jbnMain);

jbnArchive = new JButton("Archive");

jbnArchive.addActionListener(this);

jtbMainToolbar.add(jbnArchive);

jbnSearch = new JButton("Search");

jbnSearch.addActionListener(this);

jtbMainToolbar.add(jbnSearch);

jbnTask = new JButton("Task");

jbnTask.addActionListener(this);

jtbMainToolbar.add(jbnTask);

jbnAlerts = new JButton("Alerts");

jbnAlerts.addActionListener(this);

jtbMainToolbar.add(jbnAlerts);

p1.add(jtbMainToolbar);

con.add("North",p1);

}

public void setMotifLookAndFeel() {

try {

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

} catch(Exception e) {

System.out.println("Error setting Windows LAF: " + e);

}

}

public void actionPerformed(ActionEvent e)

{

JTabbedPane tabbedPane = new JTabbedPane();

JPanel p2 = new JPanel();

if(e.getSource() == jbnMain)

{

tabbedPane.addTab("Page 1",new JButton(" JButton1"));

tabbedPane.addTab("Page 2",new JTextField("2"));

tabbedPane.addTab("Page 3",new JTextArea("3"));

System.out.println(tabbedPane.isVisible());

}

if(e.getSource() == jbnArchive)

{

tabbedPane.addTab("Page 4",new JButton("Hello"));

tabbedPane.addTab("Page 5",new JTextField("HI !"));

tabbedPane.addTab("Page 6",new JTextArea("How Are You"));

}

p2.add(tabbedPane, BorderLayout.WEST );

con.add(p2);

}

public static void main(String args[])

{

mainScreen ms = new mainScreen();

ms.setMotifLookAndFeel();

ms.setSize(400,400);

ms.setVisible(true);

}

}

See my program

m_m_muddua at 2007-7-12 22:44:42 > top of Java-index,Desktop,Core GUI APIs...
# 7

hi

check this out

import java.awt.BorderLayout;

import java.awt.Container;

import java.awt.FlowLayout;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import javax.swing.JButton;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JTabbedPane;

import javax.swing.JTextArea;

import javax.swing.JTextField;

import javax.swing.JToolBar;

import javax.swing.UIManager;

public class mainScreen extends JFrame implements ActionListener

{

JPanel p1,p2;

JButton jbnMain,jbnArchive,jbnSearch,jbnTask,jbnAlerts,jbnExit;

Container con;

JTabbedPane tabbedPane = new JTabbedPane(); //for following my way

JPanel p3 = new JPanel();//for following my way

public mainScreen()

{

super("PiConnect -> Main Screen");

super.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

con = getContentPane();

p1 = new JPanel();

p1.setLayout(new FlowLayout());

JToolBar jtbMainToolbar = new JToolBar();

jtbMainToolbar.setFloatable(false);

jbnMain = new JButton("Main");

jbnMain.addActionListener(this);

jtbMainToolbar.add(jbnMain);

jbnArchive = new JButton("Archive");

jbnArchive.addActionListener(this);

jtbMainToolbar.add(jbnArchive);

jbnSearch = new JButton("Search");

jbnSearch.addActionListener(this);

jtbMainToolbar.add(jbnSearch);

jbnTask = new JButton("Task");

jbnTask.addActionListener(this);

jtbMainToolbar.add(jbnTask);

jbnAlerts = new JButton("Alerts");

jbnAlerts.addActionListener(this);

jtbMainToolbar.add(jbnAlerts);

p1.add(jtbMainToolbar);

con.add("North",p1);

p3.add(tabbedPane, BorderLayout.WEST );//for following my way

con.add(p3);//for following my way

}

public void setMotifLookAndFeel() {

try {

UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");

} catch(Exception e) {

System.out.println("Error setting Windows LAF: " + e);

}

}

public void actionPerformed(ActionEvent e)

{

//this is in ur way

//JTabbedPane tabbedPane = new JTabbedPane();

//JPanel p3 = new JPanel();

tabbedPane.removeAll();//for following my way

if(e.getSource() == jbnMain)

{

tabbedPane.addTab("Page 1",new JButton(" JButton1"));

tabbedPane.addTab("Page 2",new JTextField("2"));

tabbedPane.addTab("Page 3",new JTextArea("3"));

System.out.println(tabbedPane.isVisible());

}

if(e.getSource() == jbnArchive)

{

tabbedPane.addTab("Page 4",new JButton("Hello"));

tabbedPane.addTab("Page 5",new JTextField("HI !"));

tabbedPane.addTab("Page 6",new JTextArea("How Are You"));

}

//this is in ur way

//p2.add(tabbedPane, BorderLayout.WEST );

//con.add(p2);

//p2.updateUI();

}

public static void main(String args[])

{

mainScreen ms = new mainScreen();

ms.setMotifLookAndFeel();

ms.setSize(400,400);

ms.setVisible(true);

}

}

regards

Aniruddha

Aniruddha-Herea at 2007-7-12 22:44:42 > top of Java-index,Desktop,Core GUI APIs...
# 8
Ya i got where i was wrong
m_m_muddua at 2007-7-12 22:44:42 > top of Java-index,Desktop,Core GUI APIs...
# 9
thanks
m_m_muddua at 2007-7-12 22:44:42 > top of Java-index,Desktop,Core GUI APIs...