Java: Scrollable JButton bar - Java Response video

Published: 02 November 2014
on channel: Vincent Aliquo
6,608
33

In this video I answer a question about scrolling through an array
of buttons that go out of frame.
SOURCE CODE BELOW!!!

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
*
@author Vincent
*/
public class ButtonScrollBar {

public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
JFrame window = new JFrame("Button Scroll Bar");
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel_1 = new JPanel();
JPanel panel_2 = new JPanel();
panel_1.setBackground(Color.gray);
window.add(BorderLayout.NORTH, panel_1);
final JScrollPane scroll_1 = new JScrollPane(panel_1, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
final JScrollPane scroll_2 = new JScrollPane(panel_2, JScrollPane.VERTICAL_SCROLLBAR_NEVER,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel_1.add(new JButton("Button 1"));
panel_1.add(new JButton("Button 2"));
panel_1.add(new JButton("Button 3"));
panel_1.add(new JButton("Button 4"));
panel_1.add(new JButton("Button 5"));
panel_1.add(new JButton("Button 6"));

panel_2.add(new JButton("Button 1"));
panel_2.add(new JButton("Button 2"));
panel_2.add(new JButton("Button 3"));
panel_2.add(new JButton("Button 4"));
panel_2.add(new JButton("Button 5"));
panel_2.add(new JButton("Button 6"));
GridLayout griddy = new GridLayout(2, 0);
window.setLayout(griddy);
window.add(BorderLayout.NORTH,scroll_1);
window.add(BorderLayout.SOUTH,scroll_2);
window.setSize(300, 190);
window.setVisible(true);
window.setLocationRelativeTo(null);
}
}


On this page of the site you can watch the video online Java: Scrollable JButton bar - Java Response video with a duration of hours minute second in good quality, which was uploaded by the user Vincent Aliquo 02 November 2014, share the link with friends and acquaintances, this video has already been watched 6,608 times on youtube and it was liked by 33 viewers. Enjoy your viewing!