JTextArea中的换行导致JScrollPane与MiGLayout无关 [英] Line wrap in a JTextArea causes JScrollPane to missbehave with MiGLayout
问题描述
我遇到与这个家伙同样的问题:
当与linewrap = true一起使用时,MigLayout JTextArea不会收缩
<我使用了其中一个答案中描述的解决方案;明确设置最小大小。如果将包含JTextArea的JPanel直接放在JFrame中,然后调整窗口大小,这可以正常工作。
但是,当将包含JTextArea的面板放在一个窗口中时JScrollPane,
再次出现同样的问题。为什么会这样,以及如何修复它?
干杯
编辑:一个例子
公共类MiGTest2扩展了JFrame {
public MiGTest2(){
setDefaultCloseOperation(JFrame。 EXIT_ON_CLOSE);
JPanel面板=新JPanel(新的MigLayout(fillx,debug,[fill]));
JTextArea textArea = new JTextArea();
textArea.setLineWrap(true);
panel.add(textArea,wmin 10);
//panel.add(new JTextField());
JScrollPane scrollPane = new JScrollPane(panel);
// add(panel);
add(scrollPane);
pack();
}
public static void main(String [] args){
new MiGTest2()。setVisible(true);
}
}
如果取消注释 //添加(panel);
,并注释 add(scrollPane);
,缩小窗口大小也会缩小JTextArea。也就是说,它不适用于JScrollPane。还要注意布局管理器在第一次放大窗口时缩小窗口大小时,如何翻转并开始摇动其所有内容
我有一个非常类似的问题,并按照上面提到的答案问题也没有帮助我。但是,它确实提供了一个有价值的想法 - 问题在于JTextArea的宽度是否已启用换行。
对我来说有用的是设置最小和首选宽度at使用命令 width
组件级别。例如,宽度10:500:
。
I am having trouble with the same thing as this guy:
MigLayout JTextArea is not shrinking when used with linewrap=true
and I used the solution described in one of the answers; to set the minimum size explicitly. This works fine if one places the JPanel which contains the JTextArea directly in a JFrame, and then resizes the window.
However, when placing the panel which contains the JTextArea inside a JScrollPane, the same problem occurs again. Why is this, and how can one fix it?
Cheers
EDIT: An example
public class MiGTest2 extends JFrame{
public MiGTest2(){
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel(new MigLayout("fillx, debug", "[fill]"));
JTextArea textArea = new JTextArea();
textArea.setLineWrap(true);
panel.add(textArea, "wmin 10");
//panel.add(new JTextField());
JScrollPane scrollPane = new JScrollPane(panel);
//add(panel);
add(scrollPane);
pack();
}
public static void main(String[] args){
new MiGTest2().setVisible(true);
}
}
If you uncomment //add(panel);
, and comment add(scrollPane);
, shrinking the window size will also shrink the JTextArea. That is, it does not work with a JScrollPane. Also note how the layout manager seems to flip out and starts "shaking" all its contents when shrinking the size of the window after first enlarging it
I had a very similar problem and following the answer in the mentioned question did not help me either. However, it did provide a valuable idea -- the problem is in the width of the JTextArea with wrap enabled.
What worked for me was setting both minimum and preferred width at the component level using command width
. For example, width 10:500:
.
这篇关于JTextArea中的换行导致JScrollPane与MiGLayout无关的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!