gpt4 book ai didi

java - 将 jtable 居中对齐到 jscrollpane

转载 作者:行者123 更新时间:2023-11-30 11:53:24 25 4
gpt4 key购买 nike

我正在使用 NetBeans。我关闭了 JTable 列的自动调整大小。现在它与滚动 Pane 的左侧对齐。我怎样才能让它居中?

最佳答案

找到解决方案。必须添加一个额外的面板。

public class GUI {

public static void main(String[] args) {
JFrame frame = new JFrame();
frame.setSize(500, 400);
JButton button = new JButton("Click me");
button.setPreferredSize(new Dimension(200, 40));
JPanel panel = new JPanel();
panel.add(button);
JScrollPane scrollableArea = new JScrollPane(panel);
frame.add(scrollableArea);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}

真是一个很棒的、意想不到的解决方案。有时候java真的很奇怪。这是原帖http://www.velocityreviews.com/forums/t600361-jscrollpane.html

关于java - 将 jtable 居中对齐到 jscrollpane,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6298785/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com