Hi all,
i want to place button on top right hand corner of the tabbed pane, just run the code below, i have add button(it going to insert tab into tabbedpane), i want to place that tab into top right hand corner of the tabbedpane (not inside the tab itself). if i set tab policy setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT), it will give two button at right hand corner along with those buttons i want to and one more add button.
please suggest so that i can move forward.
Thanks in advance
import java.awt.Dimension;
import java.util.HashMap;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
/**
*
* @author Dayananda.BV
*/
public class TabpaneDemo extends javax.swing.JFrame {
/** Creates new form TabpaneDemo */
HashMap<Integer, tabpanel> panelMap = new HashMap<Integer, tabpanel>();
public TabpaneDemo() {
initComponents();
createFloorPlan();
getContentPane().setPreferredSize(new Dimension(400,400));
jTabbedPane1.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">
private void initComponents() {
jTabbedPane1 = new javax.swing.JTabbedPane();
add_tab_button = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
add_tab_button.setText("+");
add_tab_button.setMargin(new java.awt.Insets(0, 0, 0, 0));
add_tab_button.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
add_tab_buttonActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(308, Short.MAX_VALUE)
.addComponent(add_tab_button, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(67, 67, 67))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(add_tab_button)
.addGap(8, 8, 8)
.addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 292, Short.MAX_VALUE))
);
pack();
}// </editor-fold>
private void createFloorPlan(){
tabpanel floorplan_Panel = new tabpanel(panelMap.size()+1);
panelMap.put(floorplan_Panel.getTabIndex(), floorplan_Panel);
jTabbedPane1.add(floorplan_Panel, floorplan_Panel.getTabName());
jTabbedPane1.setSelectedIndex(jTabbedPane1.getTabCount()-1);
}
private void add_tab_buttonActionPerformed(java.awt.event.ActionEvent evt) {
createFloorPlan();
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new TabpaneDemo().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton add_tab_button;
private javax.swing.JTabbedPane jTabbedPane1;
// End of variables declaration
class tabpanel extends JPanel{
private int tabIndex = 0;
private String tabName ;
public tabpanel(int tabIndex) {
this.tabIndex = tabIndex;
if(tabIndex >= 10) {
tabName = "Floor Map"+tabIndex;
} else{
tabName = "Floor Map"+tabIndex+" ";
}
}
public int getTabIndex(){
return tabIndex;
}
public String getTabName(){
return tabName;
}
}
}
Thanks
Dayananda B V