我的JEditorPane
自動換行;我不想那樣。我只想要一個水平條出現,允許用戶儘可能多地寫入。我怎樣才能做到這一點?我嘗試了幾種方法。我已經覆蓋getScrollableTracksViewportWidth()
,但這沒有幫助。有沒有人知道我可以關掉這個詞包裝?如何關閉JEditorPane中的自動換行?
1
A
回答
3
5
一個快速谷歌搜索導致我this page,其通過繼承文本窗格並重寫getScrollableTracksViewportWidth()
方法實現它:
// Override getScrollableTracksViewportWidth
// to preserve the full width of the text
public boolean getScrollableTracksViewportWidth() {
Component parent = getParent();
ComponentUI ui = getUI();
return parent != null ? (ui.getPreferredSize(this).width <= parent
.getSize().width) : true;
}
-1
你爲什麼不使用一個JTextField?
它只有一行。
1
如果你能控制其進入文本,並且您使用的JEditorPane的功能,您可以通過標記HTML代碼,並使用空格:NOWRAP;階梯性質。
jEditorPane1.setContentType("text/html");
StringBuilder sb = new StringBuilder();
sb.append("<div style='");
if (!wordWrap.isSelected()) { //some checkbox
sb.append("white-space:nowrap;");
}
sb.append("font-family:\"Monospaced\">'");
sb.append("your very interesting long and full of spaces text");
/*be aware, more then one space in row will be replaced by single space
to avoid it you need to substitute by .
Also rememberer that \n have to be repalced by <br>
so filering like:
line = line.replaceAll("\n", "<br>\n"); //be aware, <br/> do not work
line = line.replaceAll(" ", " ");
line = line.replaceAll("\t", " ");
may be usefull.*/
sb.append("</div>");
jEditorPane1.settext(sb.toString()); //jeditor pane do not support addition/insertion of text in html mode
相關問題
- 1. JEditorPane中的換行
- 2. 如何在VSCode中打開和關閉自動換行?
- 3. Android Studio - 自動標記關閉 - 關閉換行
- 4. 如何自動關閉infoWindow?
- 5. 如何自動關閉JOptionPane?
- 6. 如何自動關閉InfoWindows
- 7. 如何自動關閉JMXConnectorServer
- 8. 如何自動關閉VTKRenderWindow
- 9. 如何自動關閉alertdialog
- 10. 如何關閉Clion中的自動關閉參數
- 11. 如何在Swift中自動關閉alertview?
- 12. 如何在android中自動關閉GPS?
- 13. 如何在Bluefish中關閉括號自動關閉
- 14. 自動關閉?
- 15. 如何自動關閉JHipster的提醒?
- 16. 如何自動關閉OSX上的NSAlert?
- 17. 單擊UISwitch時關閉自動切換?
- 18. 正則表達式,JEditorPane,自閉標記
- 19. 自動關閉Android中
- 20. 如何自動強行關閉excel,然後重新啓動?
- 21. 如何關閉父項時自動關閉子jFrames?
- 22. PetaPoco - 如何關閉自動增量?
- 23. 如何關閉自動回覆?
- 24. Xcode 8:如何關閉自動保存
- 25. 如何關閉彩盒自動與.js.erb
- 26. 如何自動關閉對話框?
- 27. 如何讓WCF自動關閉連接?
- 28. 如何自動關閉Java服務器?
- 29. 如何關閉Swiftype自動完成?
- 30. Eclipse - 如何自動關閉引號
如果您不需要'JEditorPane'中的功能,那麼可以使用支持'setLineWrap()'方法的'JTextArea'。 –
交叉發表:http://www.coderanch.com/t/565180/GUI/java/turn-off-word-wrap-jeditorpane – camickr