删除AWT中的容器(ScrollPane)边框

发布于 2024-12-10 11:22:16 字数 290 浏览 0 评论 0原文

我正在寻找一种解决方案来删除 AWT ScrollPane 中的默认边框。

在 JScrollPane 中它相当简单..

paneScrollPane.setBorder(BorderFactory.createEmptyBorder());

或者

paneScrollPane.setBorder(null);

只是想知道 ScrollPane 是否可以达到相同的效果

I was looking for a solution to remove default border in AWT ScrollPane.

In JScrollPane its rather simple..

paneScrollPane.setBorder(BorderFactory.createEmptyBorder());

or

paneScrollPane.setBorder(null);

Just wanted to know can we achieve the same effect in case of ScrollPane

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

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

发布评论

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

评论(3

高速公鹿 2024-12-17 11:22:16

这可能是不可能的。 AWT 的主要缺点之一是您无法实际绘制或自定义 AWT 组件的视图。

我可能提出的唯一建议是,您可以尝试在 ScrollPanel 周围创建在边框上绘制的画布。

This probably is not possible. One of the main drawbacks of AWT was that you can't actually draw over or customize the view of your AWT component.

The only recommendation I might make would be that you could try creating Canvases around your ScrollPanel that draw over the border.

墨落画卷 2024-12-17 11:22:16

您可以使用此方法:

JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setViewportBorder(null);

我从类 javax.swing.plaf.synth.SynthScrollPaneUI 获取了以下信息:

protected void paint(SynthContext context, Graphics g) {
    Border vpBorder = scrollpane.getViewportBorder();
    if (vpBorder != null) {
        Rectangle r = scrollpane.getViewportBorderBounds();
        vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height);
    }
}

You could use this method:

JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setViewportBorder(null);

I got this information from class javax.swing.plaf.synth.SynthScrollPaneUI:

protected void paint(SynthContext context, Graphics g) {
    Border vpBorder = scrollpane.getViewportBorder();
    if (vpBorder != null) {
        Rectangle r = scrollpane.getViewportBorderBounds();
        vpBorder.paintBorder(scrollpane, g, r.x, r.y, r.width, r.height);
    }
}
煮茶煮酒煮时光 2024-12-17 11:22:16

这是不可能的,因为 AWT 实现了外观和感觉,并且强烈基于来自本机操作系统(主题)的方法,Border 仅针对 Swing JComponents 实现,

that not possible because AWT implements Look and Feel and is strongly based on methods that came from Native OS (Themes), Border are implemented just for Swing JComponents,

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