【问题标题】:How to add margin of text in the JTextArea?如何在 JTextArea 中添加文本边距?
【发布时间】:2013-05-02 04:27:11
【问题描述】:

如何在 JTextArea 内为文本添加右侧和顶部的边距,例如 5 个像素。

这是图片:Click Here

public class SubTextField extends JTextArea{

public SubTextField()
{ 
    setLineWrap(true);
    setWrapStyleWord(true);
    setPreferredSize(new Dimension(0,50));
    Border b = BorderFactory.createMatteBorder(1, 1, 1, 1, Color.black);
    setBorder(b);
    setFont(new Font("Arial",Font.PLAIN,16));
    actionButtons();
}
}

【问题讨论】:

  • 不要使用setPreferredSize(new Dimension(0,50)); 使用setColumnssetRows,因为它们会更好地处理字体大小的变化...

标签: java swing jtextarea


【解决方案1】:

setMargin(new Insets(5,0,0,5)); 将在顶部和右侧创建 5 个像素的边距。

Insets对象的参数分别是top、left、bottom和right)。

【讨论】:

    【解决方案2】:

    如果您使用的是窗口生成器,那么您可以使用布局助手支持并设置插图和许多其他功能,例如轻松增长、填充。

    【讨论】:

      猜你喜欢
      • 2013-01-22
      • 2022-10-05
      • 1970-01-01
      • 2013-04-20
      • 2019-04-30
      • 1970-01-01
      • 1970-01-01
      • 2015-09-04
      • 1970-01-01
      相关资源
      最近更新 更多