Resetting scroll bar in JavaFX on button click - javafx-2

I have used two scroll bars for controlling brightness and contrast on image after the use i want to reset the scroll bars to their initial value with a button click
I am not getting any links for that to reset scroll bars on button clicks in JavaFX?

The question somewhat unclear. Need explanation of "not getting any links". Some sample code would be helpful. Based on an assumption, try this:
final ScrollBar scrollBar = new ScrollBar();
Button btn = new Button("Reset");
btn.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
scrollBar.setValue(scrollBar.getMin());
// Or if you have stored initial value somewhere use it
scrollBar.setValue(myInitialValue);
}
});

Related

Android: Custom bottom sheet dialog

How can I implement following design functionality with android standard component bottom sheet:
Image when Bottom sheet dialog fragment will appear:
Image when user scrolled to up to view bottom of content:
I will use ViewPager to scrolling header images and RecyclerView to showing descriptions and other informations. And parallax effect to ImageView(which are placed in ViewPager) when scrolling content vertically. Have a minimum height of the ImageView(and ViewPager), user can't collapse fully it (Look to second screenshot, which is user scrolled until the end of content).
I want stop scrolling ImageView when it will reach to minimum height(look to second one Screenshot), but the content of below ImageView should be continue scrolling
This can be done with an if statement in an on scroll view such as shown below:
ScrollView scrollView = findViewById(R.id.scrollView); //Adjust for your code
ImageView imageView = findViewById(R.id.imageView); //Adjust for your code
boolean imageIsHidden = false;
int threshold = 250;
scrollView.getViewTreeObserver().addOnScrollChangedListener(new OnScrollChangedListener() {
#Override
public void onScrollChanged() {
int scrollY = rootScrollView.getScrollY();
if(scrollY >= threshold){
imageIsHidden = true;
//Move image outside of scroll view so it doesn't scroll
}
else if(scrollY < threshold && imageIsHidden){
imageIsHidden = false;
//Move image inside of scroll view so it does scroll
}
}
});
What this does is has a boolean called imageIsHidden and an integer called threshold. Threshold is where you want it to make it disappear. You will need to play around with this value to find a sweet spot.
You will also need to implement moving the image inside and outside of the scroll view as well in the if and if else statement.

Layout snaps to visible (first time only) instead of slide animation

I'm creating a 2 row info bar in the bottom of the screen.
At first only the top row will be visible.
Press an 'expand' button, the 2nd row will slide up from
below. Now both the rows are visible.
Pressing same button again, the bottom row slides down, and
only the 1st row is visible.
This scenario is very common, and after checking different implementations, I've come to this simple one which works almost perfectly:
2 layouts in 1 > make bottom GONE > onClick - make bottom VISIBLE and apply slide up on entire Bar > onClick - apply slide down on Bar and make bottom GONE
Below is the onClick code:
mInfoBar = (RelativeLayout) mRootView.findViewById(R.id.infoBar);
mInfoBottomRow = (RelativeLayout) mRootView.findViewById(R.id.infoBottomRow);
mBtnExpand.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mInfoBottomRow.getVisibility() == View.GONE) {
mInfoBottomRow.setVisibility(View.VISIBLE);
TranslateAnimation slideUp = new TranslateAnimation(0, 0, mInfoBottomRow.getHeight(), 0);
slideUp.setDuration(200);
mInfoBar.startAnimation(slideUp);
} else {
TranslateAnimation slideDown = new TranslateAnimation(0, 0, 0, mInfoBottomRow.getHeight());
slideDown.setDuration(200);
slideDown.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationEnd(Animation animation) {
mInfoBar.clearAnimation();
mInfoBottomRow.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationStart(Animation animation) {
}
});
mInfoBar.startAnimation(slideDown);
}
}
});
The problem is, the very first time the button is pressed, the info bar (with both top and bottom row) snaps to its position (without the sliding effect).
All other subsequent button press works perfectly...
2nd press - the bar slides down to show the top bar resting on the bottom of the screen and the bottom row gone.
3rd press - the bar slides up to show both top and bottom row.
and so on...
Can't understand why setVisibility(VISIBLE) is snapping to view only first time, or why the sliding effect is not showing the first time.
I'd rather not change the animation implementation since it's giving me desired effect all but once.
So any insight within this will be really appreciated.
Your hiddenView's height is 0 for the first time as far as i guess. You should make visible your hiddenView in your layout.
use
android:visibility="visible"
instead of
android:visibility="gone"
in your hiddenView.
Get the height and make it gone by following code:
hiddenView.getViewTreeObserver().addOnGlobalLayoutListener(
new ViewTreeObserver.OnGlobalLayoutListener(){
#Override
public void onGlobalLayout() {
height = hiddenView.getHeight();
hiddenView.getViewTreeObserver().removeGlobalOnLayoutListener( this );
hiddenView.setVisibility( View.GONE );
}
});
Use this height to animate.. :)

How can I add button to top right corner of a Dialog In libgdx?

I want to add close button to top right corner of a dialog box.
I tried using setbounds with addactor and just add and setposition with setsize and addactor, but nothing works. I know that dialog works with table layout, it has a table for content and for buttons. I don't want to use this layout and put the button outside this layout like on the border of the dialog.
How can I do it?
This is how it should be:
The easiest solution I could come up with now, is to use negative padding for your button to move it "outside" of it's cell.
Button closeButton = new TextButton("X", skin, "default");
getTitleTable().add(closeButton).size(60, 40).padRight(-30).padTop(-20);
With this padding hack you have the problem, that the button will be outside of your Dialog, and by default, Window checks the bounds of your window when it performs Actor.hit(...) evaluation.
We need to disable clipping for that reason, but the rendering of the window depends on it. That's why we use another hack to enable it, just for the rendering:
#Override
public void draw(Batch batch, float parentAlpha) {
setClip(true);
super.draw(batch, parentAlpha);
setClip(false);
}
Do this:
private Stage stage;
private Window window;
private Table table;
#Override
public void show() {
table = new Table();
table.setSize(Gdx.graphics.getWidth() / 2
, Gdx.graphics.getHeight() / 5);
window = new Window("", skin);
window.setSize(table.getWidth(), table.getHeight());
Button btnWindow = new Button(skin, "close");
btnWindow.addListener(new ClickListener() {
#Override
public void clicked(InputEvent event, float x, float y) {
window.setVisible(false);
}
});
window.addActor(btnWindow);
btnWindow.setSize(50, 50);
btnWindow.setPosition(window.getWidth() - btnWindow.getWidth()
, window.getHeight() - btnWindow.getHeight());
table.addActor(window);
window.setModal(true);
table.setPosition(Gdx.graphics.getWidth() / 2 - window.getWidth() / 2
, Gdx.graphics.getHeight() / 2 - window.getHeight() / 2 +
100);
window.addAction(Actions.sequence(Actions.alpha(0)
, Actions.fadeIn(.1f)
, Actions.moveTo(+50, +50, 1)));
stage.addActor(table);
}
I had a similar problem. After a bit of searching this thread helped me.
Basically to tell the alignment of the actors inside a table, and to tell the alignment of the table itself are two separate things. Setting the alignment of the table top top-left would produce the desired behavior.
table = new Table();
table.setFillParent(true);
table.setSkin(usedSkin);
table.setDebug(true);
table.top().left();
stage.addActor(table);
table.add(exitBtn);

SmartGWT Dialog setting Height for dynamix text

Here's the deal, im trying to create a popup window that uses a dynamic text,
when the text is too large i would like to cap the height of the window and
use a scrollbar instead to navigate through it but it does not seems to be
working.
code:
final Dialog dialog = new Dialog();
dialog.setMessage(direttivaDescription);
dialog.setOverflow(Overflow.AUTO);
dialog.setWidth(600);
dialog.setHeight(50);
dialog.setIcon(someIcon);
dialog.setButtons(new Button("OK"));
dialog.addButtonClickHandler(new ButtonClickHandler() {
public void onButtonClick(ButtonClickEvent event) {
dialog.hide();
}
});
dialog.draw();
If the text is too large the window height will be resized accordingly. The funny
part is that setWidth method seems to be working just fine.
You need a container such as HLayout, VLayout, DynamicForm etc. where you can add the message in it then finally add the container in the Dialog.
Sample code:
VLayout vLayout=new VLayout();
vLayout.addMember(new Label(message));
vLayout.setOverflow(Overflow.AUTO);
vLayout.setWidth100();
...
dialog.addItem(vLayout);
dialog.draw();
snapshot:

GXT: UiBinder new instance of a Widget

I have a TextField form inside a window. Created with UiBinding. Next to the TextField is a button. I wanted to know if it was possible to create a new TextField widget when that button was pressed using UiBinder?
This is what I have:
Window class:
#UiField
TextField text;
#UiField
HorizontalPanel hPanel;
....
#UiHandler("addText")
public void onClick(SelectEvent event){
hPanel.add(text);
}
My UiBinder file:
<gxt:Window ...(generic setup)...>
<g:VerticalPanel>
<gxt:FramedPanel>
<container:VericalLayoutContainer>
<container:child>
<g:HorizontalPanel ui:field="hPanel">
<form:FieldLabel text="Text">
<form:Widget>
<form:TextField ui:field="text"/>
</form:Widget>
</form:FieldLabel>
<button:TextButton ui:field="addText"/>
</g:HorizontalPanel>
</container:child>
</container:VericalLayoutContainer>
</gxt:FramedPanel>
</g:VerticalPanel>
</gxt:Window>
When I click the button it all it does is move the button from the right side of the text field to the left. I have more textfields in the window so I played around to see what it was really doing. It's taking that field and just moving it next to the button.
Is there a way I can create a new TextField underneath the original?
Probably LazyDomElement will help you.

Resources