I have created a ScrollPane but there is no bar to scroll with (like the one on the side of your browser) you have to drag with your mouse. How can I get a scroll bar?
What I did to add a scrollbar was use libgdx's ScrollPane.ScrollPaneStyle to set the scroll bar as a ninepatch.
ScrollPane.ScrollPaneStyle scrollStyle;
/...
scrollTexture = new Texture(Gdx.files.internal("Scroll9.png"));
scrollNine = new NinePatch(new TextureRegion(scrollTexture,6,6),2,2,2,2);
then I created the vertical scroll knob
scrollStyle = new ScrollPane.ScrollPaneStyle();
scrollStyle.vScrollKnob = new NinePatchDrawable(box);
and applied the style to my scrollable table
scroll = new ScrollPane(test, scrollStyle);
source:
http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.ScrollPaneStyle.html
The bar is enabled via the skin:
Skin skin = new Skin(Gdx.files.internal("data/uiskin.json"));
ScrollPane scrollPane=new ScrollPane(resultsTextArea, skin);
I tried. It works now...
This is untested!
It seems that using the following enables scrollbars for a scrollpane.
boolean enable_x = true;
boolean enable_y = true;
scrollpane.setForceScroll(enable_x,enable_y);
source: http://libgdx.badlogicgames.com/nightlies/docs/api/com/badlogic/gdx/scenes/scene2d/ui/ScrollPane.html
Related
I have a JScrollPane that holds a JPanel. The layout on the JPanel is a GridBagLayout. On that JPanel, I add a number of custom components - each is a JPanel with 3 JLabels.
The first time in the program I lay all of this out, it works fine. When I invoke the code to add another custom component to the JPanel, the panel appears empty, but I can determine by examining the contents of the JPanel that my components are actually there. If I resize the JDialog in which this all sites, the JPanel will paint properly. It also works if I scroll the JScrollPane horizontally even a tiny bit.
I use the same method for the initial layout as I do when adding an item.
I've tried various combinations of repaint(), invalidate() and doLayout() but nothing seems to work all the time. I've run into this situation before and have never been able to fully solve it. Any suggestions?
Running under OpenJDK 7u25. Below is the code that lays out the scroll pane and panel.
private void displayRelatedBug(ArrayList<Bug> a_bugs) {
// sort the bugs by ID
ArrayList<Bug> l_sorted = new ArrayList<>(a_bugs);
Collections.sort(l_sorted);
pnlRelatedBugs.removeAll();
pnlRelatedBugs.setLayout(new GridBagLayout());
GridBagConstraints l_gbc = new GridBagConstraints();
l_gbc.gridx = 0;
l_gbc.gridy = 0;
l_gbc.gridwidth = 1;
l_gbc.gridheight = 1;
l_gbc.anchor = GridBagConstraints.NORTHWEST;
l_gbc.fill = GridBagConstraints.NONE;
l_gbc.insets = new Insets(3, 4, 0, 0);
for (Bug r : l_sorted) {
pnlRelatedBugs.add(new RelatedBugDisplay(r, this), l_gbc);
l_gbc.gridy++;
}
// add a filler at the bottom to push it up
l_gbc.weighty = 1.0;
pnlRelatedBugs.add(new MMPanel(), l_gbc);
// add a filler on the right to push them left
l_gbc.weighty = 0.0;
l_gbc.weightx = 1.0;
l_gbc.gridx++;
pnlRelatedBugs.add(new MMPanel(), l_gbc);
// try in vain to make it show up!!!
pnlRelatedBugs.invalidate();
pnlRelatedBugs.doLayout();
pnlRelatedBugs.repaint();
scrollerRelatedBugs.doLayout();
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
pnlRelatedBugs.repaint();
scrollerRelatedBugs.repaint();
// this seems to help if the scroll bar is showing
scrollerRelatedBugs.getHorizontalScrollBar().setValue(1);
scrollerRelatedBugs.getHorizontalScrollBar().setValue(0);
}
});
}
Whenever you add/remove components from a visible panel, the basic code is:
panel.remove(...);
panel.add(...);
panel.revalidate();
panel.repaint();
Without a proper SSCCE we can't really tell what your code is doing.
If you do add/remove/replace/others actions with components on showing container, you must to revalidate and repaint your container, to which you add components for proper displaying.
I am working on a Flex mobile Application and I am using s:List defined in actionscript component with MXML renderer.
In my sView:
var movieList:List = new List();
private function created(event:FlexEvent):void
{
movieList.itemRenderer = new ClassFactory(MovieRenderer);
movieList.dataProvider = new ArrayList();
movieList.useVirtualLayout = false;
movieList.pageScrollingEnabled = true; // if this is omitted scroll bar is invisible
this.addElement(movieList);
}
After HTTPService call is returned:
private function movieDataReady(event:events.ExternalDataEvent):void{
movieList.dataProvider.addItem(event.result);
}
Each event.result item is a custom Object.
The issue is that the scroller seems to be the full height of the list as opposed to the view/screen. This renders it useless as you cannot scroll. If you try it does scroll but goes back as soon as you release. Scroller seems to be about the height of the combined height of all list items.
I had it working before but I made some changes and can't figure out what I am missing this time.
I have MXML s:View component that consists of action bar and 3 custom components that are 100% application width. I added a scroller like so:
section = new VGroup();
var scroller:Scroller = new Scroller();
scroller.percentHeight = 100;
scroller.viewport = section;
What happens is that I get both vertical and horizontal scroll bars. I want to remove the horizontal scrollbar. The horizontal scrollbar appears to be barely wider than the width of the application. As far as I see my content does not exceed application width.
How can I get rid of the horizontal scroll bar?
All you should have to do is set the horizontalScrollPolicy style to ScrollPolicy.OFF:
In Actionscript, you set styles using the setStyle() method:
section = new VGroup();
var scroller:Scroller = new Scroller();
scroller.percentHeight = 100;
scroller.viewport = section;
scroller.setStyle("horizontalScrollPolicy", ScrollPolicy.OFF);
In MXML, you just pass in a string that the ScrollPolicy class defines:
<s:Scroller horizontalScrollPolicy="off">
<s:VGroup>
</s:VGroup>
</s:Scroller>
I was playing around with ScrollPane options in order to disable the wheel scroll functionality of the vertical bar. Tried myScrollPane.mouseEnabled = false;, myScrollPane.mouseWheelEnabled = false; with no luck. Also, myScrollPane.verticalLineScrollSize = 0; also did not seem to result in desired effect.
Okkkk this should be what you're looking for!
myScrollPane.addEventListener(MouseEvent.MOUSE_WHEEL, disableScroll, true);
function disableScroll(e:MouseEvent):void
{
e.stopPropagation();
}
I'm using the last Flex 4 sdk Hero.
i setup a classic List component with InteractionMode="Touch". Thus, my vertical scroll bar is not visible until i drag the list ,which is normal.
My customer ask me to add some "page down" button on the list. I've done it as follow, which work perfectly :
private function handleDownButton(event:*):void {
var currentPosition:Number = wcList.scroller.viewport.verticalScrollPosition;
var nextPosition:Number = currentPosition+((wcList.dataGroup.layout) as VerticalLayout).getVerticalScrollPositionDelta(NavigationUnit.PAGE_DOWN);
var anim:Animate = new Animate(wcList.scroller.viewport);
anim.motionPaths = new <MotionPath>[
new MotionPath("verticalScrollPosition")];
anim.motionPaths[0].keyframes = new <Keyframe>[
new Keyframe(0), new Keyframe(500, nextPosition)];
anim.play();
if ((nextPosition+wcList.height)>=wcList.scroller.viewport.contentHeight) {
buttonDown.enabled=false;
}
buttonUp.enabled = true;
}
My big problem is that my customer also want the vertical scroll bar to be visible during the animation, but i can't find a solution for this (wcList.scroller.verticalScrollBar.visible = true don't work at all).
Any idea of how doing this?
Thanks.
A hack that might work for you...
http://flexponential.com/2011/06/21/using-drag-and-drop-with-a-spark-list-in-a-mobile-flex-application/