You are not logged in.

Perry

Beginner

  • "Perry" is male
  • "Perry" started this thread

Posts: 40

Date of registration: Jan 15th 2011

Location: Sarasota, FL

Occupation: Cabinet Design

Hobbies: Programming

  • Send private message

1

Friday, August 16th 2013, 1:53pm

Listbox AddItem Method

The AddItem Method of combo boxes and list boxes seems to be slow. Most times it isn't a problem until you reach around 5000 entrys.

You can test this on the sort routines that are given as sample apps.

Instead of clearing and adding items to the list box on the right, try simply changing .List() values in the entrys in the left list box with the new sorted data. Do this without clearing the List Box, or using the .AddItem Method.
The speed of the Sort Demo picks up impressively.

I'm testing one app where filling the Listbox takes nearly 5 minutes. It was longer but I discovered that because we are working with event driven programming, that routine was being hit twice.

Has anyone found another method of adding Items that is faster?

My particular need at this point is to speed up the list box when I add Items with a checkbox style.

theuserbl

Intermediate

Posts: 436

Date of registration: Dec 20th 2008

  • Send private message

2

Friday, August 16th 2013, 9:22pm

Have currently not the time to look closer at it.

But you are right, the implementation of it in the Jabaco Framework working slow.

Here the Java-way without checkboxes.
50000 entries are very fast generated.

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
Public Sub Command1_Click()
  Dim listModel As New DefaultListModel
  Dim f = New JFrame("JScrollPane Demonstration")
  f.setSize(300, 200)
  
  Dim list As New JList(listModel)
  'Dim scrollpane As New JScrollPane(list)
  Dim scrollpane As New JScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED)
  f.getContentPane().add(scrollpane)
  For i = 1 To 50000
    listModel.addElement("Entry Number " & i )
  Next i  
  f.setVisible(True)
End Sub


Have to look, how to integrate it better in Jabaco.
But currently I have not the time for that.

Greatings
theuserbl

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

3

Sunday, December 8th 2013, 12:57pm

ComboBox/Listbox AddItem Method very slow - approach to a fix

Hey there,

I have located the bottleneck when adding items to ComboBox And ListBox.
The problem are these two lines In the ListCellData class:

Jabaco Source

1
2
3
tmpCheckBox = New JCheckBox(Text)
...
tmpLabel = New JLabel(Text, getIcon(), SwingConstants.LEFT)


Creating new instances of those components seems to slow down the whole procedure dramatically!

For Strings only I can provide a solution that will make a 100.000 entries and more no problem!
For CheckBoxes And Icons I don't have a solution.So please dig into it. Maybe someone else can think of something.
This has to be changed :

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
'in ListCellDataRenderer
Public Function getListCellRendererComponent(List As #JList, Value As #Object, Index As Integer, IsSelected As Boolean, CellHasFocus As Boolean) As #Component 
   On Error Resume Next
   Dim tmpCellData As ListCellData  = Cast(Value, #ListCellData)
   If tmpCellData <> Nothing And myOwner <> Nothing Then
   'old
'      getListCellRendererComponent = tmpCellData.getComponent(myOwner, IsSelected, CellHasFocus)
   'new
      Dim myComponent As #Component
      myComponent = IIF(tmpCellData.Icon = Nothing And tmpCellData.AsCheckBox = False, Base.getListCellRendererComponent(List, Value, Index, IsSelected, CellHasFocus), Nothing)
      getListCellRendererComponent = tmpCellData.getComponent(myOwner, myComponent, IsSelected, CellHasFocus)
'
      If Index Mod 2 = 1 Then If Not IsSelected Then
         If myOwner.BackColorAlternating = 0 Then 
            Call getListCellRendererComponent.setBackground(myOwner.getBackground)
         Else
            Call getListCellRendererComponent.setBackground(RGBtoColor(myOwner.BackColorAlternating))
         End If
      End If
   Else
      getListCellRendererComponent = Base.getListCellRendererComponent(List, Value, Index, IsSelected, CellHasFocus)
   End If
End Function

'in ListCellData
'old
   'Public Function getComponent(Owner As IListCellDataOwner, IsSelected As Boolean, CellHasFocus As Boolean) As #Component 
'new
Public Function getComponent(Owner As IListCellDataOwner, myComponent As #Component, IsSelected As Boolean, CellHasFocus As Boolean) As #Component

'in ComboBox And ListBox
Private Function GetCellComponent(Index As Long) As Component
   On Error Resume Next
   GetCellComponent = Cast(GetCellData(Index).getComponent(Me, Nothing, (ListIndex = Index), (ListIndex = Index)), Component)
End Function


I have added a SampleApp: ListCellData Test.zip

This is not to be considdered as a final solution, it is just for demonstrating the issue!


Dani

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

4

Saturday, December 21st 2013, 9:46am

Hey there,

yet another version of getListCellRendererComponent for the ListCellDataRenderer class. It takes care of an issue where most of the properties of the ComboBox - Editor get overridden by LAF !!
Have a look at the above code for what else has to be changed to use this.

This makes ComboBoxes populated with strings only incredibly fast (compared to what we have now!):

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
Public Function getListCellRendererComponent(List As #JList, Value As #Object, Index As Integer, IsSelected As Boolean, CellHasFocus As Boolean) As #Component 
   On Error Resume Next
   Dim tmpCellData As ListCellData  = Cast(Value, #ListCellData)
   If tmpCellData <> Nothing And myOwner <> Nothing Then
         'old
         'getListCellRendererComponent = tmpCellData.getComponent(myOwner, IsSelected, CellHasFocus)
      If Index = -1 Then
         'pass on Nothing so ListCellData invokes a new component; to compensate LAF settings of the Editor!
         getListCellRendererComponent = tmpCellData.getComponent(myOwner, Nothing, IsSelected, CellHasFocus)
      Else
         'new
         'pass on the default BaseComponent
         Dim myComponent As #Component
         myComponent = IIF(tmpCellData.Icon = Nothing And tmpCellData.AsCheckBox = False, Base, Nothing)
         getListCellRendererComponent = tmpCellData.getComponent(myOwner, myComponent, IsSelected, CellHasFocus)
      End If
      If Index Mod 2 = 1 Then If Not IsSelected Then
         If myOwner.BackColorAlternating = 0 Then 
            Call getListCellRendererComponent.setBackground(tmpCellData.Owner.getBackground)
         Else
            Call getListCellRendererComponent.setBackground(RGBtoColor(tmpCellData.Owner.BackColorAlternating))
         End If
      End If
   Else
      getListCellRendererComponent = Base.getListCellRendererComponent(List, Value, Index, IsSelected, CellHasFocus)
   End If
End Function


We should probably move this to the framework. But I was kind of hoping that someone came up with a thought about how to speed things up using icons and CheckBoxes as well.

Jabaco Source

1
2
ComboBox1.AddItem New ListCellData(" Dani", resources.ApplicationputPng, False)
 ComboBox1.AddItem New ListCellData(" Dani", Nothing, True)


Anyone??

Happy holidays everyone...


Dani

This post has been edited 3 times, last edit by "Dani" (Jan 22nd 2014, 9:01pm)


Perry

Beginner

  • "Perry" is male
  • "Perry" started this thread

Posts: 40

Date of registration: Jan 15th 2011

Location: Sarasota, FL

Occupation: Cabinet Design

Hobbies: Programming

  • Send private message

5

Wednesday, January 22nd 2014, 6:57pm

Slow List Boxes

How about we split the code.
Have 1 version of code for a List box without icons, and one code version for list boxes with Icons.
Do the same for combo boxes.

Just an Idea. I don't know how feasable that would be, since I'm not a very good Java programmer.

What we would be attempting, is to isolate the problem only to the case where a person would use Icons. I will admit this does not solve the problem with the Icons, but it would free up the use of the list boxes in cases where no Icons are used.

We could then work on the problem with the Icons at a more leasurely pace. I suspect the problem may be a bit involving. The Icons of course are graphic in nature, & I would suppose the code somewhere is attempting to allocate memory space for it. I can see where repeated allocations of memory space for graphics could take up processing time. Just a guess here.

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

6

Wednesday, January 22nd 2014, 8:52pm

Hey there,

Quoted

How about we split the code.
Have 1 version of code for a List box without icons, and one code version for list boxes with Icons.
Do the same for combo boxes.


don't worry about that! My solution is already taking care of all those cases and works fine with my personal jabaco.jar !
I simply did not yet upload it to the framework because I was hoping someone had a hint on how to speed things up with icons too.

Just take my code above and compile the framework!


Dani

Perry

Beginner

  • "Perry" is male
  • "Perry" started this thread

Posts: 40

Date of registration: Jan 15th 2011

Location: Sarasota, FL

Occupation: Cabinet Design

Hobbies: Programming

  • Send private message

7

Friday, January 24th 2014, 1:57pm

Quoted

Just take my code above and compile the framework!


I need to be stepped through.
Are there instructions posted somewhere that I can follow?

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message

8

Friday, January 24th 2014, 2:52pm

Hey there,

I have just comitted a patch to the Jabaco framework.
You can view my changes rev. 128 here:

https://code.google.com/p/jabacoframework/source/list

There are many posts throughout this forum on how to download and compile the framework.
In fact I have just pointed to a related post a couple days ago:
http://www.jabaco.org/board/p4045-framew…m.html#post4045

If you wait a bit I am sure theuserbl will compile the framework and provide the downloadlink here:

www.jabaco.org/wiki/Latest_JabacoFramework_Binary


Dani

Perry

Beginner

  • "Perry" is male
  • "Perry" started this thread

Posts: 40

Date of registration: Jan 15th 2011

Location: Sarasota, FL

Occupation: Cabinet Design

Hobbies: Programming

  • Send private message

9

Tuesday, February 4th 2014, 2:44pm

Listbox Speed

Dani
These improvements are HUGE. :)
Thanks a lot. Good Work.

Dani

Intermediate

Posts: 325

Date of registration: Nov 19th 2009

Location: GERMANY

  • Send private message
Rate this thread
WoltLab Burning Board