I want to make the border of a borderpane more round and bold.
I tested this code:
bpi.setStyle("-fx-background-color: linear-gradient(to bottom, #f2f2f2, #d4d4d4);"
+ " -fx-border: 12px solid; -fx-border-color: white; -fx-background-radius: 15.0;"
+ " -fx-border-radius: 15.0");
I get this result:
How I can fix this?
Why your current approach doesn't work
Don't use -fx-border (it doesn't even currently exist in JavaFX CSS).
Though there are other fx-border-* attributes such as -fx-border-color, -fx-border-width and -fx-border-radius, I wouldn't recommend them either.
Suggested Approach
Instead, use a combination of layered attributes:
-fx-background-color
-fx-background-insets
-fx-background-radius
You can find documentation on these CSS attribute features in the JavaFX CSS reference guide.
Although using -fx-background-* attributes for a border seems strange:
It is the way that all of the borders in the default JavaFX modena.css stylesheet are handled.
In my experience, when borders are rounded, applying borders in this way is simpler and gives better results than using -fx-border-* attributes.
Sample Code
For instance, here is an example fxml file which applies the standard modena.css style attribute values for "button like things" to a BorderPane. (modena.css comes from Java 8).
You can copy and paste the fxml and css, then load them up in SceneBuilder to see what it looks like.
button-like.css
.button-like {
-fx-background-color:
-fx-shadow-highlight-color,
-fx-outer-border,
-fx-inner-border,
-fx-body-color;
-fx-background-insets: 0 0 -1 0, 0, 1, 2;
-fx-background-radius: 3px, 3px, 2px, 1px;
}
button-like.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.paint.*?>
<?scenebuilder-stylesheet button-like.css?>
<AnchorPane id="AnchorPane" maxHeight="-Infinity" maxWidth="-Infinity"
minHeight="-Infinity" minWidth="-Infinity" prefHeight="131.0"
prefWidth="196.0" xmlns:fx="http://javafx.com/fxml/1"
xmlns="http://javafx.com/javafx/2.2">
<children>
<BorderPane layoutX="48.0" layoutY="26.0" prefHeight="79.0" prefWidth="100.0"
styleClass="button-like"
/>
</children>
</AnchorPane>
Note
You wouldn't actually want to apply the above exact style in your application for styling something like a BorderPane, as that is not a "button like thing". Using the same styling for something that is not a button would confuse the user. But the sample approach should demonstrate the general idea on layering backgrounds to achieve the style you want.
Additional Example
This example uses the same FXML layout file defined above, just a different stylesheet to achieve a different style.
AnchorPane {
-fx-background-color: #232732;
}
.button-like {
-fx-outer-border: white;
-fx-body-color: linear-gradient(to bottom, #FAFAFA, #EAEAEA);
-fx-background-color:
-fx-outer-border,
-fx-body-color;
-fx-background-insets: 0, 6;
-fx-background-radius: 6px, 0px;
-fx-background-image: url('http://icons.iconarchive.com/icons/appicns/simplified-app/64/appicns-Chrome-icon.png');
-fx-background-repeat: no-repeat;
-fx-background-position: center;
}
/**
Icon license: Free for non-commercial use.
Icon license Commercial usage: Not allowed
Icon source: http://appicns.com
*/
Related
We are having an issue with Extension Library "listInline" command gives us a vertical instead of a horizontal list in Xpages. Below is the code and a snap shot of the issue:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:label value="Here is an inline list:" id="label4"></xp:label>
<xe:listInline id= "listInline1">
<xp:link escape= "true" text= "Link 1" id= "label1"></xp:link>
<xp:link escape= "true" text= "Link 2" id= "link2"></xp:link>
<xp:link escape= "true" text= "Link 3" id= "link3"></xp:link>
</xe:listInline>
</xp:view>
Gives us
Here is an inline list:
Link 1
Link 2
Link 3
Instead of the links going across the page.
Link 1 Link 2 Link 3
It shows entries in vertical list if you use theme "Bootstrap4".
Add following css to get a horizontal list:
.lotusInlinelist li {
border-left: 1px solid #CCCCCC;
display: inline;
margin: 0;
padding: 0 7px;
}
As an alternative, you could switch to another theme like "Bootstrap3".
First question is: do I really need to use tables to align/organize labels/fields on my xPage?
It's like old style development (using hidden tables) that helps group components on the form/page.
Anyway I just switched from Notes 8 to Notes 9 and apply Bootstrap 3 theme. Now all tables have top border I cannot remove. It's something weird. Even my own class doesn't remove the border.
table, th, td {
border-collapse: collapse;
}
Moreover if I try to set border size/color it works only for left,righ and bottom. If I set border size 2px then it sets the color for top border as well
table, th, td {
border: 1px solid black;
}
So how do I remove tables borders on my page. See picture below
Add the following lines to your CSS:
.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td,
.table>tbody>tr>td, .table>tfoot>tr>td {
border-top: 0px;
}
You don't need a table to align label and field. Use style "display:inline-block" and set an appropriate width:
<xp:label
value="Label1"
id="label1"
for="inputText1"
style="width:20%;display:inline-block;">
</xp:label>
<xp:inputText
id="inputText1"
value="#{sessionScope.input1}"
style="width:75%;display:inline-block;">
</xp:inputText>
Use separate classes for label and fields with those styles to set the same align to all label/fields in your application.
If you move to a Bootstrap theme you would not need the tables for alignment plus you would be creating a responsive design that could adapt to mobile devices.
My Mathjax code looks fine on the computer but oversized on mobile: http://teach.sg/mathematics/additional-mathematics/trigonometric-functions/
Any way to resize this automatically for mobile?
Note: I am using safari on iPhone 6. Chrome gives me the same result.
I hope this simple solution will fit to you:
Just add overflow-x: scroll; to div's style that containing MathJax equation. It will make your MathJax equation scroll-able, and prevent going equation out of range.
In your example it is a div with
id="std-body-box-2864" style="color:#000000; border-top-color: #56b5ff; border-left-color: #56b5ff; border-right-color: #56b5ff; border-bottom-color: #56b5ff; background-color: #ffffff;".
Add overflow-x: scroll; at the end of style tag :
style="color:#000000; border-top-color: #56b5ff; border-left-color: #56b5ff; border-right-color: #56b5ff; border-bottom-color: #56b5ff; background-color: #ffffff; overflow-x: scroll;".
It will add a scroll at the bottom of the div. MathJax equation will stay in the "Special Angles" box.
Raw preview :
Actually there can be many solutions(including smart ones using jQuery), you can find appropriate one by googling "responsive tables in html". MathJax is using <span>, it's not actually the tables, but I hope that will help.
In this answer I found a better solution to this problem:
.MathJax_Display, .MJXc-display, .MathJax_SVG_Display {
overflow-x: auto;
overflow-y: hidden;
}
I'm using css to change the default font size of TableView controls.
My problem is that when the font size is changed also changes the scrollbar width (it looks thinner as the font size is decreased).
I'd like to change the TableView's font size maintaining the default scrollbar width.
My css file:
.table-view {
-fx-font-size: 10px;
}
There is an issue on that http://javafx-jira.kenai.com/browse/RT-20922
You could try specify -fx-font-size for the scroll bar directly in the css like this:
.table-view > .virtual-flow > .scroll-bar {
-fx-font-size: 10pt;
}
You could also refer to caspian.css inside jfxrt.jar to see other possible solutions.
I found a solution styling the table rows only, instead of the whole tableview.
.table-row-cell {
-fx-font-size: 10px;
}
.table-view .scroll-bar:vertical > .increment-button,
.table-view .scroll-bar:vertical > .decrement-button {
-fx-padding: 0.5em 0.5em ;
}
This can help with the scrollbar width, make it wider.
I am looking for a way to say set a maxWidth size to 80% in FXML.
Much like in web development.
<VBox fx:id="testVB" prefWidth="600">
But this does not:
<VBox fx:id="testVB" prefWidth="80%">
I know that in Straight JavaFX2 non-fxml you can create insets? What is the best way to do this outside of code in FMXL?
Thanks!
Riley
I'm not sure you can. You need to use the GridPane layout component. In this component, you can specify rows and columns constraints, and in these constraints you can specify a width as a percentage. For example:
<GridPane>
<children>
<TitledPane text="testGridPane" GridPane.columnIndex="0" GridPane.rowIndex="0" />
</children>
<columnConstraints>
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="80.0" prefWidth="100.0" />
<ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" percentWidth="20.0" prefWidth="100.0" />
</columnConstraints>
<rowConstraints>
<RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
</rowConstraints>
</GridPane>
This code defines a GridPane with a first column with a width of 80%. The TitledPane is set in the first cell of the first column of this GridPane, and can (because you need to be sure that the width constraints of the TitledPane match your needs) occupy 80% of the width of the GridPane.
Please note that I removed all information not relevant to your question. By the way, Oracle's Scene Builder tool is very useful to define complex FXML layout.
It seems like many answers have already been provided and they should work. However, there is a way to set percentages:
<fx:define>
<Screen fx:factory="getPrimary" fx:id="screen" />
</fx:define>
This would help you detect the dimensions of the current screen, the application is being displayed on. Now that we have the display dimensions, we can play with it in FXML as follows:
<HBox fx:id="hroot" prefHeight="${screen.visualBounds.height}" prefWidth="${screen.visualBounds.width}"> Your FXML elements inside the root... </HBox>
Note that I use visualBounds, since this would get me the available space on the screen, since I don't want an overlap with the taskbar in Windows for example. For fullscreen applications, you would just use 'bounds'.
Now, to come to your point of using percentages, you can actually play with the value of the prefheight and prefWidth. You can put calculations inside the ${}.
Optionally:
If you want to have all your elements use relative sizes, just refer to them, using their ID and width or height property, and make your calculation.
<VBox fx:id="VBSidebar" prefWidth="${hroot.width*0.15}" prefHeight="${hroot.height}"> more elements.. </VBox>
Hope this helps!
You can simulate it - basic example that simulates 50% for two cols in an HBox. You can add dummy panes to get thirds, etc.
HBox {
VBox {
static hgrow : "ALWAYS",
Label {
text : "Privacy",
alignment : "CENTER",
styleClass : ["h2", "heading"]
}
},
VBox {
static hgrow : "ALWAYS",
Label {
text : "Messages",
alignment : "CENTER",
styleClass : ["h2", "heading"]
},
Label {text:""}
}
}