swing:lists
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
swing:lists [2018/03/27 15:47] – gthanos | swing:lists [Unknown date] (current) – external edit (Unknown date) 127.0.0.1 | ||
---|---|---|---|
Line 19: | Line 19: | ||
<WRAP tip 80% center round> | <WRAP tip 80% center round> | ||
- | Η κλάση JList δεν έχει την δυνατότητα scrolling. Αν θέλετε να προσθέσετε scrolling θα πρέπει να το κάνετε δημιουργώντας ένα αντικείμενο του [[http:// | + | Η κλάση JList δεν έχει την δυνατότητα scrolling. Αν θέλετε να προσθέσετε scrolling θα πρέπει να το κάνετε δημιουργώντας ένα αντικείμενο του [[http:// |
</ | </ | ||
==== Listening Interface ==== | ==== Listening Interface ==== | ||
- | Αντικείμενα του τύπου JList μπορούν να κάνουν register Listening objects του τύπου [[http:// | + | Αντικείμενα του τύπου |
<code java> | <code java> | ||
void valueChanged(ListSelectionEvent e) | void valueChanged(ListSelectionEvent e) | ||
Line 35: | Line 35: | ||
<code java ListDemo.java> | <code java ListDemo.java> | ||
- | |||
import java.awt.*; | import java.awt.*; | ||
import java.awt.event.*; | import java.awt.event.*; | ||
Line 42: | Line 41: | ||
/* ListDemo.java requires no other files. */ | /* ListDemo.java requires no other files. */ | ||
+ | @SuppressWarnings(" | ||
public class ListDemo extends JPanel | public class ListDemo extends JPanel | ||
implements ListSelectionListener { | implements ListSelectionListener { | ||
- | private JList list; | + | private JList< |
- | private DefaultListModel listModel; | + | private DefaultListModel< |
private static final String hireString = " | private static final String hireString = " | ||
Line 55: | Line 55: | ||
super(new BorderLayout()); | super(new BorderLayout()); | ||
- | listModel = new DefaultListModel(); | + | listModel = new DefaultListModel< |
listModel.addElement(" | listModel.addElement(" | ||
listModel.addElement(" | listModel.addElement(" | ||
Line 61: | Line 61: | ||
//Create the list and put it in a scroll pane. | //Create the list and put it in a scroll pane. | ||
- | list = new JList(listModel); | + | list = new JList<>(listModel); |
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); | ||
list.setSelectedIndex(0); | list.setSelectedIndex(0); | ||
Line 196: | Line 196: | ||
} | } | ||
+ | /* if textField is empty returns true */ | ||
private boolean handleEmptyTextField(DocumentEvent e) { | private boolean handleEmptyTextField(DocumentEvent e) { | ||
if (e.getDocument().getLength() <= 0) { | if (e.getDocument().getLength() <= 0) { | ||
Line 253: | Line 254: | ||
</ | </ | ||
+ | | Προηγούμενο: |
swing/lists.1522165678.txt.gz · Last modified: 2018/03/27 14:47 (external edit)