I am trying to puzzle out steps to make an online listbox (or tree or outline) in Swing -- this is one in which the listbox can display a "view" inside a large result set from the database without obtaining the entire result set's contents all it must produce is really a manages that Products N1 - N2 will need to become displayed soon, in order to fetch them, and request for that items in item N.

I understand how to get it done in Win32 (ListView + LVS_OWNERDATA) as well as in XUL (custom treeview), and that i found something for SWT, although not Swing.

Any suggestions?


update: aha, I did not know very well what to search for in search engines like google, &lifier the lessons don't appear to refer to it as a "virtual listbox" or make use of the idea. I discovered a good tutorial will be able to begin with, and among the Sun lessons appears ok also.

Here's my example program, which works the way in which I expect... except it appears such as the listbox queries my AbstractListModel for all rows, not only the rows which are visible. For any million-row virtual table this is not practical. How do i fix this? (edit: it appears like setPrototypeCellValue fixes this. However I do not understand why...)

package com.example.test

import java.awt.BorderLayout

import java.awt.Dimension

import java.awt.event.ActionEvent

import java.awt.event.ActionListener

import javax.swing.AbstractListModel

import javax.swing.JButton

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

// according to:

// http://world wide web.java2s.com/Tutorial/Java/0240__Swing/extendsAbstractListModel.htm

// http://world wide web.java2s.com/Tutorial/Java/0240__Swing/SpinnerNumberModel.htm

// http://java.sun.com/j2se/1.4.2/paperwork/api/javax/swing/SpinnerNumberModel.html

// http://world wide web.java2s.com/Tutorial/Java/0240__Swing/ListeningforJSpinnerEventswithaChangeListener.htm

public class HanoiMoves stretches JFrame primary(String[] args) 

    static final int initialLevel = 6

    final private JList list1 = new JList()

    final private HanoiData hdata = new HanoiData(initialLevel)

    public HanoiMoves() 

    

    spinner1.addChangeListener(listener)

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)

    setVisible(true)

    



class HanoiData stretches AbstractListModel 

    private int level

    public int getLevel() 

    public void setLevel(int level) 

    public int getSize() 

    // the ruler function (http://mathworld.wolfram.com/RulerFunction.html)

    // = position of rightmost 1

    // see bit-twiddling hacks page:

    // http://world wide web-graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightMultLookup

    public int rulerFunction(int i)

    lengthy r1 = (i &lifier (-i)) &lifier 0xffffffff

    r1 *= 0x077CB531

    return MultiplyDeBruijnBitPosition[(int)((r1 >> 27) &lifier 0x1f)]

    

    final private static int[] MultiplyDeBruijnBitPosition =

    

    public Object getElementAt(int index) publish_before = (x % 3) + 1

    int publish_after  = ((x+K) % 3) + 1

    return String.format("%d. move disk %of publish %d to publish %d",

    move, disk, publish_before, publish_after)

    




update:

per jfpoilpret's suggestion, I put a breakpoint within the getElementData() function.

if ((index &lifier 0x3ff) == )



I checked out the stacktrace for that thread under consideration. It isn't really that useful (published below). From another fine-tuning, however, it appears such as the causes would be the fireIntervalAdded()/fireIntervalRemoved() and also the alternation in caused by getSize(). The fireIntervalxxxx appears to clue Swing into checking the getSize() function, and when the dimensions changes, it is going and refetches All the row contents immediately (or at best it puts demands in to the event queue to do this).

There must be a way to inform it Avoid That!!!! but I'm not sure what.

com.example.test.HanoiMoves at localhost:3333

    Thread [primary] (Suspended (breakpoint at line 137 in HanoiData))

    HanoiData.getElementAt(int) line: 137

    BasicListUI.updateLayoutState() line: unavailable

    BasicListUI.maybeUpdateLayoutState() line: unavailable

    BasicListUI.getPreferredSize(JComponent) line: unavailable

    JList(JComponent).getPreferredSize() line: unavailable

    ScrollPaneLayout$UIResource(ScrollPaneLayout).layoutContainer(Container) line: unavailable

    JScrollPane(Container).layout() line: unavailable

    JScrollPane(Container).doLayout() line: unavailable

    JScrollPane(Container).validateTree() line: unavailable

    JPanel(Container).validateTree() line: unavailable

    JLayeredPane(Container).validateTree() line: unavailable

    JRootPane(Container).validateTree() line: unavailable

    HanoiMoves(Container).validateTree() line: unavailable

    HanoiMoves(Container).validate() line: unavailable

    HanoiMoves(Window).show() line: unavailable

    HanoiMoves(Component).show(boolean) line: unavailable

    HanoiMoves(Component).setVisible(boolean) line: unavailable

    HanoiMoves(Window).setVisible(boolean) line: unavailable

    HanoiMoves.<init>() line: 69

    HanoiMoves.primary(String[]) line: 37

    Thread [AWT-Shutdown] (Running)

    Daemon Thread [AWT-Home windows] (Running)

    Thread [AWT-EventQueue-] (Running)


Update: I attempted using a few of the FastRenderer.java code in the Advanced JList Programming article which fixed it. However it works out it isn't the renderer whatsoever! One type of code fixed my problem, and that i do not understand why:

list1.setPrototypeCellValue(list1.getModel().getElementAt())