-
Bug
-
Resolution: Fixed
-
P2
-
9, 10
-
b36
This bug was reported on Swing alias by Alan Snyder <javalists@cbfiddle.com>
The performance downgrade is rather big > 20x.
Test to benchmark the layout:
===================================
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Element;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.View;
public class Test {
public static void main(String[] args) {
boolean isRepeat = args.length > 0 && args[0].equals("repeat");
new Test(isRepeat ? 1000 : 1);
}
public Test(int count) {
TestRunner r = new TestRunner();
for (int i = 0; i < 100; i++) {
r.runTest();
}
for (int counter = 0; counter < count; counter++) {
long ts1 = System.currentTimeMillis();
for (int i = 0; i < 2000; i++) {
r.runTest();
}
long ts2 = System.currentTimeMillis();
System.err.println("Test: " + (ts2 - ts1) + " milliseconds");
}
}
class TestRunner {
View view;
int counter;
float width;
float height;
TestRunner() {
try {
DefaultStyledDocument doc = new DefaultStyledDocument();
String text = createText();
doc.insertString(0, text, new SimpleAttributeSet());
Element p = doc.getParagraphElement(0);
JTextPane pane = new JTextPane(doc);
view = pane.getUI().getRootView(pane);
} catch (BadLocationException ex) {
throw new UnsupportedOperationException(ex);
}
}
void runTest() {
counter++;
if (counter % 2 == 0) {
width = 600;
height = 600;
} else {
width = 800;
height = 400;
}
view.setSize(width, height);
}
String createText() {
String s = "Inserts some content into the document. Inserting content causes a write lock to be held while the actual changes are taking place, followed by notification to the observers on the thread that grabbed the write lock. ";
return s + s + s + s + s + "\n";
}
}
}
The performance downgrade is rather big > 20x.
Test to benchmark the layout:
===================================
import javax.swing.JTextPane;
import javax.swing.text.BadLocationException;
import javax.swing.text.DefaultStyledDocument;
import javax.swing.text.Element;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.View;
public class Test {
public static void main(String[] args) {
boolean isRepeat = args.length > 0 && args[0].equals("repeat");
new Test(isRepeat ? 1000 : 1);
}
public Test(int count) {
TestRunner r = new TestRunner();
for (int i = 0; i < 100; i++) {
r.runTest();
}
for (int counter = 0; counter < count; counter++) {
long ts1 = System.currentTimeMillis();
for (int i = 0; i < 2000; i++) {
r.runTest();
}
long ts2 = System.currentTimeMillis();
System.err.println("Test: " + (ts2 - ts1) + " milliseconds");
}
}
class TestRunner {
View view;
int counter;
float width;
float height;
TestRunner() {
try {
DefaultStyledDocument doc = new DefaultStyledDocument();
String text = createText();
doc.insertString(0, text, new SimpleAttributeSet());
Element p = doc.getParagraphElement(0);
JTextPane pane = new JTextPane(doc);
view = pane.getUI().getRootView(pane);
} catch (BadLocationException ex) {
throw new UnsupportedOperationException(ex);
}
}
void runTest() {
counter++;
if (counter % 2 == 0) {
width = 600;
height = 600;
} else {
width = 800;
height = 400;
}
view.setSize(width, height);
}
String createText() {
String s = "Inserts some content into the document. Inserting content causes a write lock to be held while the actual changes are taking place, followed by notification to the observers on the thread that grabbed the write lock. ";
return s + s + s + s + s + "\n";
}
}
}
- relates to
-
JDK-8156217 Selected text is shifted on HiDPI display
- Resolved