-
Bug
-
Resolution: Won't Fix
-
P4
-
1.4.2
-
x86
-
windows_2000
Issue | Fix Version | Assignee | Priority | Status | Resolution | Resolved In Build |
---|---|---|---|---|---|---|
JDK-2172576 | 1.4-pool | Unassigned | P5 | Closed | Won't Fix |
Name: rmT116609 Date: 05/26/2004
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 2000
A DESCRIPTION OF THE PROBLEM :
I have a JTextPane inside JScrollPane and the JScrollPane is on a JPanel. JPanel has border layout. I need to print JTextPane only. I print other
components below the JTextPane. Given the width of paper, I need to figure out how much height is required to print the JTextPane. The
getPreferredSize().height returned by the JTextPane is wrong in JDK 1.4.1 and 1.5.0. In JDK 1.3.1, it was giving the right height.
The JPanel is sometimes added to a container and sometimes it is not added to a container. It used to work in both the cases in JDK 1.3.1
and both the cases are not working in 1.4.1 and 1.5.0.
If this is not a bug, then please give me a piece of code to get the preferred height of JTextPane. I need to set this height on JScrollPane or
JTextPane before calling print() method on JTextPane. Please note that the JPanel containing the ScrollPane may or may not be on a container.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided test case in JDK1.3.1, 1.4.1 and 1.5.0. You will see the preferred height on the console. You will see 3 different preferred heights
for 3 versions of JDK.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Preferred height of 36 in JDK 1.3.1 is correct because the text "Sheet 1:2 23/3/4" can fit in one line if the available width is 600 pixels.
ACTUAL -
In JDK 1.4.1, the preferred height is 118
In JDK 1.5.0, the preferred height is 133
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
public class JTextPaneTest extends JComponent{
public static void main(String[] args){
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JTextPane pane = new JTextPane();
pane.setContentType("text/html");
pane.setText("<p align=\"center\"><span style=\"font-weight:bold; font-size:16pt; color:#336699; font-family:Dialog;\">"+"Sheet 1:2 23/3/4"+"</span></p>");
JScrollPane scrollPane = new JScrollPane(pane);
panel.add(scrollPane, BorderLayout.CENTER );
if(panel.getParent() == null)
scrollPane.setSize(new Dimension(500,500)); //arbitrary size
scrollPane.setSize(600, pane.getPreferredSize().height);
int height = scrollPane.getSize().height;
System.out.println("JTextPane height " + pane.getPreferredSize().height);
System.out.println("JScrollPane height " + height);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The workaround works for JDK 1.4.1 only and the preferred height is 42(very close to 36).
public class JTextPaneTest extends JComponent{
public static void main(String[] args){
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JTextPane pane = new JTextPane();
pane.setContentType("text/html");
pane.setText("<p align=\"center\"><span style=\"font-weight:bold; font-size:16pt; color:#336699; font-family:Dialog;\">"+"Sheet 1:2 23/3/4"+"</span></p>");
JScrollPane scrollPane = new JScrollPane(pane);
panel.add(scrollPane, BorderLayout.CENTER );
if(panel.getParent() == null)
scrollPane.setSize(new Dimension(500,500)); //arbitrary size
scrollPane.setSize(600, pane.getPreferredSize().height);
scrollPane.getViewport().setSize(600, pane.getPreferredSize().height);
int height = scrollPane.getSize().height;
System.out.println("JTextPane height " + pane.getPreferredSize().height);
System.out.println("JScrollPane height " + height);
}
}
Release Regression From : 1.3.1
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Incident Review ID: 275184)
======================================================================
###@###.### 11/4/04 14:01 GMT
FULL PRODUCT VERSION :
java version "1.4.1_01"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Windows 2000
A DESCRIPTION OF THE PROBLEM :
I have a JTextPane inside JScrollPane and the JScrollPane is on a JPanel. JPanel has border layout. I need to print JTextPane only. I print other
components below the JTextPane. Given the width of paper, I need to figure out how much height is required to print the JTextPane. The
getPreferredSize().height returned by the JTextPane is wrong in JDK 1.4.1 and 1.5.0. In JDK 1.3.1, it was giving the right height.
The JPanel is sometimes added to a container and sometimes it is not added to a container. It used to work in both the cases in JDK 1.3.1
and both the cases are not working in 1.4.1 and 1.5.0.
If this is not a bug, then please give me a piece of code to get the preferred height of JTextPane. I need to set this height on JScrollPane or
JTextPane before calling print() method on JTextPane. Please note that the JPanel containing the ScrollPane may or may not be on a container.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Run the provided test case in JDK1.3.1, 1.4.1 and 1.5.0. You will see the preferred height on the console. You will see 3 different preferred heights
for 3 versions of JDK.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Preferred height of 36 in JDK 1.3.1 is correct because the text "Sheet 1:2 23/3/4" can fit in one line if the available width is 600 pixels.
ACTUAL -
In JDK 1.4.1, the preferred height is 118
In JDK 1.5.0, the preferred height is 133
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.awt.*;
import javax.swing.*;
public class JTextPaneTest extends JComponent{
public static void main(String[] args){
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JTextPane pane = new JTextPane();
pane.setContentType("text/html");
pane.setText("<p align=\"center\"><span style=\"font-weight:bold; font-size:16pt; color:#336699; font-family:Dialog;\">"+"Sheet 1:2 23/3/4"+"</span></p>");
JScrollPane scrollPane = new JScrollPane(pane);
panel.add(scrollPane, BorderLayout.CENTER );
if(panel.getParent() == null)
scrollPane.setSize(new Dimension(500,500)); //arbitrary size
scrollPane.setSize(600, pane.getPreferredSize().height);
int height = scrollPane.getSize().height;
System.out.println("JTextPane height " + pane.getPreferredSize().height);
System.out.println("JScrollPane height " + height);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
The workaround works for JDK 1.4.1 only and the preferred height is 42(very close to 36).
public class JTextPaneTest extends JComponent{
public static void main(String[] args){
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
JTextPane pane = new JTextPane();
pane.setContentType("text/html");
pane.setText("<p align=\"center\"><span style=\"font-weight:bold; font-size:16pt; color:#336699; font-family:Dialog;\">"+"Sheet 1:2 23/3/4"+"</span></p>");
JScrollPane scrollPane = new JScrollPane(pane);
panel.add(scrollPane, BorderLayout.CENTER );
if(panel.getParent() == null)
scrollPane.setSize(new Dimension(500,500)); //arbitrary size
scrollPane.setSize(600, pane.getPreferredSize().height);
scrollPane.getViewport().setSize(600, pane.getPreferredSize().height);
int height = scrollPane.getSize().height;
System.out.println("JTextPane height " + pane.getPreferredSize().height);
System.out.println("JScrollPane height " + height);
}
}
Release Regression From : 1.3.1
The above release value was the last known release where this
bug was known to work. Since then there has been a regression.
(Incident Review ID: 275184)
======================================================================
###@###.### 11/4/04 14:01 GMT
- backported by
-
JDK-2172576 REGRESSION: JScrollPane's height is wrong when it contains JTextPane
-
- Closed
-