
I want to use MenuBar with Scrollbar. I tried it. I dont know how to do it. so please help me. The program should be.... 1.add JScrollPane into the panel. 2.Panel layout should be null. 3.Use menubar 4.Each and every component should inside the panel. I tried it but menu bar is not working in this program. Here is the code......
import javax.swing.*; import java.awt.*; public class menu extends JFrame { MenuBar bar; Menu file,setting,rate,help,crate,prate; public menu() { JFrame frame =new JFrame("Stock Analysis");
bar=new MenuBar(); file=new Menu("File"); setting=new Menu("Setting"); rate=new Menu("Rate"); help=new Menu("Help");
setMenuBar(bar); bar.add(file); bar.add(rate); bar.add(setting); bar.add(help);
JPanel panel=new JPanel(); JButton b1=new JButton("Button1"); JButton b2=new JButton("Button2"); panel.setLayout(null); panel.setPreferredSize(new Dimension(1000, 1500));
b1.setBounds(100,100,150,50); b2.setBounds(100,200,150,50);
panel.add(b1); panel.add(b2);
JScrollPane s = new JScrollPane(panel); frame.add(s); frame.setVisible(true); frame.setSize(500,500); } public static void main(String arg[]) { menu m=new menu(); } }

Hi Friend,
Try the following code:
import java.awt.*;
import javax.swing.*;
public class menu extends JFrame{
private JPanel panel;
public menu()
{
JMenuBar bar = new JMenuBar();
JMenu m = new JMenu("Info");
JMenuItem file = new JMenuItem("File");
JMenuItem setting = new JMenuItem("Setting");
JMenuItem rate = new JMenuItem("Rate");
JMenuItem help = new JMenuItem("Help");
m.add(file);
m.add(setting);
m.add(rate);
m.add(help);
bar.add(m);
this.setJMenuBar(bar);
panel = new JPanel();
JButton b1=new JButton("Button1");
JButton b2=new JButton("Button2");
panel.setLayout(null);
panel.setPreferredSize(new Dimension(1000, 1500));
b1.setBounds(100,100,150,50);
b2.setBounds(100,200,150,50);
panel.add(b1);
panel.add(b2);
JScrollPane s = new JScrollPane(panel);
this.add(s);
this.setSize(500,500);
this.setVisible(true);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[]args){
menu me=new menu();
}
}
Thanks
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.