【问题标题】:Java Swing - setting margins on TextArea with Line BorderJava Swing - 在带有线条边框的 TextArea 上设置边距
【发布时间】:2012-05-03 17:20:33
【问题描述】:

正如标题所说,我只是想在带有 LineBorder 集的 TextArea 上设置边距(提供一些填充)。不设置边框, .setMargins 工作正常。这是具体的代码块。

aboutArea = new JTextArea("program info etc.....");

Border border = BorderFactory.createLineBorder(Color.BLACK);

aboutArea.setSize(400, 200);
aboutArea.setBorder(border);
aboutArea.setEditable(false);
aboutArea.setFont(new Font("Verdana", Font.BOLD, 12));

add(aboutArea);

这些我都试过了:

aboutArea.setMargins(10,10,10,10);
.getBorders(aboutArea).set(10,10,10,10);
UIManager.put("aboutArea.margin", new Insets(10, 10, 10, 10));

但在我应用边框后,边距没有任何影响,填充始终为 0。任何想法如何在带有边框的 textArea 上设置填充?

【问题讨论】:

  • JTextArea 边距的键是 "TextArea.margin"

标签: java swing textarea margins insets


【解决方案1】:

如果你尝试添加 CompoundBorder 会怎样,这会不会,这会给你几乎相同的东西

JTextArea tarea = new JTextArea("program info etc.");
Border border = BorderFactory.createLineBorder(Color.BLACK);
tarea.setBorder(BorderFactory.createCompoundBorder(border, 
            BorderFactory.createEmptyBorder(10, 10, 10, 10)));

【讨论】:

  • @Daniel 一切都取决于 JTextArea 是否放置在 JScrollPane +1 中
  • +1,但是(歪头)至于截图,为什么不把GUI放在一个纯白色的BG前面呢?例如。 Ctrl-t 当我在 FF 中并获得超过一半屏幕大小的空白区域时。如需更多提示,请参阅How do I create screenshots?
  • @mKorbel 你提醒我,我通常将组件添加到JPanel,然后将边框设置为面板。它完美地适用于滚动窗格、按钮、标签..
  • 我尝试将打开的窗口放在 stackoverflow 页面的任何空白处,有时我忘记从顶部窗口下方删除我的控制台,这似乎是我的图像有什么问题?
  • @nIcE cOw hehehe 有时候玩“Fail to React”会更好
猜你喜欢
  • 2012-04-21
  • 1970-01-01
  • 2014-07-16
  • 2011-10-25
  • 2017-06-24
  • 2012-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多