I have written a small program for creating a simple gui with tabbed panes.Currently it has two tabs. In one of the tabs i have created a button and in another tabs i have created two buttons(based upon a string in a third class).What i am not able to do is inside the second tab i want to created two tabs ("one" and "two" refered in te code) and the two button that are currently in the tab should be present in each of the sub tabs.Can anybody tell me how can i acheive this?
main class: abc.java
public class abc {
JFrame frame;
JTabbedPane tabPane;
abc_export exp;
bsm_import2 imp;
public static void main(String[] args) {
abc jtab = new abc();
jtab.start();
}
public void start(){
exp=new abc_export();
imp=new bsm_import2();
tabPane.addTab("bsm_export", exp.tab);
tabPane.addTab("bsm_import2", imp.tab);
}
public abc() {
// Create a frame
frame = new JFrame();
// Create the tabbed pane.
tabPane = new JTabbedPane();
//Adding into frame
frame.add(tabPane, BorderLayout.CENTER);
frame.setSize(300, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
Class two:abc_export.java
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class abc_export {
JPanel tab;
public abc_export() {
//Adding into frame
tab = new JPanel();
JButton btn=new JButton("run");
tab.add(btn);
tab.setOpaque(false);
}
};
class three: bsm_import2.java(this is where i need the changes to be done to create sub tabs)
import javax.swing.*;
import java.awt.*;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.*;
import java.util.StringTokenizer;
import java.util.*;
import java.awt.event.*;
public class bsm_import2 {
public static JPanel tab;
public bsm_import2()
{
createAndShowGUI();
}
private static void createAndShowGUI() {
tab=new JPanel();
tab.setLayout(new GridLayout(3,2));
String line="tab1#one tab2#two";
String strAry[] = line.split(" ");
JButton Button[]=new JButton[100];
final Map<String, String> map = new HashMap<String, String>();
for(int i =0; i < strAry.length ; i++){
String[] parts = strAry[i].split("#");
map.put(parts[0],parts[1]);
Button[i] = new JButton(parts[0]);
tab.add(Button[i]);
tab.setOpaque(false);
}
for ( String key : map.keySet() ) {
System.out.println( key );
}
}
}