-2
JPanel mEvidenceFilePanel = new JPanel();
mEvidenceFilePanel.setLayout(null);
mEtitleSnoLbl = new JLabel("", JLabel.LEFT);
mEtitleEtypesLbl = new JLabel("", JLabel.LEFT);
mEtitleSnoLbl.setBounds(10, 1, 50, 50);
mEtitleEtypesLbl.setBounds(50, 1, 100, 50);
mEvidenceFilePanel.add(mEtitleSnoLbl);
mEvidenceFilePanel.add(mEtitleEtypesLbl);
hv.mMainFrame.getContentPane().add(mEvidenceFilePanel);

I cant figure it out of adding scrollbar inside the JPanel, not for Frame... anyone know help me...how to add the Scrollbar inside.. Thanks...

MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
Karthick
  • 183
  • 3
  • 14
  • 1
    Don't use `null` layouts. Pixel perfect layouts are an illusion in modern UI design, you have no control over fonts, DPI, rendering pipelines or other factors that will change the way that you components will be rendered on the screen. Swing was designed to work with layout managers to overcome these issues. If you insist on ignoring these features and work against the API design, be prepared for a lot of headaches and never ending hard work... – MadProgrammer May 28 '14 at 05:44
  • 1
    The next question is, why? If you're trying to use it as some kind of gauge, use a [`JSlider`](http://docs.oracle.com/javase/tutorial/uiswing/components/slider.html) it's what it's designed for. If you're trying to make a scrollable area, simply set whatever you want to be scrolled as the `JScrollPane`'s viewport component... – MadProgrammer May 28 '14 at 05:45
  • Thanks for your reply... i got your point. i'm new to swing thats way i tried without layout. i will change the layout.. – Karthick May 28 '14 at 05:51
  • do have a any simple example for that.. – Karthick May 28 '14 at 05:51
  • [Laying Out Components Within a Container](http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html) or [How to Use Sliders](http://docs.oracle.com/javase/tutorial/uiswing/components/slider.html) or [How to Use Scroll Panes](http://docs.oracle.com/javase/tutorial/uiswing/components/scrollpane.html)? – MadProgrammer May 28 '14 at 05:53

1 Answers1

1

First of all it's a very bad idea to make your layouts null. As for the answer to your question try this..

JPanel pn= new JPanel();
pn.setLayout(null); //Do not do this, I'm just using this as an example
JScrollPane scroll = new JScrollPane(panel);
JScrollPane s = new JScrollPane(pn, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
Vinnie
  • 452
  • 5
  • 24