Scrollpane中的jList,查找并显示selectedIndex的值

发布于 2024-08-27 09:31:15 字数 329 浏览 7 评论 0原文

我在滚动窗格中有一个 JList。如果您单击列表并上下移动箭头键,它会像您预期的那样工作,您可以移动选择索引并显示周围就好了。

现在,我想做的基本上是有一个文本框,我在文本框中输入“漫画”之类的内容,并希望它查找该值的索引。这工作得很好。

问题出在列表框的值低于或高于可视区域时。如果是,则选定的索引将进行查找,但不会更改可滚动区域的位置。但是,如果我按向上或向下箭头和 requestFocus() 到列表,然后上下移动,它会寻找正确的可视区域。

我缺少什么才能在不改变焦点的情况下实现这一目标。我希望能够在列表中输入我想要的所有内容并让它显示所选择的内容。我觉得我在这里遗漏了一些明显的东西。

I have a JList inside a Scrollpane. If you click on the list and move the arrow keys up and down it works like you expect, you can move your selection index and display around just fine.

Now, what I want to do is basically have a text box and i'm typing in the text box like "comic" and want it to seek to the index of that value. This WORKS just fine.

Where the problem is when the value of the list box is below, or above the viewable area. When it is, the selected index seeks, but does not change the position of the scrollable region. However, if I press the up or down arrows and requestFocus() to the list, and move up and down it seeks to the right viewable area.

What am I missing to make this happen WITHOUT changing focus. I want to be able to just type in the list all I want and have it show me what is selected. I feel i'm missing something obvious here.

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

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

发布评论

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

评论(1

走走停停 2024-09-03 09:31:15

如果我理解这个问题,那么您应该能够使用:

list.setSelectedIndex(...);
list.ensureIndexIsVisible(...);

如果这没有帮助,那么发布您的 SSCCE 来演示问题。

If I understand the question then you should be able to use:

list.setSelectedIndex(...);
list.ensureIndexIsVisible(...);

If that doesn't help then post your SSCCE demonstrating the problem.

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