SWT ScrolledComposite cutting off information. - java

I'm making an application that has many lines of data coming back from a Database stub(which will become an Oracle database), and for some reason the scroll bar stops at about the 500th element. I'm wondering if there's anyway to have all the elements show within the scroll bar.

I'm assuming here that you're using Windows, because there is a fairly general problem with scrollbars on Windows: the maximum value is a short int, 32,768. Therefore, if the height of the inner composite of a ScrolledComposite is greater than 32,768 pixels, the composite will be clipped.
I haven't found a robust way of fixing this, but there is a workaround: separate the scrollbar from the composite that you wish to scroll. You can't create a ScrollBar, but you can make a ScrolledComposite that is precisely as wide as a ScrollBar, then attach a ScrollListener to it and have it adjust the layout position of the scrolling composite.
Somewhere I have a snippet, but I'm not even exactly sure if this diagnosis applies to your scenario.

You might need to set the minimum and maximum values of the ScrollBar. You would use the setMinimum() and setMaximum() methods, respectively.
It's also a good idea to set the page increment. This is the number of scroll lines that the selected value changes by when the user clicks the area between the thumb and the arrow buttons, or presses the Page Up or Page Down buttons. You would use the setPageIncrement() method.
Finally, Oracle may impose a maximum number of rows you can retrieve from a table. I believe the default is 500 rows.

Related

Is there a way to have a GridView with dynamic cell size?

In android, the gridview provides an excellent way to arrange items neatly. However, the cell size for a grid is fixed. That is, in a 3 column by 4 rows grid, if the very first item is 10 dp in height and the second and third items are 20 dp in height, then all the cells in first row will be of 20 dp height.
I want to find a way where in, the view will automatically adjust the cell size for the first cell, so that items below the first item of 10dp height are displayed immediately below it, instead of leaving that extra 10dp gap.
This is the sort of behaviour we can see in Windows live tiles. The items below small tiles move up to fill the gap. I want to implement a similar functionality.
Is there a way to do that?
So turns out, there was already a way to do this. I just didn't know the right term for it.
Android provides a StaggeredGridLayout Layout Manager that does just what I need.
You can take a look at this page
Also, visit this page to see it in action.

Expandable grid Vaadin UI

I have a simple grid. Two columns with a variable amount of rows. I want to make it so i have a header row with an arrow that can collapse and show the whole grid. So when I bring up the app, only the header row is visible with an arrow, and I can click to expand/collapse to show the rest of the grid.
A TreeGrid seems like overkill since I don’t need any hierarchical structure, just the ability to collapse/expand one row. I exclusively use IE and I’ve read that Drawyer doesnt work with IE 8 and above. I return a list of the objects and the object just has two string variables.
Any help with this? I am new to Vaadin 8.
Set grid height (workaround)
As a workaround, you could set the height to be approximately the number of pixels you expect to be the height of the header.
See the Sampler demo. Click the gear icon at top to expose properties of the example Grid object. The last property shown is "Size (W x H)". Change 100% to 100px to see the effect.
Grid height set to 100%
Grid height set to 100px
You can also hide the footer (see checkbox in that property list).
I don't think this can be done with plain Vaadin. But I recommend the following simpler approach:
Initially call grid.setHeightByRows(1.5) (javadoc). This will show exactly one row and a half to indicate more data is available. A scrollbar will appear, too.
Make a new column within the grid that has a button or add a button below the grid that - when clicked - calls setHeightByRows with the number of elements in the grid and hides the button. This will show all rows.

How to set minimum size of scrollbar thumb slider on SWT ScrollBar?

Specifically on a Windows XP machine, The width of the SWT ScrollBar Slider becomes incredibly thin when the internal scroll composite is very large. Is there a way to set the minimum width of the thumb slider to like 10-15px so that it doesn't get that thin? My specific case with this is when using NatTables with large amounts of data.
The scrollbar in NatTable is managed by the ViewportLayer. It internally uses instances of ScrollBarScroller for this, which are wrappers around a ScrollBar. To support custom scrollbars like the one posted in the other answer, the ViewportLayer supports that you set a custom ScrollBarScroller. This is explained in one of my blog posts here: NatTable with custom scrollbars.
You could for example set a customized instance of ScrollBarScroller where you override #setThumb(int) and there you ensure that the value of the thumb never gets below a certain minimum. Not sure if that would have any side effects on scrolling. But it should be worth a try.
Hi I don't think you can do that, because the Scrollbar it's drawn by the OS.
I think you have two options here, if you really need this feature:
1) implement you custom Scrollbar.
2) try to use/modify an existing custom Scrollbar, for instance this one: http://www.codeaffine.com/2014/12/17/sacrilege-custom-swt-scrollbar/

Do JComboBoxes have a maximum number of fields?

I had a look through the documentation but could not find an answer to this... Obviously, it becomes impractical to use a JComboBox if the number of fields becomes too high, but all the same, in theory, do JComboBoxes have a maximum number of fields?
Methods like setSelectedIndex(...) and getItemAt(...) take an int variable as a parameter. This would indicate that the ComboBoxModel can support a "theoretical" maximum of INTEGER.MAX_VALUE items.
However, the items must also be rendered and ultimately displayed in a JScrollPane. The scroll pane and vertical JScrollBar also use an int variable to specify the pixel location of the scrollbar.
So you must also consider the height of each rendered item in the scroll pane.
Therefore a more reasonable "theoretical" maximum using the standard Swing components would be INTEGER.MAX_VALUE / rendered-row-height.
However, I suppose you could create a custom scroll pane that only displayed the items in blocks. So as you scroll towards the end of one block you preload the next block. Theoretically this would allow you to display all INTEGER.MAX_VALUE items in the combo box.
I don't know if there would be any other limitations for the "theoretical" maximum number of items.
In any case I'm sure we all agree a combo box would become unusable well before the "theoretical" maximum is reached.
Not to my knowledge, like you said it might become more useful to use another interface tool if you end up having to scroll for too much. My reasoning is because you can dynamically populate it which needs to be as flexible as your data.
Following the answer #camickr gave you, I created an array with the hightest integer value in java (INTEGER.MAX_VALUE, which is 2147483647) and then after waiting for ten seconds the program throwed me an Requested array size exceeds VM limim error. According to plumbr.io that means:
Java has got a limit on the maximum array size your program can
allocate. The exact limit is platform-specific but is generally
somewhere between 1 and 2.1 billion elements.
Then I decided to try just with 1.800.000 elements and that worked, it lasts 10 secs approximately and when I clicked the combo box it took like 5 seconds to load all the elements, but it worked with no issue.

How to determine how far a scrollbar has moved in SWT?

Before Scroll
After Scroll
I am working on creating an Eclipse plugin for tracking of collections (Arrays, Array List, etc.). And I was in need of an SWT Table with expandable columns. In order to implement this, I created several SWT buttons, and generated them before I created the table, and I linked them to the columns that need to be expanded. What I'm having a problem with now is that I need a way to determine how much a user scrolled the scroll bar in order to determine what the new location of the buttons should be. For instance, if the user scrolls 10 pixels to the left, I need to move the buttons 10 pixels to the left, etc.
Is there an easy way to accomplish this within the SWT ScrollBar framework?
Actually, I was able to solve the problem by using Scrollbars "getSelection" method. Turns out, the value that this method represents is the offset from 0 of the scrollbar. In order to solve the problem, I just subtracted the getSelection value from the X position of the buttons

Categories

Resources