Created
June 9, 2009 16:19
-
-
Save seanh/126603 to your computer and use it in GitHub Desktop.
Swing problem with styled text component and scroll pane
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package scratch; | |
import java.awt.*; | |
import java.awt.event.*; | |
import javax.swing.*; | |
/** | |
* | |
* @author seanh | |
*/ | |
public class StyledTextWrapAndScroll { | |
StyledTextWrapAndScroll() { | |
JFrame frame = new JFrame(); | |
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
frame.setPreferredSize(new Dimension(150,200)); | |
Container contentPane = frame.getContentPane(); | |
JTextPane tp = new JTextPane(); | |
tp.setContentType("text/html"); | |
tp.setText("<p>bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla bla</p>"); | |
/* This will wrap. | |
JScrollPane scrollPane = new JScrollPane(tp); | |
contentPane.add(scrollPane); */ | |
/* This will not wrap. */ | |
JPanel panel = new JPanel(); | |
panel.add(tp); | |
JScrollPane scrollPane = new JScrollPane(panel); | |
scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); | |
contentPane.add(scrollPane); | |
frame.pack(); | |
frame.setVisible(true); | |
} | |
public static void main(String[] args) { | |
new StyledTextWrapAndScroll(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment