Hye guys...im trying to create ScrollBar Horizontal on whole frame, i keep trying and do some research but still fail...Please help me...What should i add. This is the code.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class listOfMovies extends JFrame implements ActionListener {
private JButton jbtBatman, jbtAngels, jbtFaster, jbtDueDate, jbtHuman, jbtFour, jbtWarrior, jbtWater;
private JLabel jlbWelcome, jlbBatman, jlbAngels, jlbFaster, jlbDueDate, jlbHuman, jlbFour, jlbWarrior, jlbWater;
private JPanel panel = new JPanel ();
// private JScrollPane scroll = new JScrollPane (panel, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneContants.HORIZONTAL_SCROLLBAR_NEVER);
// private container con;
Font f = new Font("Times",Font.BOLD,20);
public listOfMovies () {
setLayout(null);
// con.add(scroll);
// initialize the label
jlbWelcome = new JLabel ("Movies");
add(jlbWelcome);
jlbWelcome.setBounds(130,10,500,100);
jlbWelcome.setHorizontalAlignment(jlbWelcome.CENTER );
jlbWelcome.setFont(f);
// initialize the button
jbtBatman = new JButton ();
jbtAngels = new JButton ();
jbtFaster = new JButton ();
jbtDueDate = new JButton ();
jbtHuman = new JButton ();
jbtFour = new JButton ();
jbtWarrior = new JButton ();
jbtWater = new JButton ();
// set icon for button
jbtBatman.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\1.jpg")); // NOI18N
jbtAngels.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\1.jpg"));
jbtFaster.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\1.jpg"));
jbtDueDate.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\1.jpg"));
jbtHuman.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\1.jpg"));
jbtFour.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\1.jpg"));
jbtWarrior.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\1.jpg"));
jbtWater.setIcon(new ImageIcon("C:\\Users\\User\\Desktop\\OOP project\\img\\icon\\1.jpg"));
// add all button in the frame
add(jbtBatman);
add(jbtAngels);
add(jbtFaster);
add(jbtDueDate);
add(jbtHuman);
add(jbtFour);
add(jbtWarrior);
add(jbtWater);
// set positions for buttons
jbtBatman.setBounds(67, 100, 180, 288);
jbtAngels.setBounds(290, 100, 180, 288);
jbtFaster.setBounds(508, 100, 180, 288);
jbtDueDate.setBounds(67, 450, 180, 288);
jbtHuman.setBounds(290, 450, 180, 288);
jbtFour.setBounds(508, 450, 180, 288);
jbtWarrior.setBounds(67, 100, 180, 288);
jbtWater.setBounds(290, 100, 180, 288);
// register listener
jbtBatman.addActionListener(this);
jbtAngels.addActionListener(this);
jbtFaster.addActionListener(this);
jbtDueDate.addActionListener(this);
jbtHuman.addActionListener(this);
jbtFour.addActionListener(this);
jbtWarrior.addActionListener(this);
jbtWater.addActionListener(this);
// initialize all labels
jlbBatman = new JLabel ("Batman : The Dark Knight");
jlbAngels = new JLabel ("Angels and Demons");
jlbFaster = new JLabel ("Faster");
jlbDueDate = new JLabel ("Due Date");
jlbHuman = new JLabel ("Human Target");
jlbWarrior = new JLabel ("Warrior Way");
jlbFour = new JLabel ("I am Number Four");
jlbWater = new JLabel ("Water");
// add labels in the frame
add(jlbBatman);
add(jlbAngels);
add(jlbFaster);
add(jlbDueDate);
add(jlbHuman);
add(jlbWarrior);
add(jlbFour);
add(jlbWater);
// set positions for the labels
jlbBatman.setBounds(90, 393, 148, 18);
jlbAngels.setBounds(331, 393, 126, 18);
jlbFaster.setBounds(584, 393, 126, 18);
jlbDueDate.setBounds(90, 700, 126, 18);
jlbHuman.setBounds(331, 700, 126, 18);
jlbWarrior.setBounds(584, 700, 126, 18);
jlbFour.setBounds(331, 393, 126, 18);
jlbWater.setBounds(584, 393, 126, 18);
}
public void actionPerformed(ActionEvent e) {
if ((e.getSource() == jbtBatman)) {
bookBatman frame = new bookBatman ();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Book Batman : The Dark Knight"); //set title of thewindow
frame.setSize(800,600); //size of the window
frame.setVisible(true); //visible the window
frame.setLocationRelativeTo (null); //center the window
}
if((e.getSource() == jbtAngels)) {
bookAngels frame=new bookAngels ();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Booking Movie"); //set title of thewindow
frame.setSize(800,600); //size of the window
frame.setVisible(true); //visible the window
frame.setLocationRelativeTo (null); //center the window
}
if((e.getSource() == jbtFaster)) {
bookFaster frame=new bookFaster ();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("Booking Movie"); //set title of thewindow
frame.setSize(800,600); //size of the window
frame.setVisible(true); //visible the window
frame.setLocationRelativeTo (null); //center the window
}
}
public static void main (String [] args) {
/* listOfMovies frame=new listOfMovies ();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setTitle("List of Movies"); //set title of thewindow
frame.setSize(800,600); //size of the window
frame.setVisible(true); //visible the window
frame.setLocationRelativeTo (null); //center the window
JPanel panel = new JPanel ();
JScrollPane spane = new JScrollPane(frame);
panel.add(frame); */
listOfMovies frame = new listOfMovies ();
JPanel panel = new JPanel();
JScrollPane scrollBar = new JScrollPane(panel,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//JFrame frame = new JFrame("AddScrollBarToJFrame");
frame.add(scrollBar);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(800,600);
frame.setVisible(true);
}
}