JTextPane遠離JDialog的邊界

[英]JTextPane is going out of boundary from JDialog


chatTextPane = new JTextPane();
chatTextPane.setPreferredSize(new Dimension(350,150));
//chatTextPane.setMaximumSize(new Dimension(350,150));//new
scrollingTextPane = new JScrollPane(chatTextPane);
scrollingTextPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
scrollingTextPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
//scrollingTextPane.setMaximumSize(new Dimension(350,150));

I'm writing a chat program on JDialog. My JTextPane is going out of boundary from the JDialog. I have added two pictures. One is before closing the JDialog window and the other is after opening the JDialog window again.

我正在JDialog上寫一個聊天程序。我的JTextPane遠離JDialog的邊界。我添加了兩張照片。一個是在關閉JDialog窗口之前,另一個是在再次打開JDialog窗口之后。

1 个解决方案

#1


Get rid of chatTextPane.setPreferredSize(new Dimension(350,150));. It's prevent it from telling the JScrollPane how big it should be.

擺脫chatTextPane.setPreferredSize(new Dimension(350,150));.它阻止它告訴JScrollPane應該有多大。

Take a look at Should I avoid the use of set(Preferred|Maximum|Minimum)Size methods in Java Swing? for more reasons why you should avoid using setPreferredSize...just in case your mistake this time didn't make it clear ;)

看看我應該避免在Java Swing中使用set(Preferred | Maximum | Minimum)Size方法嗎?更多理由為什么你應該避免使用setPreferredSize ...以防萬一你的錯誤這次沒有說清楚;)


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2015/05/08/b9fe63494eb1a2454aad99adb5bb7d1c.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com