Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 161469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T11:13:07+00:00 2026-05-11T11:13:07+00:00

I’ve got my virtual list in swing working well, but it seems to fail

  • 0

I’ve got my ‘virtual list’ in swing working well, but it seems to fail when I exceed some particular number of items. By ‘fail’ I mean that the scroll bar magically vanishes when the number of items is > Nmax, and it comes back when the number of items is <= Nmax; Nmax seems to be somewhere around 119,304,000 on my system.

What am I running up against?!?!

(Here’s a test program: on my computer, if I type in 119,304 it works ok, but I click the up arrow and the scroll bar disappears)

package com.example.test;  import java.awt.BorderLayout; import java.awt.Dimension; import javax.swing.AbstractListModel; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JSpinner; import javax.swing.SpinnerModel; import javax.swing.SpinnerNumberModel; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener;  // based on: // http://www.java2s.com/Tutorial/Java/0240__Swing/extendsAbstractListModel.htm // http://www.java2s.com/Tutorial/Java/0240__Swing/SpinnerNumberModel.htm // http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/SpinnerNumberModel.html // http://www.java2s.com/Tutorial/Java/0240__Swing/ListeningforJSpinnerEventswithaChangeListener.htm // http://java.sun.com/products/jfc/tsc/tech_topics/jlist_1/jlist.html  public class BigVirtualList extends JFrame {      public static void main(String[] args) {         new BigVirtualList();     }      static final int initialLength = 1;     final private JList list1 = new JList();     final private BVLData bvldata = new BVLData(initialLength*1000);      public BigVirtualList() {         this.setTitle('Big virtual list');         this.getContentPane().setLayout(new BorderLayout());         this.setSize(new Dimension(400, 300));         list1.setModel(bvldata);          list1.setPrototypeCellValue(list1.getModel().getElementAt(0));           SpinnerModel model1 = new SpinnerNumberModel(initialLength,1,1000000,1);         final JSpinner spinner1 = new JSpinner(model1);          this.getContentPane().add(new JScrollPane(list1), BorderLayout.CENTER);         JLabel label1 = new JLabel('Length (1000s of items):');         JPanel panel1 = new JPanel(new BorderLayout());         panel1.add(label1, BorderLayout.WEST);         panel1.add(spinner1, BorderLayout.CENTER);         this.getContentPane().add(panel1, BorderLayout.SOUTH);                ChangeListener listener = new ChangeListener() {             public void stateChanged(ChangeEvent e) {                 Integer newLength = (Integer)spinner1.getValue();                 bvldata.setLength(newLength*1000);             }         };          spinner1.addChangeListener(listener);         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);         setVisible(true);     } }  class BVLData extends AbstractListModel {     public BVLData(int length) { this.length = length; }      private int length;      public int getLength() { return length; }     public void setLength(int length) {         int oldLength = getLength();         this.length = length;         int newLength = getLength();          if (newLength > oldLength)             fireIntervalAdded(this, oldLength+1, newLength);         else if (newLength < oldLength)             fireIntervalRemoved(this, newLength+1, oldLength);           }         @Override     public Object getElementAt(int index) {         return 'Item '+index+' mod 107 = '+(index%107);     }      @Override     public int getSize() { return getLength(); }  } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T11:13:07+00:00Added an answer on May 11, 2026 at 11:13 am

    Well I don’t see the purpose but anyway …

    I guess you break the integer max value somewhere in the scroll pane:

    System.out.println('CellHeight:'+list1.getFixedCellHeight()); System.out.println('CellHeight*119304000:'+NumberFormat.getNumberInstance().format(list1.getFixedCellHeight()*119304000.0)); System.out.println('MAXINT:'+Integer.MAX_VALUE); 

    Gives you the numbers:

     CellHeight:18 CellHeight*119304000:2.147.472.000 MAXINT:2.147.483.647 

    As you can see adding another 18000 pixel in height will go beyond MAXINT … this gets you in trouble.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I need to clean up various Word 'smart' characters in user input, including but
i got an object with contents of html markup in it, for example: string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.