- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在尝试让这个组件正确对齐时遇到了最令人沮丧的时间。
本次 SSCCE:
public static void main(String[] args) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Windows".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException e) {
e.printStackTrace();
}
JFrame frame = new JFrame();
frame.setLayout(new MigLayout(new LC().fill()));
final JList<String> company_list = new JList<>();
company_list.setListData(new String[] {"Company 1", "Company 2", "Company 3", "Company 4", "Company 5"});
JScrollPane company_list_jsp = new JScrollPane(company_list);
frame.add(company_list_jsp, "dock west, width 150px, growx");
final MainPanel mainPanel = new MainPanel();
frame.add(mainPanel, "grow");
company_list.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
mainPanel.setCompanyName(company_list.getSelectedValue());
}
});
frame.setSize(800,600);
frame.setLocationByPlatform(true);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
static class MainPanel extends JPanel {
JLabel company_name_label;
JList company_contacts_list;
JList customers_list;
JTextArea company_notes_textArea;
public MainPanel() {
setLayout(new MigLayout(new LC().fillX()));
company_name_label = new JLabel();
company_name_label.setText("Company");
company_name_label.setFont(new Font("Tahoma", Font.PLAIN, 24));
add(company_name_label, "cell 0 0 1 3, span");
JPanel panel1 = new JPanel(new MigLayout(new LC().fill().insetsAll("0")));
JLabel label1 = new JLabel("Company Contacts");
panel1.add(label1, "cell 0 1 1 1, sg 1");
JLabel label2 = new JLabel("Customers");
panel1.add(label2, "cell 1 1 1 1, sg 1");
JLabel label3 = new JLabel("Company Notes");
panel1.add(label3, "cell 2 1 1 1, sg 1");
company_contacts_list = new JList();
JScrollPane company_contacts_list_jsp = new JScrollPane(company_contacts_list);
panel1.add(company_contacts_list_jsp, "cell 0 2 1 1, height 150px, growx, sg 2");
customers_list = new JList();
JScrollPane customers_list_jsp = new JScrollPane(customers_list);
panel1.add(customers_list_jsp, "cell 1 2 1 1, height 150px, growx, sg 2");
company_notes_textArea = new JTextArea();
company_notes_textArea.setColumns(20);
company_notes_textArea.setRows(5);
company_notes_textArea.setWrapStyleWord(true);
company_notes_textArea.setLineWrap(true);
JScrollPane company_notes_textArea_jsp = new JScrollPane(company_notes_textArea);
panel1.add(company_notes_textArea_jsp, "cell 2 2 1 1, height 150px, growx, sg 2");
add(panel1, "span, grow");
}
public void setCompanyName(String companyName) {
company_name_label.setText(companyName);
}
}
产生这个:
JTextArea
未与其他两个组件正确对齐。
注意:如果您注释掉 Windows
LookAndFeel
代码,它就会起作用:
但是更改我的应用程序的 LAF 不是一个选项。
有谁知道为什么会这样吗?
最佳答案
您可以通过将 MigLayout
的 rowConstraints
参数设置为 “[][][fill]”
来指定整个第三行垂直填充。例如:
JPanel panel1 = new JPanel(new MigLayout("fill,insets 0", "[][][]", "[][][fill]"));
关于java - 为什么这个组件不对齐(MigLayout),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24415275/
右侧面板包含所有按钮,我想与底部对齐。 JPanel easternDock = new JPanel(new MigLayout("", "")); easternDock.add(button1,
任何人都可以建议我在哪里可以获得 Miglayout 站点中回调停靠演示应用程序的源代码。这样的教程也可以。谢谢。 最佳答案 有很多断开的链接指向以前的源代码所在的位置。现在演示与 MiG Layou
这里有点不对劲。我试图让最右边的按钮(在下面的示例中标记为“帮助”)与 JFrame 右对齐,并将巨大的按钮的宽度与 JFrame 绑定(bind),但每个按钮至少为 180px。我得到了巨大的按钮约
我正在尝试使结构整齐地居中,但标签和字段之间没有相等的空间,我想我可能不得不使用两列而不是合并它们。 这就是我想要实现的目标: +-----------------------------------
我是新来的,所以对我放宽点。我已经研究了所有关于 miglayout 的文档(顺便说一句,这非常好),但我似乎无法正确显示我想要的网格。 我需要 MigLayout() 参数来设置网格: 2 行,因为
我正在使用 Miglayout 为我的一个面板创建类似表格的布局。我需要所有面板的固定宽度为 200 像素。当我在面板中添加组件时,一切正常,但是当我尝试插入一个具有长文本的按钮(因此需要超过 200
我对 MigLayout 有一些奇怪的行为。我有一个 SSCCE 反射(reflect)了我的问题。基本上,顶部两个面板之间有一个间隙(该间隙属于左侧单元格)。其他一切都如我所愿。仅当 JFrame
我拥有的代码: JPANEL JPanel dadosdaparte = new JPanel(new MigLayout("fillx")); 添加到JPANEL dadosdapa
我有这个面板,它使用 MigLayout 为我的内容创建单元格。这是代码部分: / ====Layout==== setLayout(new MigLayout("hidemode 3
所以我有一个无法解决的问题,我希望我的 GUI 应用程序分为 3 个 JPanel(左、中、右)。我希望左面板和右面板具有固定尺寸,并且中心是流动的。这意味着侧面板仅在 JFrame 展开时垂直展开,
这个问题不太可能对任何 future 的访客有帮助;它只与一个较小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于全世界的互联网受众。如需帮助使此问题更广泛适用,visit the
我有一个扩展类 JComponent 的类,我在其中创建一个带有数字的组件。我想使用 MigLayout 在框架中添加此类对象,但组件没有添加,我只能看到空框架。感谢您的帮助。 用图形创建组件的类 p
我有一个问题想问那些熟悉 MigLayout 或基本 Swing 使用方法的人。 我正在尝试为游戏创建服务器浏览器。 布局最终将如下所示。另外,老实说我不知道该使用什么布局管理器。 +------
我想要发生的是东部和南部的 jetty 移动到窗口的边缘,中间的两个单元填充所有其他空间。相反, jetty 是静态的,拉伸(stretch)窗口只会产生空白空间。 setLayout(new
我正在编写一个应用程序,我希望在其中具有此布局 45% 35% 10% ---------------------
我刚刚开始使用 MigLayout。 我阅读了一些文档,包括 MigLayout 的快速入门指南,并搜索了一些 SO 问题,但没有找到答案。我确信这是显而易见的,但就像我说的,这是我第一次使用这个布局
代码如下: ScreenHeight = Toolkit.getDefaultToolkit().getScreenSize().height, ScreenWidth = Toolkit.getDe
我正在尝试利用 MigLayout 布局管理器创建一个 GUI,允许用户将项目从一个列表移动到另一个列表。我需要箭头靠在一起(垂直)。我遇到的问题是顶部箭头位于单元格的顶部,但我未能成功将其向下移动到
我正在尝试将一个 JTabbedPane 添加到一个面板,上面有用于控件的按钮。我正在使用 MigLayout。 但是,我无法让 JTabbedPane 在按钮不需要时也填充的情况下填充。 参加以下
我目前面临的问题是,有 2 行,MigLayout 似乎强制两个第一个单元格具有相同的宽度,而我希望它们独立工作(注意“Filter”标签太长) ): 除了将两行定义为两个不同的 MigLayout
我是一名优秀的程序员,十分优秀!