private JScrollBar createScrollBar(int row) { JScrollBar scrollBar = new JScrollBar(); scrollBar.setMinimum(0); scrollBar.setVisibleAmount(1); scrollBar.setBlockIncrement(1); scrollBar.setOrientation(JScrollBar.HORIZONTAL); GridBagConstraints scrollBarContraints = new GridBagConstraints(); scrollBarContraints.fill = GridBagConstraints.HORIZONTAL; scrollBarContraints.weightx = 1.0; scrollBarContraints.gridx = 1; scrollBarContraints.gridy = row; super.add(scrollBar, scrollBarContraints); return scrollBar; }
public BallControlUsingThread() { // Group buttons in a panel JPanel panel = new JPanel(); panel.add(jbtSuspend); panel.add(jbtResume); panel.add(jbtAdd); panel.add(jbtSubtract); // Add ball and buttons to the panel ball.setBorder(new javax.swing.border.LineBorder(Color.red)); jsbDelay.setOrientation(JScrollBar.HORIZONTAL); ball.setDelay(jsbDelay.getMaximum()); setLayout(new BorderLayout()); add(jsbDelay, BorderLayout.NORTH); add(ball, BorderLayout.CENTER); add(panel, BorderLayout.SOUTH); // Register listeners jbtSuspend.addActionListener(this); jbtResume.addActionListener(this); jbtAdd.addActionListener(this); jbtSubtract.addActionListener(this); jsbDelay.addAdjustmentListener(this); }