Individual loyiha Mavzu: “Java Swing asosida sodda web browser tarmoq dasturiy ta’minotini yaratish” Topshirdi: Raxmonov Javohir


SimpleWindow(){super("Пробное окно")


Download 184.05 Kb.
bet10/14
Sana18.06.2023
Hajmi184.05 Kb.
#1571768
1   ...   6   7   8   9   10   11   12   13   14
SimpleWindow(){super("Пробное окно");
setDefaultCloseOperation(EXIT_ON_CLOSE);
Box box = Box.createVerticalBox();
box.add(new JButton("Кнопка"));
box.add(Box.createVerticalStrut(10));
box.add(new JButton("+"));
box.add(Box.createVerticalGlue());
box.add(new JButton("-"));
box.add(Box.createVerticalStrut(10));
box.add(new JButton("Кнопка с длинной надписью"));
setContentPane(box);setSize(250, 100);}


Elementlarni tekislash xususiyatlari
Vertikal panel misolida barcha tugmalar chap tomonga tekislangan. Ushbu gorizontal hizalama sukut bo'yicha qabul qilinadi.


Biroq, dastur oynasini ishlab chiqishda ba'zi elementlarning, masalan, o'ng chekka yoki markaz bo'ylab boshqacha hizalanishi kerak bo'lishi mumkin. Har qanday vizual komponentning (masalan, tugma yoki panel) hizalanishini o'rnatish uchun setAlignmentX(float alignment)gorizontal hizalama va setalignmenty(float alignment) — vertikal hizalama usullari qo'llaniladi. Parametr sifatida JComponent sinfida belgilangan doimiylardan foydalanish eng oson. Gorizontal tekislash uchun left_alignment (chap tomonda), RIGHT_ALIGNMENT (o'ng tomonda) va CENTER_ALIGNMENT (markazda) konstantalari ishlatiladi. Vertikal tekislash uchun-BOTTOM_ALIGNMENT (pastki chetida), TOP_ALIGNMENT (yuqori chetida) va CENTER_ALIGNMENT (markazda).

6-rasm


Biroq, hizalama kutilganidan biroz boshqacha ishlaydi. Buni aniqlash uchun uchinchi tugmani o'ng chetiga qo'yib, oldingi misolni o'zgartiring. Buning uchun qatorni almashtiring:


box.add(new JButton("-"));
Qolgan uchtasi uchun:
JButton rightButton = new JButton("-");
rightButton.setAlignmentX(JComponent.RIGHT_ALIGNMENT);

Download 184.05 Kb.

Do'stlaringiz bilan baham:
1   ...   6   7   8   9   10   11   12   13   14




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