-
Bug
-
Resolution: Won't Fix
-
P3
-
6u18
-
x86
-
windows_xp
When a JTextArea is constructed with rows and columns arguments like JTextArea(2, 20)
and with line-wrapping option like setLineWrap(true) and set monospaced font, the
JTextArea must line-wrap at the specified position.
For example, JTextArea(2, 20) work correctly in JRE 1.6.0_17 like this;
a-1) Input 20 characters: "12345678901234567890"
-> No wrap
----------------------
|12345678901234567890|
| |
----------------------
a-2) Input one more character: "1"
-> The wrap point is correct (after the 20th character).
----------------------
|12345678901234567890|
|1 |
----------------------
But, not in JRE 1.6.0_18;
b-1) Input 20 characters: "12345678901234567890"
-> No wrap
----------------------
|12345678901234567890|
| |
----------------------
b-2) Input one more character: "1"
-> The wrap point is not correct (not 20th, but 19th and 2 characters are
at the next line).
----------------------
|1234567890123456789 |
|01 |
----------------------
It seems to be caused by the changes of javax.swing.text.WrappedPlainView and
javax.swing.text.Utilities for Bug ID 6857057 (6828938).
- STEPS TO FOLLOW TO REPRODUCE THE PROBLEM:
OS: Windows XP SP2
JRE: 6u18
1. Save the following codes.
2. Compile the following java code.
3. Run the program.
4. Input 20 characters and one more character.
- EXPECTED VERSUS ACTUAL BEHAVIOR:
EXPECTED:
When JTextArea(2, 20), the line-wrap is after the 20th character.
ACTUAL:
When JTextArea(2, 20), the line-wrap is after the 19th character and 2 characters are at the next line.
For the following source code, this bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class JTextAreaTest extends JFrame {
private JPanel panel;
private JTextArea textarea;
private static final long serialVersionUID = -1757960069921078681L;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JTextAreaTest test = new JTextAreaTest();
test.pack();
test.setVisible(true);
}
});
}
public JTextAreaTest() {
textarea = new JTextArea(2, 20);
textarea.setLineWrap(true);
textarea.setWrapStyleWord(false);
textarea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 13));
textarea.setText("12345678901234567890");
panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(textarea);
this.setContentPane(panel);
this.setTitle(this.getClass().getName());
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
---------- END SOURCE ------------
and with line-wrapping option like setLineWrap(true) and set monospaced font, the
JTextArea must line-wrap at the specified position.
For example, JTextArea(2, 20) work correctly in JRE 1.6.0_17 like this;
a-1) Input 20 characters: "12345678901234567890"
-> No wrap
----------------------
|12345678901234567890|
| |
----------------------
a-2) Input one more character: "1"
-> The wrap point is correct (after the 20th character).
----------------------
|12345678901234567890|
|1 |
----------------------
But, not in JRE 1.6.0_18;
b-1) Input 20 characters: "12345678901234567890"
-> No wrap
----------------------
|12345678901234567890|
| |
----------------------
b-2) Input one more character: "1"
-> The wrap point is not correct (not 20th, but 19th and 2 characters are
at the next line).
----------------------
|1234567890123456789 |
|01 |
----------------------
It seems to be caused by the changes of javax.swing.text.WrappedPlainView and
javax.swing.text.Utilities for Bug ID 6857057 (6828938).
- STEPS TO FOLLOW TO REPRODUCE THE PROBLEM:
OS: Windows XP SP2
JRE: 6u18
1. Save the following codes.
2. Compile the following java code.
3. Run the program.
4. Input 20 characters and one more character.
- EXPECTED VERSUS ACTUAL BEHAVIOR:
EXPECTED:
When JTextArea(2, 20), the line-wrap is after the 20th character.
ACTUAL:
When JTextArea(2, 20), the line-wrap is after the 19th character and 2 characters are at the next line.
For the following source code, this bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.FlowLayout;
import java.awt.Font;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.SwingUtilities;
public class JTextAreaTest extends JFrame {
private JPanel panel;
private JTextArea textarea;
private static final long serialVersionUID = -1757960069921078681L;
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JTextAreaTest test = new JTextAreaTest();
test.pack();
test.setVisible(true);
}
});
}
public JTextAreaTest() {
textarea = new JTextArea(2, 20);
textarea.setLineWrap(true);
textarea.setWrapStyleWord(false);
textarea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 13));
textarea.setText("12345678901234567890");
panel = new JPanel();
panel.setLayout(new FlowLayout());
panel.add(textarea);
this.setContentPane(panel);
this.setTitle(this.getClass().getName());
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
}
}
---------- END SOURCE ------------
- relates to
-
JDK-8014863 Line break calculations in Java 7 are incorrect.
- Resolved
-
JDK-6857057 api/javax_swing/text/GlyphView/index.html#Methods test fails
- Closed