Scroll 2 listview at same time - java

In my JavaFX project I was using 2 TextFlows to display some text. I used vvalueProperty of ScrollPanes which are holding the TextFlows to scroll both TextFlow at same time
scrolPane1.vvalueProperty().bindBidirectional(scrolPane2.vvalueProperty());
But since TextFlow is only support in Java 8, Im trying to replace them with ListView.
How can I scroll 2 ListViews at same time? Since ListView contains a inner ScrollPane my approach that worked with TextFlow doesn't work here.
Simply I want to scroll 2 ListViews at same time.

Try something like
Platform.runLater(new Runnable() {
#Override
public void run() {
Node n = listView1.lookup(".scroll-bar");
if (n instanceof ScrollBar) {
final ScrollBar bar = (ScrollBar) n;
if (bar.getOrientation().equals(Orientation.VERTICAL)) {
// get the second scrollbar of another listview and bind values of them
}
}
}
});

Related

adding text box on top of gwt java

I am currently working on a school project where we are creating a GWT web application which uses a GeoChart widget to display information about the servers we have crawled. Simply put, I would wish to create a text box on top of our GeoChart widget which shows an interactive world map that takes up the whole screen right now to input information. I have searched quite extensively but I have been unable to come up with an answer.
Here is the code as follows:
#Override
public void onModuleLoad() {
dataReader = (DataReaderAsync) GWT.create(DataReader.class);
RootLayoutPanel.get().add(getSimpleLayoutPanel());
// Create the API Loader
ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
chartLoader.loadApi(new Runnable() {
#Override
public void run() {
getSimpleLayoutPanel().setWidget(getGeoChart());
drawGeoChart();
}
});
}
As GeoChart is a widget, it is wrapped under(i am not sure if this is the right word) a SimpleLayoutPanel right now which will display it into a full screen. As stated above, I would wish to include text above the geoChart. From my understanding, I would need to create another widget containing my text and add both the GeoChart widget and the text box widget into it. What would be the best way to go about doing this?
I believe DialogBox could solve your problem. People usually program the DialogBox in a way that it only pops up into display when certain event is triggered and disappears after user finishes some operation. In your particular case, you can simply make the DialogBox shows up from the beginning and never disappears. And the best part of it: you don't need to add the DialogBox widget to the geoChart widget. Calling dialogBox.center() or dialogBox.show() will do the magic for you.
Here is the sample code.
#Override
public void onModuleLoad() {
dataReader = (DataReaderAsync) GWT.create(DataReader.class);
RootLayoutPanel.get().add(getSimpleLayoutPanel());
// Create the API Loader
ChartLoader chartLoader = new ChartLoader(ChartPackage.CORECHART);
chartLoader.loadApi(new Runnable() {
#Override
public void run() {
getSimpleLayoutPanel().setWidget(getGeoChart());
drawGeoChart();
}
});
// NOTE: the first argument 'false' makes sure that this dialog box
// will not disappear when user clicks outside of it
// NOTE: the second argument 'false' makes sure that mouse and keyboard
// events outside of the dialog box will NOT be ignored
DialogBox dialogBox = new DialogBox(false, false);
DialogBox.setText("Demo");
HorizontalPanel panel = new HorizontalPanel();
panel.setSpacing(5);
InlineLabel labelOfTextBox = new InlineLabel("Label");
TextBox textBox = new TextBox();
panel.add(labelOfTextBox);
panel.add(textBox);
dialogBox.setWidget(panel);
// show up in the center
dialogBox.center();
}
Dear all thanks for answering my question. To rectify this problem, I have made use of the custom widget API within GWT(known as Composite). Here's the code as below:
private static class CombinedWidget extends Composite {
public CombinedWidget() {
// place the check above the text box using a vertical panel.
VerticalPanel panel = new VerticalPanel();
DockLayoutPanel dPanel = new DockLayoutPanel(Unit.EM);
panel.setSpacing(13);
panel.add(nameProject);
nameProject.setStyleName("gwt-Group-Label");
panel.add(className);
panel.add(nameKs);
panel.add(nameEsmond);
panel.add(nameBowen);
panel.add(nameAaron);
dPanel.addWest(panel, 13);
dPanel.add(getGeoChart());
// all composites must call initWidget() in their constructors.
initWidget(dPanel);
setWidth("100%");
}
Actually I sort of changed from the original idea. Instead of putting it on the very top, I attached the labels into a VerticalPanel and then created a CombinedWidget(custom widget) which adds both a VerticalPanel and DockLayoutPanel together. I then added the VerticalPanel(containing all the labels) and the GeoChart into the DockLayoutPanel.
This solved my problem of displaying both the labels and the GeoChart on the same page(as originally i added it into a VerticalPanel but it would not work as the app would not read the GeoChart due to the VerticalPanel being overlayed on top of the GeoChart).
If you guys want a picture of my app to visualise, please say so!

JavaFX ScrollPane - speed up swiping effect on touch device

I found that if I swipe within a ScrollPane in a JavaFX application on a touch device, the scroll-animation is quite slow. I do not swipe over the ScrollBar of the ScrollPane but within the content itself.
How can I speed up the swipe animation?
This is a known problem with touch devices and the ScrollPane ;)
If you want to speedup the animation you have to set the position by your own.
I solved the same problem I while ago on this way, worked well.
You need to do something like this:
ScrollPane scrollPane = new ScrollPane();
final IntegerProperty vValueProperty = new SimpleIntegerProperty(0);
final int steps = 5;
scrollPane.vvalueProperty().bind(vValueProperty);
scrollPane.setOnSwipeDown(new EventHandler<GestureEvent>() {
public void handle(GestureEvent event) {
// calculate the needed value here
vValueProperty.set(vValueProperty.get() + steps);
}
});
If the normal swipe animation disturbes you, just kill the event with
event.consume();
But it could be that you need to use an EventFilter in this case cause the EventFilter is called before the Event is doing anything. Can't remember if a consume() at the end of the EventHandler is enough. If not you need to use something like this:
scrollPane.addEventFilter(SwipeEvent.SWIPE_DOWN,
new EventHandler<SwipeEvent>() {
public void handle(SwipeEvent event) {
vValueProperty.set(vValueProperty.get() - steps);
event.consume();
}
});
Well this is just to speedup the animation. If you want your Pane following your finger, just save the first value, which you get OnTouchDetected and calculate the Offset OnTouchMoved. This is your value you can use to translate the Pane correctly. :)
Hope it is useful. I don't have a touch device here to test it.

How to scroll in horizontal scroll view

I have made a scroll view in my app it works fine. I have some buttons on click of button i want to scroll to desired position. How can i achieve this And one last thing how can i end the spaces between i images in grid view so all the photos sick together.
Thanks In Advance.
Try this:
yourScrollView.post(
new Runnable() {
#Override
public void run() {
yourScrollView.scrollTo(desiredPositionX, desiredPositionY);
}
}
);

Java JScrollPane Detect Scroll Near Bottom

I've been unable to find anything related to my question on the Internet.
I have a JScrollPane which adds a JPanel, and the JPanel gets populated with JLabels.
Currently, the user scrolls to the bottom of the JScrollPane, and then clicks the 'Next' button.
What I would like to do is to detect when the user is at/near the bottom of the JScrollPane, so that I can then trigger the 'Next' behaviour without any input from the user.
Is this even possible?
Thanks in advance everyone.
You could use an AdjustmentListener registered with your the vertical scrollbar in your JScrollPane and take action based on the event value.
Here is an example.
JScrollBar uses a BoundedRangeModel, and this will accept a ChangeListener -- so you can listen for changes to the scrollbar and respond accordingly.
Here is an example showing how to trigger an event when the scrollpane is near the bottom (90% of the height):
final JScrollPane scrollPane = new JScrollPane(panel);
scrollPane.getViewport().addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent event) {
JScrollBar scrollbar = scrollPane.getVerticalScrollBar();
if (scrollbar.getValue() + scrollbar.getVisibleAmount() > scrollbar.getMaximum() * 0.9) {
// trigger the 'Next' behaviour here
}
}
});
Alternatively, the listener can also be added to the model:
final BoundedRangeModel model = scrollPane.getVerticalScrollBar().getModel();
model.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent event) {
if (model.getValue() + model.getExtent() > model.getMaximum() * 0.9) {
// trigger the 'Next' behaviour here
}
}
});

JScrollPane - automatically scroll to bottom?

I've been trying to create a a scroll pane that automatically keeps scrolling down as the user adds more lines of text to the window. I implemented this:
pane.getVerticalScrollBar().addAdjustmentListener(new AdjustmentListener() {
public void adjustmentValueChanged(AdjustmentEvent e) {
e.getAdjustable().setValue(e.getAdjustable().getMaximum());
}
});
"pane" is a JScrollPane that is holding a JList.
Unfortunately, the code above sticks the scroll bar to the bottom of the pane (which is what I wanted) but then I am unable to move the scroll bar from its position (so now it's stuck at the bottom). Is there a simple way to have the scroll bar stick to the bottom, but still be able to be scrolled elsewhere?
Thanks!
When you add an item to the JList you can use the method:
list.ensureIndexIsVisible(...)
where the index is the index of the last item in the list.

Categories