【问题标题】:How to show JLabel ellipsis in MigLayout?如何在 MigLayout 中显示 JLabel 省略号?
【发布时间】:2013-03-15 05:44:30
【问题描述】:

使用默认布局管理器,JLabel 在调整框架大小时显示其省略号。

如图所示:

public static void main(String[] args) {
    final JFrame jFrame = new JFrame("JLabel, show me your ellipsis!");

    jFrame.getContentPane().add(new JLabel("Sure darling! Shrink me and I'll show you"));

    jFrame.pack();
    jFrame.setVisible(true);
}

但是,MigLayout 不会显示此类行为!

public static void main(String[] args) {
    final JFrame jFrame = new JFrame("JLabel, show me your ellipsis!");

    jFrame.getContentPane().setLayout(new MigLayout());
    jFrame.getContentPane().add(new JLabel("Nope! I just do not know you well enough!"));

    jFrame.pack();
    jFrame.setVisible(true);
}

我尝试了所有我能想到的布局/组件约束。有谁知道这种事情在 Mig 中是否可行?

【问题讨论】:

  • +1 一个有趣的例子,你的代码示例让我哈哈大笑。

标签: java swing layout miglayout


【解决方案1】:

JLabel 的最小尺寸与它的首选尺寸大致相同(或者确切地说,不记得了)。 MigLayout 仅将组件缩小到其最小值。所以你必须添加一个允许尺寸小于其 minSize 的组件约束:

content.add(label, "wmin 10lp");

【讨论】:

    猜你喜欢
    • 2015-09-17
    • 1970-01-01
    • 1970-01-01
    • 2017-01-09
    • 1970-01-01
    • 2019-04-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多