将 jtable 居中对齐到 jscrollpane 中

发布于 2024-11-14 21:41:46 字数 80 浏览 1 评论 0 原文

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

I am using NetBeans. I turned off the auto-resize of JTable columns. Now it is aligned to the left side of scroll pane. How can I make it centered?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

怂人 2024-11-21 21:41:47

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

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

Found the solution. Have to add an extra panel.

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);
    }
}

Really a great and unexpected solution. Sometime java really acts weird. Here is the orginal post http://www.velocityreviews.com/forums/t600361-jscrollpane.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文