选择列表中的项目,在文本区域中显示文本 [英] Select item in list, show text in text area

查看:179
本文介绍了选择列表中的项目,在文本区域中显示文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究gui的草稿,看看不同的选择。我正在跳使用 JList 根据 item JTextArea 中显示文本被选中。您可以在左侧看到 JList ,在中心看到 JTextArea

I am working on a rough draft of a gui, looking at different options. I was hopping to use a JList to show text in a JTextArea based on what item is selected. You can see the JList on the left and the JTextArea in the center.

或者有更好的方法吗?我已经在使用将用于广泛类别的标签。我看到 CardLayout ,但不太喜欢这个样子。任何提示?

Or is there a better way to do this? I am already using tabs that will be used for a broad category. I saw that the CardLayout, but don't quite like the look. Any tips?

推荐答案

好吧,你可以使用ListSelectionListener相应地设置内容..

Well, you can use a ListSelectionListener to set the content accordingly..

 JList list = new JList(someArrayofData);
 list.addListSelectionListener(new ListSelectionListener(){
      public void valueChanged(ListSelectionEvent e){
            int selectedIndex = list.getSelectedIndex();
            //refresh the content based on the index
            setContent(selectedIndex);
      }
});

很难说哪种gui布局最适合你,而不知道应用程序的用途。

Its hard to say which gui layout will work the best for you without knowing what the application is for.

这篇关于选择列表中的项目,在文本区域中显示文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆