— Scott McNealy, Sun Microsystems Chairman, President and ceo



Download 40,57 Mb.
Pdf ko'rish
bet387/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   383   384   385   386   387   388   389   390   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

swing
you are here
4
417
JList
Constructor
String [] listEntries = {“alpha”, “beta”, “gamma”, “delta”, 
 
 
 
 
“epsilon”, “zeta”, “eta”, “theta “};
list = new JList(listEntries);
How to use it
Make it have a vertical scrollbar
JScrollPane scroller = new JScrollPane(list);
scroller.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
scroller.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
panel.add(scroller);
1
Restrict the user to selecting only ONE thing at a time
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
3
Register for list selection events
list.addListSelectionListener(this);
4
Handle events (find out which thing in the list was selected)
public void valueChanged(ListSelectionEvent lse) {
 
if( !lse.getValueIsAdjusting()) {
String selection = (String) list.getSelectedValue();
 
System.out.println(selection);
 
}
}
5
Set the number of lines to show before scrolling
list.setVisibleRowCount(4);
2
This is just like with 
JTextArea -- you 
make a 
JScrollPane (and give it the list), then add the 
scroll pane (NOT the list) to the panel.
You’ll get the event TWICE if you don’t 
put in this if test.
getSelectedValue() actually 
returns an Object. A list isn’t 
limited to only String objects.
JList constructor takes an array of any object 
type. They don’t have to be Strings, but a 
String representation will appear in the list.
there are no
Dumb Questions



Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   383   384   385   386   387   388   389   390   ...   555




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©hozir.org 2024
ma'muriyatiga murojaat qiling

kiriting | ro'yxatdan o'tish
    Bosh sahifa
юртда тантана
Боғда битган
Бугун юртда
Эшитганлар жилманглар
Эшитмадим деманглар
битган бодомлар
Yangiariq tumani
qitish marakazi
Raqamli texnologiyalar
ilishida muhokamadan
tasdiqqa tavsiya
tavsiya etilgan
iqtisodiyot kafedrasi
steiermarkischen landesregierung
asarlaringizni yuboring
o'zingizning asarlaringizni
Iltimos faqat
faqat o'zingizning
steierm rkischen
landesregierung fachabteilung
rkischen landesregierung
hamshira loyihasi
loyihasi mavsum
faolyatining oqibatlari
asosiy adabiyotlar
fakulteti ahborot
ahborot havfsizligi
havfsizligi kafedrasi
fanidan bo’yicha
fakulteti iqtisodiyot
boshqaruv fakulteti
chiqarishda boshqaruv
ishlab chiqarishda
iqtisodiyot fakultet
multiservis tarmoqlari
fanidan asosiy
Uzbek fanidan
mavzulari potok
asosidagi multiservis
'aliyyil a'ziym
billahil 'aliyyil
illaa billahil
quvvata illaa
falah' deganida
Kompyuter savodxonligi
bo’yicha mustaqil
'alal falah'
Hayya 'alal
'alas soloh
Hayya 'alas
mavsum boyicha


yuklab olish