Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: JScrollPane not scrolling down to Jlabel

  1. #1
    Junior Member
    Join Date
    Mar 2019
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question JScrollPane not scrolling down to Jlabel

    Hey all I have the following java code that simply has a few swing JLabel, JPanel, and JScrollPanel.

    I seem to not be able to have the labels that are inside the pane (546211) to cause the scroll to activate vertically. Right now, with me adding to the labels inside and having some off scene, it still does not scroll to those.

    This is what my design looks like:



    And for testing I shorten the height so that the last label is not viewable:



    But when I run it, I am unable to scroll to see that label:



    As you can see from the image above my scroll is there but it has no value. The scroll should be there since I put a label out of scene that I would need to scroll down to in order to see it.

    Hopefully it's just something I am overlooking for the JScrollPane. Or perhaps I have something out of order?

    My java code:

            static JPanel panel;
    	private JFrame frame;
     
    	public static void main(String[] args) {
    		EventQueue.invokeLater(new Runnable() {
    			public void run() {
    				try {
    					tester window = new tester();
    				} catch (Exception e) {
    					e.printStackTrace();
    				}
    			}
    		});
    	}
     
    	public tester() {
    		initialize();
    	}
     
        private void initialize() {
    		Image imgBG = new ImageIcon(this.getClass().getResource("/background.png")).getImage();
    		Image imgAvatar = new ImageIcon(this.getClass().getResource("/blank.png")).getImage();		
    		panel = new JPanel();
     
    		panel.setLayout(null);
     
    		JLabel lblLabelBG = new JLabel("");
    		lblLabelBG.setBounds(10, 3, 635, 129);
    	    lblLabelBG.setIcon(new ImageIcon(imgBG));
    		lblLabelBG.setBackground(new Color(204, 102, 0));		
     
    		JLabel AvatarImg = new JLabel("");
    		AvatarImg.setIcon(new ImageIcon(imgAvatar));
    		AvatarImg.setBounds(5, 4, 100, 111);
    		panel.add(AvatarImg);
     
    		JLabel lblPH = new JLabel();
    		lblPH.setFont(new Font("Segoe UI", Font.BOLD, 25));
    		lblPH.setBounds(15, 110, 172, 22);
    		lblPH.setText("555-555-5555");
    		panel.add(lblPH);
     
    		JLabel lblRX = new JLabel();
    		lblRX.setFont(new Font("Segoe UI", Font.BOLD, 25));
    		lblRX.setBounds(55, 170, 157, 22);
    		lblRX.setText("546211");
    		panel.add(lblRX);
    		panel.add(lblLabelBG);
     
    		JScrollPane scrollPane = new JScrollPane(panel);
    		scrollPane.setBackground(new Color(153, 153, 102));
    		scrollPane.setBounds(10, 11, 743, 156);
    		scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    		scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
     
    		JFrame frame = new JFrame("");
     
    		frame.getContentPane().setBackground(new Color(240, 240, 240));
    		frame.getContentPane().setLayout(null);		
    		frame.setSize(785, 291);
    		frame.getContentPane().add(scrollPane);
    		frame.setVisible(true);
    	}

  2. #2
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    102
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JScrollPane not scrolling down to Jlabel

    A guy is doing the programming from NetBeans too. From the server side. Or whatever Java editor you're on.

Similar Threads

  1. Drawing and Scrolling
    By aussiemcgr in forum Android Development
    Replies: 6
    Last Post: July 21st, 2014, 01:03 PM
  2. Replies: 1
    Last Post: April 10th, 2014, 06:07 AM
  3. [SOLVED] JScrollPane and programatic scrolling
    By brajan1984 in forum AWT / Java Swing
    Replies: 6
    Last Post: January 6th, 2013, 02:58 PM
  4. Loop through JLabel and change JLabel
    By JoeBrown in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 11th, 2012, 12:52 PM
  5. scrolling in jsp tables
    By ravindraneeluri in forum Member Introductions
    Replies: 1
    Last Post: May 25th, 2011, 09:17 AM