社区
Java SE
帖子详情
JTextPane的问题
synclock
2003-09-13 10:02:54
怎么设置不要自动换行,就像jtextarea中的setTextWrap(好像是这个)那样
谢谢
...全文
48
5
打赏
收藏
JTextPane的问题
怎么设置不要自动换行,就像jtextarea中的setTextWrap(好像是这个)那样 谢谢
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
YuLimin
2003-09-13
打赏
举报
回复
应当可以吧,不错;)
liad
2003-09-13
打赏
举报
回复
可以参考http://forum.java.sun.com/thread.jsp?forum=57&thread=326017
Keepers
2003-09-13
打赏
举报
回复
以上两个是sun网站的解决方案
Keepers
2003-09-13
打赏
举报
回复
这么解决不知道行不.
import java.awt.*;import javax.swing.*;import javax.swing.text.*;public class TestNoWrap extends JFrame{ JTextPane textPane; JScrollPane scrollPane; public TestNoWrap() { JPanel panel = new JPanel(); panel.setLayout( new BorderLayout() ); setContentPane( panel ); // no wrap by adding text pane to a panel using border layout textPane = new JTextPane(); textPane.setText("1234567890 1234567890 1234567890"); JPanel noWrapPanel = new JPanel(); noWrapPanel.setLayout( new BorderLayout() ); noWrapPanel.add( textPane ); scrollPane = new JScrollPane( noWrapPanel ); scrollPane.setPreferredSize( new Dimension( 200, 100 ) ); panel.add( scrollPane, BorderLayout.NORTH ); // no wrap by overriding text pane methods textPane = new JTextPane() { public void setSize(Dimension d) { if (d.width < getParent().getSize().width) d.width = getParent().getSize().width; super.setSize(d); } public boolean getScrollableTracksViewportWidth() { return false; } }; textPane.setText("1234567890 1234567890 1234567890"); scrollPane = new JScrollPane( textPane ); scrollPane.setPreferredSize( new Dimension( 200, 100 ) ); panel.add( scrollPane ); } public static void main(String[] args) { TestNoWrap frame = new TestNoWrap(); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setVisible(true); }}
办法2
import java.awt.*;import javax.swing.*;import javax.swing.text.*;public class TextPaneNoWrap extends JFrame{ JTextPane textPane; JScrollPane scrollPane; public TextPaneNoWrap() { JPanel panel = new JPanel(); panel.setLayout( new BorderLayout() ); setContentPane( panel ); // no wrap by adding text pane to a panel using border layout textPane = new JTextPane(); textPane.replaceSelection(" spaces: no wrap - 0 1 2 3 4 5 6 7 8 9"); textPane.replaceSelection("\t\ttabs : wrap - 0 1 2 3 4 5 6 7 8 9\n"); JPanel noWrapPanel = new JPanel(); noWrapPanel.setLayout( new BorderLayout() ); noWrapPanel.add( textPane ); scrollPane = new JScrollPane( noWrapPanel ); scrollPane.setPreferredSize( new Dimension( 200, 100 ) ); panel.add( scrollPane, BorderLayout.NORTH ); // no wrap by overriding text pane methods textPane = new JTextPane() { public void setSize(Dimension d) { if (d.width < getParent().getSize().width) d.width = getParent().getSize().width; super.setSize(d); } public boolean getScrollableTracksViewportWidth() { return false; } }; textPane.replaceSelection("\t\ttabs : wrap - 0 1 2 3 4 5 6 7 8 9"); textPane.replaceSelection(" spaces: no wrap - 0 1 2 3 4 5 6 7 8 9\n"); scrollPane = new JScrollPane( textPane ); scrollPane.setPreferredSize( new Dimension( 200, 100 ) ); panel.add( scrollPane ); } public static void main(String[] args) { TextPaneNoWrap frame = new TextPaneNoWrap(); frame.setDefaultCloseOperation( EXIT_ON_CLOSE ); frame.pack(); frame.setVisible(true); }}
pqds
2003-09-13
打赏
举报
回复
guanzhu!
JAVA-----J
Text
Pane
实例
JAVA-----J
Text
Pane
实例 代码
J
Text
Pane
使用
J
Text
Pane
使用,可以传图片,文字等
关于J
Text
Pane
中进行搜索结果显示的
问题
及解决
NULL 博文链接:https://icarusliu.iteye.com/blog/1412007
J
Text
Pane
关键字变色
SWT J
Text
Pane
可以把控件中需要的字符串的颜色修改成自己想要的颜色
控制jEditor
Pane
和j
Text
Pane
换行的演示程序
演示、说明程序 博文链接:https://bps.iteye.com/blog/136627
Java SE
62,614
社区成员
307,326
社区内容
发帖
与我相关
我的任务
Java SE
Java 2 Standard Edition
复制链接
扫一扫
分享
社区描述
Java 2 Standard Edition
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章