-
Bug
-
Resolution: Duplicate
-
P4
-
None
-
1.2.0
-
generic
-
generic
Name: el35337 Date: 09/24/98
Run the attached code. In the window it brings up,
click on the "Lonely" button in Tab 1. Switch to
Tab 2, note that the Horizontal scrollbar has not
appeared. Click on the friendly button or type in
the text area, note that the horizontal scrollbar
now appears. A quick and dirty workaround for this
is commented out in the code below. This bug
appears for Swing/JFC version 1.0.3 running with
JDK 1.1.5 under HPUX and Windows95 as well as
for JDK 1.1.6 and JDK 1.2beta4 under Windows95
// Code demonstrating the bug. Click the "Lonely" button then switch
// to Tab 2, then click the "Friendly" button. You'll see that the
// scrollbar doesn't appear till the friendly button gets clicked.
import com.sun.java.swing.*;
import com.sun.java.swing.text.Document;
import java.awt.*;
import java.awt.event.*;
class TextAreaScrollBug extends JFrame {
protected JTextArea textArea;
protected JTabbedPane tabbedPane;
protected JButton lonelyButton;
protected JButton friendlyButton;
protected String verboseString =
"abc def ghi jkl mno pqr stu vwx yz 123 456 7890";
public TextAreaScrollBug() {
super("TextAreaScrollBug");
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
textArea = new JTextArea(5, 30);
JScrollPane scrollPane = new JScrollPane(textArea);
lonelyButton = new JButton("I'm Lonely");
lonelyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea.append("I'm Lonely " + verboseString + "\n");
}
});
friendlyButton = new JButton("Text Area likes me!");
friendlyButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textArea.append("I'm friendly " + verboseString + "\n");
}
});
JPanel tab1 = new JPanel();
JPanel tab2 = new JPanel();
tab1.add(lonelyButton, BorderLayout.SOUTH);
tab2.add(friendlyButton, BorderLayout.SOUTH);
tab2.add(scrollPane, BorderLayout.CENTER);
/*
// This is the code which works around the bug - kinda clugy
tab2.addComponentListener(new java.awt.event.ComponentAdapter() {
public void componentShown(ComponentEvent e) {
try {
Document doc = textArea.getDocument();
textArea.append(" ");
doc.remove(doc.getLength() - 1, 1);
} catch (Exception ex) {}
}
});
*/
tabbedPane = new JTabbedPane();
tabbedPane.addTab("Tab 1", tab1);
tabbedPane.addTab("Tab 2", tab2);
JPanel contentPane = new JPanel();
contentPane.setLayout(new BorderLayout());
contentPane.setPreferredSize(new Dimension(400, 200));
contentPane.add(tabbedPane, BorderLayout.CENTER);
setContentPane(contentPane);
}
public static void main(String[] args) {
TextAreaScrollBug frame = new TextAreaScrollBug();
frame.pack();
frame.show();
}
}
(Review ID: 37463)
======================================================================
- duplicates
-
JDK-4159019 scroll bar for text area not created correctly
-
- Resolved
-