我正在尝试在 JToolBar 中对齐 JToggleButtons。我希望按钮垂直向左对齐。我的代码如下:
JToolBar toolbar = new JToolBar();
toolbar.setLayout(new FlowLayout());
toolbar.setAlignmentX(FlowLayout.LEFT);
toolbar.add(new JToggleButton("Test"));
toolbar.add(new JToggleButton("Test2"));
toolbar.add(new JToggleButton("Test3"));
toolbar.add(new JToggleButton("Test with a long name"));
此外,当停靠在左侧时,它看起来像这样。理想情况下,我希望按钮垂直堆叠(并且仍然保持与左侧对齐)。有小费吗?