简体   繁体   English

如何在 GUI 应用程序中超出滚动窗格之外的滚动条

[英]How to exceed the scroll bar beyond the scroll pane in a GUI application

I am designing a online marketing page on GUI(user interface).我正在设计 GUI(用户界面)上的在线营销页面。 I have added a scroll pane in my main JFrame.我在主 JFrame 中添加了一个滚动窗格。 The scroll pane starts from 'vertical position = 20' and so does the scroll bar during run time.滚动窗格从“垂直 position = 20”开始,运行时滚动条也是如此。 I want the scroll bar to start from 'vertical position = 0' instead of 20, with the scroll pane still remaining at 'verticle position = 20'我希望滚动条从“垂直 position = 0”而不是 20 开始,滚动窗格仍保留在“垂直 position = 20”

I've tried changing the maximum and minimum size in the properties, but it doesn't work.我尝试更改属性中的最大和最小大小,但它不起作用。

A simple example would help in understanding your issue.一个简单的例子将有助于理解您的问题。 In the meantime, try to use the following method in JComponent.同时,尝试在 JComponent 中使用以下方法。 This works with the component's viewport ancestor, if it has one, and moves the viewport so the given rectangle area is visible or at least its origin.这适用于组件的视口祖先(如果有的话),并移动视口以使给定的矩形区域可见或至少可见其原点。 In your case, you could add the component to view to the scrollPane and then call component.scrollRectToVisible(startRect) to ensure the starting position is correct.在您的情况下,您可以将要查看的组件添加到 scrollPane,然后调用component.scrollRectToVisible(startRect)以确保起始 position 是正确的。

public void scrollRectToVisible(Rectangle rect)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM