-
Bug
-
Resolution: Fixed
-
P3
-
1.4.0
-
beta2
-
x86
-
windows_nt
Name: boT120536 Date: 06/03/2001
java version "1.4.0-beta"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.0-beta-b65)
Java HotSpot(TM) Client VM (build 1.4.0-beta-b65, mixed mode)
Edit the attached simple test program, providing a suitable ".gif" filename for
the toolbar icon. Then, compile and execute the program. Click on the toolbar
icon and notice the behavior of the tabbed pane. Edit the program, changing the
JTabbedPane's TabLayoutPolicy to JTabbedPane.SCROLL_TAB_LAYOUT. Recompile and
execute. Click on the toolbar icon and notice that the tabs added by the
"changeTabbedPaneAction" do not appear as they did when the TabLayoutPolicy was
not scrollable.
/**
* stp.java
*
* @author Gary L. Schaps
* @version 31May01
*/
import java.util.Vector;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
public class stp extends JFrame {
////////////////////////////////////////
// class variables
////////////////////////////////////////
private static String[] tabbedPaneLabels =
{"ONE","TWO","THREE","FOUR","FIVE", "SIX","SEVEN","EIGHT","NINE"};
private static String WINLF = new
String("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
static final String copyright = new String("Simple Test Program
(C) Gary L. Schaps 2001");
static final int WIDTH = 1100;
static final int HEIGHT = 900;
////////////////////////////////////////
// instance variables
////////////////////////////////////////
JPanel top;
JToolBar toolBar;
JTabbedPane tabbedPane;
JPanel[] emptyPanel;
JLabel[] labels;
Font bigFont = new Font("Dialog", Font.PLAIN, 14);
Font iconFont = new Font("Dialog", Font.PLAIN, 9);
Action changeTabbedPaneAction;
JButton button;
/**
* constructor
*/
public stp() {
int i=0;
emptyPanel = new JPanel[9];
labels = new JLabel[9];
tabbedPane = new JTabbedPane();
// tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
setTitle("Simple Test Program");
top = new JPanel();
top.setLayout(new BorderLayout());
getContentPane().add(top, BorderLayout.NORTH);
toolBar = new JToolBar();
toolBar.setFloatable(false);
top.add(toolBar, BorderLayout.SOUTH);
// tool bar button
changeTabbedPaneAction = new AbstractAction("change tabbed pane",
new ImageIcon(getClass().getResource("nutbolt.gif"))){
public void actionPerformed(ActionEvent e) {
tabbedPane.removeAll();
tabbedPane.addTab("A", emptyPanel[0]);
tabbedPane.addTab("B", emptyPanel[1]);
tabbedPane.setSelectedIndex(0);
}
};
button = toolBar.add(changeTabbedPaneAction);
toolBar.add(Box.createRigidArea(new Dimension(5,0)));
button.setText("Change Tabbed Pane");
button.setFont(iconFont);
button.setBorderPainted(false);
button.setFocusPainted(false);
button.setToolTipText("change tabbed pane");
for(i=0; i<9; i++){
labels[i] = new JLabel(copyright, JLabel.CENTER);
labels[i].setFont(bigFont);
emptyPanel[i] = new JPanel();
emptyPanel[i].add(labels[i], BorderLayout.CENTER);
tabbedPane.addTab(tabbedPaneLabels[i], emptyPanel[i]);
}
getContentPane().add(tabbedPane, BorderLayout.CENTER);
} // stp()
/**
* main
*/
public static void main(String args[]) throws
UnsupportedLookAndFeelException,
ClassNotFoundException, InstantiationException, IllegalAccessException {
JFrame f = new stp();
String LF;
//
// L&F - Windows on NT, Metal on Solaris
//
try{
LF = UIManager.getSystemLookAndFeelClassName();
if (LF.compareTo(WINLF) == 0) {
UIManager.setLookAndFeel(LF);
}
}catch (Exception exc){
System.err.println("Error loading L&F: " + exc);
}
f.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e){
System.exit(0);
}
});
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
f.setLocation(screenSize.width/2 - WIDTH/2,
screenSize.height/2 - HEIGHT/2);
f.setSize(WIDTH, HEIGHT);
f.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
f.setVisible(true);
} // main()
} // EOF
(Review ID: 125561)
======================================================================