我使用swingx和miglayout扩展,但我遇到了问题。我有以下代码:
public class App {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new MigLayout());
JXPanel keysPanel = new JXPanel();
JXPanel keysPanelContainer = new JXPanel();
JScrollPane scrollPane = new JScrollPane(keysPanelContainer,
ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
JButton nextButton = new JButton("Next");
keysPanel.setLayout(new MigLayout());
keysPanelContainer.setLayout(new MigLayout());
scrollPane.setBorder(BorderFactory.createEmptyBorder());
keysPanelContainer.setScrollableHeightHint(ScrollableSizeHint.PREFERRED_STRETCH);
keysPanelContainer.add(keysPanel, "w 100%, h 100%");
frame.add(scrollPane, "w 100%, h 100%");
frame.add(nextButton, "newLine, right");
frame.setSize(600, 320);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
当我运行此代码时,如果我的keysPanel增加到无穷大,则为高度。我的代码有什么问题?我需要keysPanel高度100%。