Home / ພື້ນຖານ Desktop app / GUI_Component / JScrollBar
Java Scroll Bar (JScrollBar) - Swing Example ສຳລັບ Scroll Bar ຫຼື JScrollBar (javax.swing.JScrollBar) ຈັດຢູ່ໃນກຸ່ມຂອງ Container ໃຊ້ສຳລັບການສ້າງ Scroll Bar ໃຫ້ກັບ JFrame ໂດຍສາມາດສ້າງ Scroll Bar ໄດ້ທັງໃນແນວຕັ້ງ ແລະ ແນວນອນ
public class MyForm extends JFrame {
public MyForm() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 362, 249);
setTitle("Kittisay Java");
JLabel label = new JLabel();
JScrollBar hbar = new JScrollBar(JScrollBar.HORIZONTAL, 30, 20, 0, 500);
JScrollBar vbar = new JScrollBar(JScrollBar.VERTICAL, 30, 40, 0, 500);
class MyAdjustmentListener implements AdjustmentListener {
@Override
public void adjustmentValueChanged(AdjustmentEvent e) {
label.setText("Position = " + e.getValue());
repaint();
}
}
hbar.addAdjustmentListener(new MyAdjustmentListener());
vbar.addAdjustmentListener(new MyAdjustmentListener());
add(label);
add(hbar, BorderLayout.SOUTH);
add(vbar, BorderLayout.EAST);
}
public static void main(String[] args) {
MyForm frm = new MyForm();
frm.setVisible(true);
}