Set TitledPane height in JavaFX - java

I have a JavaFX application using gradle. I have used an Accordion as container for my TitledPane for my menu. The problem is that I can't set the TitledPane height according to sum of it's content height.
For example TitledPane 1 has 3 button inside:
So I set the height manually. But for TitledPane 2 I need to set height exactly for 1 button and remove extra blank spaces:
How could I do that? By the way the button border of Accordion gets disappear when I expand any TitledPane. My tress structure of Accordion is:
I have tried using css like:
.accordion .titled-pane {
-fx-fit-to-height: true;
}
or:
.accordion .titled-pane {
-fx-fit-to-height: true;
}
or some other css codes.

Related

Problem with Translucent Navigation bar in Android

I'm using Translucent Navigation bar by adding below attribute to make my app mobile nav menu looks like some Google apps where mobile nav bar is a bit transparent and content will visible through it.
<item name="android:windowTranslucentNavigation">true</item>
But my output is it
I don't want my views to go under it. I just need it when there is More content to scroll on screen like when there is a scrolling activity or in recyclerview. But at the end I need my activity views to not overlap by it.
Any suggestions please...
You may need to apply insets to have space between bottom of the device and navigationbar. RootView is the top layout on xml file.
rootView.setOnApplyWindowInsetsListener { view, insets ->
recyclerview.run {
setPadding(paddingLeft,paddingTop,paddingRight, insets.systemWindowInsetBottom)
}
insets
}
With this snippet you will have transparent navigationbar but your RecyclerView will always be above navigationBar.
And add
android:clipToPadding="false"
flag, this works with RecyclerView, and other scrollable views i guess.
You can check out this medium article or Chris Bane's tivi app to get familiar with insets.
Also put an example on github
What you could try for a static view is:
android:layout_marginBottom="?android:attr/actionBarSize"
If in a ScrollView this obviously won´t work but you can still try to play around wiht different layers inside the xml and fit a margin or padding if needed.
Otherwise it might be helpful if you post your xml file to actually see what you try to implement.
It is possible in both ScrollView and Recyclerview.
If there is scrollview in your Xml file then you should create
two other layout(ex: LinearLayout1 as Scrollview child Layout and
LinearLayout2 as LinearLayout1 child Layout) as a child layouts and
set bottom margin in the Secode child layout(LinearLayout2) same as
your bottom navigationBar height.
Well, here is the example how you can get bottom navigationBar height.
public int getNavigationBarHeight()
{
boolean hasMenuKey = ViewConfiguration.get(getApplicationContext()).hasPermanentMenuKey();
int resourceId = getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0 && !hasMenuKey)
{
return getResources().getDimensionPixelSize(resourceId);
}
return 0;
}
Note: The height of the navigationBar is in px. So, you have to set margin of your child layout in px.
For Recyclerview, you can give bottom margin(RunTime) of parent
layout in adapter class for the last item of the recyclerView
same as navigationBar height.
Example:
if (position==adapter_dueModelList.size()-1){// the list item
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
);
params.setMargins(0, 0, 0, 132);//give margin same as a navigationBar height.
((ViewHolder) holder).linear_layout.setLayoutParams(params);
}

How to change color of selected RadioButton in JavaFX [CSS]?

I just want to change the color of the fill circle on a RadioButton. Surprisingly I couldn't find this in documentation. Is it possible?
I found this similar thread with a solution that is not working for me: CSS Change radio button color in JFXRadioButton
Here is how I have tried it (also tried other variations to no avail):
.radio-button .radio {
-fx-selected-color: yellow;
-fx-unselected-color: blue;
}
-jfx-selected-color and -jfx-unselected-color are not defined in JavaFX. They are attributes from JFoenix (docs). Also -fx-selected-color and -fx-unselected-color are not available in JavaFX.
To change the color of the dot in the RadioButton you can use the :selected pseudoclass like this (docs):
.radio-button:selected .radio .dot {
-fx-background-color: red;
-fx-background-insets: 0;
}
Additionally to the -fx-background-color you should set -fx-background-insets: 0;, because otherwise the dot is not exactly in the center anymore.
The result will look like this:

Vaadin HybridMenu shift with scrollpanel

I want to add scrollbar to my web app so I can see every components on my browser.
Red rectangle in picture below is Grid. Grid is placed inside class that extends VerticalLayout and implements View.
Green color shows my scrollbar which is added to HybridMenu instance.
HybridMenu root = HybridMenuBuilder.get()
.setContent(new VerticalLayout())
.setMenuComponent(EMenuComponents.LEFT_WITH_TOP)
.setConfig(menuConfig)
.build();
root.addStyleName("scrollpanel");
root.setSizeFull();
super.setContent(root); //class extends UI
scrollpanel definition in css:
.scrollpanel > div {
overflow: auto !important;
}
When I reduce height of browser window, menu bar is also being scrolled:
I tried to set scrollbar to VerticalLayout, but it seems like id didn't capture that grid was partly hidden. (I've setted everything in VerticalLayout to full size - How to add scrollbar to Vaadin layout)
//extends VerticalLayout implements View
private void init()
{
this.addStyleName("scrollpanel");
this.setSizeFull();
this.setMargin(false);
grid.setSizeFull();
this.addComponentsAndExpand(grid);
this.setExpandRatio(grid, 0.7f);
this.setComponentAlignment(grid, Alignment.TOP_LEFT);
}
Generally I found some not expected (at least for me) behaviour of components in VerticalLayout. They acts differently according to Layout root
(Example with VerticalLayout as root).
Questions:
How can I avoid hiding part of hybrid menu when scrolling?
Am I missing something about adding scroll panel to this VerticalLayout?
#Edit:
I found that this problem doesn't occurs if HybridMenu content is not fullSized or content is not set.
On the other hand scrollbars are not available without it.
So, creating HybridMenu the way that code below shows, solves problem with scrollpanels, but restores previous problem (layout type doesn't change anything).
AbsoluteLayout test = new AbsoluteLayout();
test.setSizeFull();
HybridMenu root = HybridMenuBuilder.get()
.setContent(test)
.setMenuComponent(EMenuComponents.LEFT_WITH_TOP)
.setConfig(menuConfig)
.build();

JavaFX change color of ImageView

Hello i'm trying to change the color of an ImageView when your mouse is on it(hover)
So I have a css file that contains this:
.cross:hover {
-fx-background-color: red;
}
And this is cross:
#FXML
private ImageView cross;
I set the fx:id in the fxml file.
Now nothing happens when I hover over it.
This is how I add the style sheet to the scene:
scene.getStylesheets().add(getClass().getResource("Style.css").toExternalForm());
This is how I set the id for css on the ImageView:
cross.getStyleClass().add("cross");
So how would I change the color of the ImageView when I hover over it?
The color of an ImageView is defined by the pixel data in the image itself. You probably need to create (externally) an alternative image with the "background" changed to red, and then use the -fx-image CSS property of ImageView to change the image displayed:
.cross {
-fx-image: url(images/cross.png);
}
.cross:hover {
-fx-image: url(images/red-cross.png);
}
where the images folder has the same parent folder as the CSS file (see CSS docs on URL.)

Binding prefWidthProperty of ListView to widthProperty of containing AnchorPane breaks resizing of AnchorPane

I have a TabPane which contains two Tabs and is set up in FXML. On initialization I dynamically add an AnchorPane to one of the Tabs. I then set a ListView as a child of the AnchorPane:
AnchorPane questionPane = new AnchorPane();
questionPane.setId("questionPane");
ListView questionList = new ListView();
questionPane.getChildren().add(questionList);
This works perfectly fine. For debugging purposes I gave the AnchorPane an orange background (via CSS) and when I now resize the window, the AnchorPane get's resized as expected.
But as soon as I add the following line to the code, the AnchorPane can only grow and doesn't shrink anymore, resulting in outsizing my window:
questionList.prefWidthProperty().bind(questionPane.widthProperty());
Can anyone please explain, why this line breaks the resizing of the AnchorPane?
Most likely you didn't specify the anchoring of the ListView:
AnchorPane.setBottomAnchor(questionList , 8.0);
AnchorPane.setRightAnchor(questionList , 5.0);
AnchorPane.setTopAnchor(questionList , 8.0);
AnchorPane.setLeftAnchor(questionList , 5.0);
The binding is not needed anymore.

Categories

Resources