我正在尝试将 a 包含JPanel
在 aJScrollPane
中。当我设置 的首选大小时JScrollPane
,它会自动将面板居中放置在其中。我想让它左对齐。我注意到实际的内部面板是 的大小JScrollPanel
,但由于某种原因,内容现在居中。如果我使用JScrollPane
andsetMinimum
而setMaximum
不是setPreferredSize
.
编辑:从评论迁移的代码:
JPanel myStandardPanel = new JPanel();
myStandardPanel.setMinimumSize(new Dimension(width, height));
myStandardPanel.setMaximumSize(new Dimension(width, height));
myStandardPanel.setLayout(new BorderLayout());
JPanel alignHorizontalPanel = new JPanel();
alignHorizontalPanel.setMinimumSize(new Dimension(width, height));
alignHorizontalPanel.setMaximumSize(new Dimension(width, height));
alignHorizontalPanel.setLayout(new BorderLayout());
JScrollPane jscp = new JScrollPane(newPanel,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jscp.setPreferredSize(new Dimension(width - 100, height - 100));
newPanel.setMinimumSize(new Dimension(width, height));
newPanel.setMaximumSize(new Dimension(width, height));
mainPanel.add(myStandardPanel, panelIdentifier);