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]

# 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
# 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