Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By jim829

Thread: NetBeans created a JList/JScrollPane that won't scroll

  1. #1
    MGeorge's Avatar
    MGeorge is offline Aging Hacker
    Join Date
    Sep 2014
    Location
    East (San Francisco) Bay, California, USA
    Posts
    20
    Rep Power
    0

    Default NetBeans created a JList/JScrollPane that won't scroll

    Using NetBeans 8.0, I have created an application that includes a JList wrapped in a JScrollpane. Everything is working quite well except that the list cannot be scrolled. The project consists of over 7k lines in 21 source files (not counting libraries) so posting the entire thing doesn't seem feasible, but the fragment below shows the NetBeans-generated code that creates the JList.

    Java Code:
       private void initComponents() {
    
          scroller = new javax.swing.JScrollPane();
          list = new javax.swing.JList();
    
          scroller.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
          scroller.setAutoscrolls(true);
    
          list.setFont(new java.awt.Font("Courier New", 0, 11)); // NOI18N
          list.setModel(new javax.swing.AbstractListModel() {
             String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
                public int getSize() { return strings.length; }
                public Object getElementAt(int i) { return strings[i]; }
          });
          list.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
          list.setMaximumSize(new java.awt.Dimension(500, 75));
          list.setMinimumSize(new java.awt.Dimension(44, 75));
          list.setName("list"); // NOI18N
          list.setPreferredSize(new java.awt.Dimension(44, 75));
          list.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
             public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                listValueChanged(evt);
             }
          });
          scroller.setViewportView(list);
    
          javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
             this.setLayout(layout);
             layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                   .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                      .addGroup(layout.createSequentialGroup()
                         .addContainerGap()
                         .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createSequentialGroup()
                               .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                  .addComponent(scroller)
                                  .addComponent(listButtons, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE))
                               .addGap(0, 0, Short.MAX_VALUE))
                            .addComponent(webFieldPanel, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                         .addComponent(webBottomButtonPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                      .addContainerGap())
             );
    
             layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                   .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(scroller, javax.swing.GroupLayout.DEFAULT_SIZE, 97, Short.MAX_VALUE)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                      .addComponent(listButtons, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                      .addComponent(webFieldPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 204, Short.MAX_VALUE)
                      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                      .addComponent(webBottomButtonPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addGap(10, 10, 10))
             );
    
       }
    The UI includes a reasonable looking list although the scrollbar is not displayed in its entirety. The list is populated with plenty of entries to cause scrolling and the scrollpane is created with VERTICAL_SCROLLBAR_ALWAYS.

    Any assistance in getting this list to scroll properly will be appreciated.

  2. #2
    MGeorge's Avatar
    MGeorge is offline Aging Hacker
    Join Date
    Sep 2014
    Location
    East (San Francisco) Bay, California, USA
    Posts
    20
    Rep Power
    0

    Default Re: NetBeans created a JList/JScrollPane that won't scroll

    Okay, after messing with this for several hours I took the shotgun approach. I removed the JList and it's JScrollPane from my UI and replaced them with 'new' ones. The scrolling problem is solved although I don't understand why. For the record, I love Netbeans (most of the time) as it makes building UIs really easy but I hate the virtually unreadable code that it generates.

    Problem solved. I'll move on and try not to think about it again.

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: NetBeans created a JList/JScrollPane that won't scroll

    Quote Originally Posted by MGeorge View Post
    For the record, I love Netbeans (most of the time) as it makes building UIs really easy but I hate the virtually unreadable code that it generates.
    Then I suggest you get away from using visual designers (no one is forcing you to use them). Using layout managers
    for your gui's is certainly more readable and you will learn more in the process.

    Regards,
    Jim
    DarrylBurke likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    MGeorge's Avatar
    MGeorge is offline Aging Hacker
    Join Date
    Sep 2014
    Location
    East (San Francisco) Bay, California, USA
    Posts
    20
    Rep Power
    0

    Default Re: NetBeans created a JList/JScrollPane that won't scroll

    Quote Originally Posted by jim829 View Post
    Then I suggest you get away from using visual designers (no one is forcing you to use them). Using layout managers
    for your gui's is certainly more readable and you will learn more in the process.

    Regards,
    Jim
    Right. Thanks for your recommendation. Still, my question goes unanswered. I was hoping someone could speak to the scrolling problem and how to avoid it when using NetBeans, not just bash me for using it.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: NetBeans created a JList/JScrollPane that won't scroll

    I didn't answer your question because you said you had already solved the problem. Any other solution I might provide
    would related to a layout manager based GUI. That would most likely be unusable by you at this point. And if you think
    my suggestion was bashing you, then you are in for a rude awakening in this forum.

    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    25

    Default Re: NetBeans created a JList/JScrollPane that won't scroll

    Quote Originally Posted by jim829 View Post
    if you think my suggestion was bashing you, then you are in for a rude awakening in this forum.

    Regards,
    Jim
    Or any other.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. JscrollPane and scroll Bug
    By jviure in forum AWT / Swing
    Replies: 0
    Last Post: 01-16-2013, 04:06 PM
  2. Replies: 5
    Last Post: 09-28-2011, 05:43 PM
  3. Replies: 1
    Last Post: 04-05-2011, 12:12 PM
  4. Moving Scroll in JScrollPane
    By ayesh85 in forum AWT / Swing
    Replies: 0
    Last Post: 03-02-2011, 08:11 AM
  5. jscrollpane scroll issues
    By kumar_gemi in forum AWT / Swing
    Replies: 11
    Last Post: 09-30-2009, 08:33 PM

Tags for this Thread

Posting Permissions

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