狠狠撸

狠狠撸Share a Scribd company logo
public static void main (String[] args) {
JFrame parent = new JFrame ();
final JTabbedPane pane = new JTabbedPane ();
pane.addTab ("test", null);
FlowLayout f = new FlowLayout (FlowLayout.CENTER, 5, 0);
// Make a small JPanel with the layout and make it non-opaque
JPanel pnlTab = new JPanel (f);
pnlTab.setOpaque (false);
// Create a JButton for adding the tabs
JButton addTab = new JButton ("+");
addTab.setOpaque (false); //
addTab.setBorder (null);
addTab.setContentAreaFilled (false);
addTab.setFocusPainted (false);
addTab.setFocusable (false);
pnlTab.add (addTab);
pane.setTabComponentAt (pane.getTabCount () - 1, pnlTab);
ActionListener listener = new ActionListener () {
@Override
public void actionPerformed (ActionEvent e) {
String title = "Tab " + String.valueOf (pane.getTabCount () - 1);
pane.addTab (title, new JLabel (title));
}
};
addTab.setFocusable (false);
addTab.addActionListener (listener);
pane.setVisible (true);
parent.add (pane);
parent.setSize (new Dimension (400, 200));
parent.setVisible (true);

More Related Content

Add tab jtabbedpane

  • 1. public static void main (String[] args) { JFrame parent = new JFrame (); final JTabbedPane pane = new JTabbedPane (); pane.addTab ("test", null); FlowLayout f = new FlowLayout (FlowLayout.CENTER, 5, 0); // Make a small JPanel with the layout and make it non-opaque JPanel pnlTab = new JPanel (f); pnlTab.setOpaque (false); // Create a JButton for adding the tabs JButton addTab = new JButton ("+"); addTab.setOpaque (false); // addTab.setBorder (null); addTab.setContentAreaFilled (false); addTab.setFocusPainted (false); addTab.setFocusable (false); pnlTab.add (addTab); pane.setTabComponentAt (pane.getTabCount () - 1, pnlTab); ActionListener listener = new ActionListener () { @Override public void actionPerformed (ActionEvent e) { String title = "Tab " + String.valueOf (pane.getTabCount () - 1); pane.addTab (title, new JLabel (title)); } }; addTab.setFocusable (false); addTab.addActionListener (listener); pane.setVisible (true); parent.add (pane); parent.setSize (new Dimension (400, 200)); parent.setVisible (true);