MigLayout JTextArea LineWrap过早包装

时间:2013-12-25 10:17:22

标签: java swing jtextarea miglayout

我有一个JTextArea,它在整个使用过程中将文本设置为各种字符串。我还有一个指定尺寸为150的列!我希望文本一直到最大长度然后换行。但是,现在它正在包裹,并且在包装之前不会达到最大长度。如果我在列中添加“填充”,那么这就解决了问题,但是,我不想填满整个空间,因为我正在创建边框。如果我的文字不长于最大值,那么边框会显示一堆空格。

以下是我如何做这个的例子。

import java.awt.Font;

import net.miginfocom.swing.MigLayout;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JFrame;
public class MigExample extends JFrame {
    public static JPanel panel = new JPanel();
    public static JTextArea content = new JTextArea();
    public static JLabel label;
    public static JFrame guiFrame = new JFrame();
    public static void main(String[] args) {

        content.setEditable(false);  
        content.setCursor(null);  
        content.setOpaque(false);  
        content.setFocusable(false);  
        content.setBorder(BorderFactory.createLoweredBevelBorder());
        content.setFont(new Font("Times New Roman", Font.BOLD, 12));
        content.setLineWrap(true);
        content.setWrapStyleWord(true);


        String s = "aaaaa bbb ccc ddd e fff ggg hhhhhhhh iiii jjjj kk l mm nnnnn oooooooooo ppppppppppppppp";
        content.setText(s);
        label = new JLabel("Content");
        panel.setLayout(new MigLayout("",
                "[75!][150!]",
                "[]"));
        panel.add(label);
        panel.add(content);
        guiFrame.add(panel);
        guiFrame.setVisible(true);
        guiFrame.setSize(750, 200);

    }

}

0 个答案:

没有答案