-
-
Save uncoded-ro/e826589c146bd80b673af8e409c0b78d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ro.virtualcampus.gui; | |
import java.awt.*; | |
import javax.swing.*; | |
import javax.swing.event.*; | |
import java.util.List; | |
public class ListPanel extends JPanel implements ListSelectionListener { | |
private static final long serialVersionUID = 1L; | |
private JList list; | |
private JLabel text1, text2; | |
public ListPanel() { | |
setLayout(new GridLayout(3, 1)); | |
text1 = new JLabel("Selecteaza echipa/echipele favorite !"); | |
DefaultListModel listModel = new DefaultListModel(); | |
listModel.addElement("Universitatea Craiova"); | |
listModel.addElement("Poli Timisoara"); | |
listModel.addElement("Dinamo Bucuresti"); | |
list = new JList(listModel); | |
list.setSelectedIndex(1); | |
list.setVisibleRowCount(2); | |
text2 = new JLabel(""); | |
JScrollPane panou = new JScrollPane(); | |
panou.add(list); | |
panou.setViewportView(list); | |
add(text1); | |
add(panou); | |
add(text2); | |
list.addListSelectionListener(this); | |
} | |
public void valueChanged(ListSelectionEvent e) { | |
List choice = list.getSelectedValuesList(); | |
text2.setText(choice.toString()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment