Results 1 to 7 of 7
  1. #1
    Mani_4 is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default problem in adding jscrollbar to panel

    hi
    please any one can tell how to add jscrollbar to the following code

    Java Code:
    import java.awt.*;
    import javax.swing.JScrollPane;  
    import javax.swing.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.sql.*;
    	public class LoginPage extends JFrame 
    	{  
    		JComboBox jb;
    		JFrame f2;
    		public static String s1,s2,s3,s4,s5;
    		char ch[]=new char[30];
    		JTextField f;
    		JPanel jp;
    		JPasswordField f1;
    		Container c;
    		JLabel l1, l2,l3;
    		static JLabel l4=new JLabel("hai");
    		JButton b1,b2,b3,b4,b5,b6;
    		JScrollPane jsp;
    		ImageIcon im;
    		String s[]={"-------Select------","Incharge","Assistent","Staff","co_staff"};
    		JComboBox jcb;
    		public static Dimension scrsize;
    		LoginPage()
    		{
    			c=getContentPane();
    			l3=new JLabel(im);
    			Toolkit toolkit=Toolkit.getDefaultToolkit();
    			scrsize=toolkit.getScreenSize();
    			setSize(scrsize.width,scrsize.height-50);		
    			jp=new JPanel();
    			jp.setLayout(null);
    			l1=new JLabel("user name :");
    			f=new JTextField(30);
    			l2=new JLabel("password :");
    			f1=new JPasswordField(30);
    			jcb=new JComboBox(s);
    			b1=new JButton("submit");
    			b2=new JButton("Admin Login");
    			b3=new JButton("about");
    			b4=new JButton("Contact us");
    			b5=new JButton("help");
    			b6=new JButton("Back to Login Page");
    			l1.setBounds(450,400,75,25);
    			f.setBounds(600,400,180,25);
    			l2.setBounds(450,500,75,25);
    			l1.setForeground(Color.white);
    			l2.setForeground(Color.white);
    			f1.setBounds(600,500,180,25);
    			l3.setBounds(0,0,scrsize.width,170);
    			jcb.setBounds(830,400,120,25);
    			b1.setBounds(660,610,100,25);
    			b2.setBounds(315,170,180,25);
    			b3.setBounds(495,170,180,25);
    			b4.setBounds(675,170,180,25);
    			b5.setBounds(855,170,180,25);
    			jp.add(l1);
    			jp.add(f);
    			jp.add(jcb);
    			jp.add(l2);
    			jp.add(f1);
    			jp.add(jcb);
    			jp.add(b1);
    			add(b2);
    			add(l4);
    			add(l3);
    			add(b3);
    			add(b4);
    			add(b5);
    			jp.setBackground(Color.darkGray);
    			jp.setForeground(Color.white);
    			add(jsp);			
    			jcb.addActionListener(this);
    			b1.addActionListener(this);
    			b2.addActionListener(this);
    			b3.addActionListener(this);
    			b4.addActionListener(this);
    			b5.addActionListener(this);
    			b6.addActionListener(this);
    			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    			setVisible(true);
    			
    		}
    }
    Moderator Edit: Code tags added
    Last edited by Fubarable; 06-05-2010 at 12:26 AM. Reason: Moderator Edit: Code tags added

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,317
    Rep Power
    25

    Default

    What are you going to control with a JScrollBar?
    Or is it a JScrollPane you want?

    Have you looked in the java tutorial for how to use them?

  3. #3
    Webuser is offline Senior Member
    Join Date
    Dec 2008
    Posts
    526
    Rep Power
    0

    Default

    the thread is for SWING forum ;)
    If my answer helped you. Please click my "REP" button and add a comment
    Have a Good Java Coding :)

  4. #4
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by Webuser View Post
    the thread is for SWING forum ;)
    Agree -- Moving.

    Also, to the original poster, hello, and welcome to the forum. I hope you don't mind that I edited your code and added code tags which should help make your posted code retain its formatting and be more readable.

    To do this yourself, highlight your pasted code (please be sure that it is already formatted when you paste it into the forum; the code tags don't magically format unformatted code) and then press the code button, and your code will have tags.

    Another way to do this is to manually place the tags into your code by placing the tag [code] above your pasted code and the tag [/code] below your pasted code like so:

    Java Code:
    [code]
      // your code goes here
      // notice how the top and bottom tags are different
    [/code]
    Best of luck, and again, welcome!
    Last edited by Fubarable; 06-05-2010 at 12:28 AM.

  5. #5
    Mani_4 is offline Member
    Join Date
    Jun 2010
    Posts
    2
    Rep Power
    0

    Default

    hi NORM sir,
    thank u for replying sir

    whenever i placed in any 15 inches screen it doesn't show complete window
    some of buttons are hide

    i want my window is suitable for any computer sir

    and i want JSCROLLPANE sir

    yes sir i see java tutorial how to add it

    but it doesn't work it sir


    thanks once again sir
    Last edited by Mani_4; 06-05-2010 at 03:40 AM.

  6. #6
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Hello Mani:

    Please elaborate because "it doesn't work" tells us nothing about what you're doing wrong. The tutorials have worked for me and most other Swing coders here. For example, in your code above, you're adding a JScrollPane to a container, but you don't appear to be adding anything that you want scrolled to the JScrollPane's viewport, so the code above doesn't conform to the tutorials instructions and of course won't work.

    I suggest you create a very small program that tries to use a JScrollPane, and then if it doesn't work, post the complete program together with any error messages you may have received, and then we'll be able to help you.

    Much luck!

  7. #7
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by Mani_4 View Post
    but it doesn't work it sir

    clear, if you don't use any layout to place your components, each add() will override the previous component. so sir, study this first.

Similar Threads

  1. Problem with JScrollBar
    By Arthur in forum AWT / Swing
    Replies: 3
    Last Post: 02-19-2010, 02:59 AM
  2. Adding a panel to a panel
    By rclausing in forum New To Java
    Replies: 7
    Last Post: 02-02-2010, 05:56 AM
  3. A problem with JScrollBar and the Jbutton
    By cowboy in forum New To Java
    Replies: 5
    Last Post: 12-19-2009, 09:17 PM
  4. Adding components to a panel
    By jboy in forum New To Java
    Replies: 1
    Last Post: 10-10-2009, 01:02 PM
  5. problem with jscrollbar in my applet
    By leonard in forum Java Applets
    Replies: 1
    Last Post: 08-03-2007, 11:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •