— Scott McNealy, Sun Microsystems Chairman, President and ceo


panel wants to be... The panel’s  FlowLayout



Download 40,57 Mb.
Pdf ko'rish
bet380/555
Sana26.05.2022
Hajmi40,57 Mb.
#609235
1   ...   376   377   378   379   380   381   382   383   ...   555
Bog'liq
Head First Java (Kathy Sierra, Bert Bates) (z-lib.org)

panel
wants to be...
The panel’s 
FlowLayout manager
I need 
to know how big the 
button 
wants to 
controls
controls
panel
panel


410
 
chapter 13

public void go() {


JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setBackground(Color.darkGray); 
JButton button = new JButton(“shock me”);
JButton buttonTwo = new JButton(“bliss”);
panel.add(button);
panel.add(buttonTwo);
frame.getContentPane().add(BorderLayout.EAST, panel);
frame.setSize(250,200);
frame.setVisible(true);
}
What happens if we add TWO buttons 
to the panel?
make TWO buttons
add BOTH to the panel
what we 
wanted:
what we 
got:
We want the buttons 
stacked on top of each 
other
The panel expanded to 
fit both buttons side 
by side. 
notice that the 
‘bliss’ button is 
smaller than 
the ‘shock me’ button... that’s how flow 
layout works. The button gets just what it 
needs (and no more).
Sharpen your pencil
JButton button = new JButton(“shock me”);
JButton buttonTwo = new JButton(“bliss”);
JButton buttonThree = new JButton(“huh?”);
panel.add(button);
panel.add(buttonTwo);
panel.add(buttonThree);
If the code above were modified to the code below, 
what would the GUI look like?
Draw what you 
think the GUI would 
look like if you ran 
the code to the left.
(Then try it!)
flow 
layout


using 
swing
you are here
4
411
BoxLayout to the rescue!
It keeps components 
stacked, even if there’s room 
to put them side by side.
Unlike FlowLayout, BoxLayout can force a 
‘new line’ to make the components wrap to 
the next line, even if there’s room for them 
to fit horizontally.
But now you’ll have to change the panel’s layout manager from the 
default FlowLayout to BoxLayout.
public void go() {
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setBackground(Color.darkGray);

Download 40,57 Mb.

Do'stlaringiz bilan baham:
1   ...   376   377   378   379   380   381   382   383   ...   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