In using the FXVK virtual keyboard, I would like to alter the default skin to my own whims. The css tags I found in the source code of JavaFX. These were added to a custom css and loaded as seen below.
public static void setVirtualKeyboardCSS() {
#SuppressWarnings("deprecation")
final Iterator<Window> windows = Window.impl_getWindows();
while (windows.hasNext()) {
final Window window = windows.next();
if (window instanceof PopupWindow) {
if (window.getScene() != null && window.getScene().getRoot() != null) {
Parent root = window.getScene().getRoot();
if (root.getChildrenUnmodifiable().size() > 0) {
Node popup = root.getChildrenUnmodifiable().get(0);
if (popup.lookup(".fxvk") != null) {
if (popup instanceof FXVK) {
FXVK keyboard = (FXVK)popup.lookup(".fxvk") // reference to the vk skin
ObservableList<String> sheets = keyboard.getStylesheets();
sheets.add("#customVK.css");
System.out.println("Setting keyboard stylesheet");
}
}
}
}
}
}
}
When the keyboard is expected to be shown, the call is made to this function and the output is shown that the call has been made. The CSS however does not change the layout. Using keyboard.getScene().getStyleSheets() instead of keyboard.getStyleSheets() also provides no working alternative.
Your code worked a lot for me, but, your error was that you must to call "setVirtualKeyboardCSS" function after the focus event propagates through the app and after the FXVK SubWindow is completely rendered.
public static final int TICK = 5;
public void setTimer() {
timer = new Timer();
timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
Platform.runLater(() -> {
setVirtualKeyboradCss();
});
}
}, TICK, TICK);
}
public void setVirtualKeyboradCss() {
#SuppressWarnings("deprecation")
final Iterator<Window> windows = Window.impl_getWindows();
while (windows.hasNext()) {
final Window window = windows.next();
if (window instanceof Popup) {
String vars = getClass().getResource("/css/variables.css").toExternalForm();
String embed = getClass().getResource("/css/embeded.css").toExternalForm();
FXVK keyboard = (FXVK) window.getScene().getRoot().lookup(".fxvk");
if (keyboard != null) {
if (!keyboard.getStylesheets().contains(embed)) {
keyboard.getStylesheets().addAll(vars, embed);
}
}
timer.cancel();
timer = null;
}
}
}
variables.css
#font-face {
-fx-font-family: "DINPro-Bold";
src: url('/fonts/DINPro-Bold.otf');
}
* {
-color-black: #303030;
-color-white: #FFFFFF;
-color-brownish-gray: #606060;
-color-yellow: #FCB400;
}
embeded.css
.fxvk {
-fx-background-color: -color-brownish-gray;
}
.fxvk .key{
-fx-font-family: "DINPro-Bold", "sans-serif";
-fx-border-image-source: null;
-fx-border-radius: 3;
-fx-background-radius: 3;
-fx-background-color: radial-gradient(center 50% 50%, radius 60%, derive(-color-white, -65%), -color-black);
}
.fxvk .key:hover{
-fx-background-color: -color-yellow;
}
.fxvk-secondary{
}
.shift-icon {
}
.capslock-icon{
}
.shift{
-fx-fill: -color-white;
}
.special {
-fx-fill: -color-white;
}
.backspace{
-fx-fill: -color-white;
}
.enter {
-fx-fill: -color-white;
}
.hide{
-fx-fill: -color-white;
}
.multi-char-text{
-fx-fill: -color-white;
}
.key-text {
-fx-fill: -color-white;
-fx-font-family: "DINPro-Bold", "sans-serif";
}
.key-alttext{
-fx-fill: -color-white;
-fx-font-family: "DINPro-Bold", "sans-serif";
}
.key-icon {
-fx-fill: -color-white;
}
.multi-char-text{
-fx-fill: -color-white;
}
Related
I want to customize the buttons, button container, backgroud color, the AlertType icon as well in an Alert Dialog.
Tried following these two solutions :
Styling default JavaFX Dialogs
Customize JavaFx Alert with css
I suppose the code from CSS that I have mentioned should be applicable to all the Alert dialog-pane ?
Not sure what am I missing here.
private static void createSimpleInformationDialog(String message){
Alert alert = createSimpleInformationAlert(message, AlertType.INFORMATION);
alert.getDialogPane().setHeaderText(StringTools.isNull(null, ""));
alert.getDialogPane().setMaxWidth(200);
alert.getDialogPane().setMinWidth(150);
alert.getDialogPane().setPadding(new Insets(0, 10, 0, 10));
alert.showAndWait();
}
private static Alert createSimpleInformationAlert(String message, AlertType type) {
Alert alert = new Alert(type);
alert.setTitle(Lang.get(Defs.FX_DIALOGS_EXCEPTIONS_GENERIC_TITLE));
alert.setContentText(message);
alert.initModality(Modality.APPLICATION_MODAL);
alert.initOwner(FXMain.getInstance().getStage());
return alert;
}
CSS file :
.dialog-pane{
-fx-border-color:black;
-fx-border-width:2.0px;
}
/**Costumization of The Bar where the buttons are located**/
.dialog-pane > .button-bar > .container {
-fx-background-color:black;
}
.dialog-pane > .content.label {
-fx-padding: 0.5em 0.5em 0.5em 0.5em;
-fx-background-color: yellow;
-fx-text-fill:black;
-fx-font-size:15.0px;
}
/**Costumization of DialogPane Header**/
.dialog-pane:header .header-panel {
-fx-background-color: black;
}
.dialog-pane:header .header-panel .label{
-fx-background-color: yellow;
-fx-background-radius:10px;
-fx-text-fill:black;
-fx-font-size:15.0px;
}
/**Costumization of Buttons**/
.dialog-pane .button{
-fx-background-color:black;
-fx-text-fill:white;
-fx-wrap-text: true;
-fx-effect: dropshadow( three-pass-box, yellow, 10.0, 0.0, 0.0, 0.0);
-fx-cursor:hand;
}
.dialog-pane .button:hover{
-fx-background-color:white;
-fx-text-fill:black;
-fx-font-weight:bold;
}
I am trying to update row background color and text in tableview. But i am able to update only background colour. But i am not able to update text color using -fx-text-fill. Could someone help.
#FXML
private void initialize(){
tablename.setRowFactory(tv -> new TableRow<ClassName>()
{
#Override
public void updateItem(ClassName item, boolean empty)
{
super.updateItem(item, empty);
if (item == null)
{
setText(null);
setStyle("");
}
else
{
if (item.gettest().equals("a") {
setStyle("-fx-background-color: #38ee00; -fx-text-fill: green;");
}
if (item.gettest().equals("b") {
setStyle("-fx-background-color: #efe939; -fx-text-fill: red;");
}
}
}
});
}
The TableView colors the background of it's rows from modena.css which is why you can override this property using inline style. The -fx-text-fill property is set for the TableCells though and therefore the values inherited from the TableRow are not used.
I recommend using a CSS stylesheet yourself and applying a pseudoclass to the rows
final PseudoClass green = PseudoClass.getPseudoClass("green");
tablename.setRowFactory(tv -> new TableRow<ClassName>() {
#Override
public void updateItem(ClassName item, boolean empty) {
super.updateItem(item, empty);
boolean gr = (item != null) && item.gettest().equals("a");
pseudoClassStateChanged(green, gr);
}
});
CSS Stylesheet (needs to be applied to the TableView, an ancestor or the scene)
.table-row-cell:filled {
-fx-background-color: #efe939;
}
.table-row-cell:filled:green {
-fx-background-color: #38ee00;
}
.table-row-cell:filled .table-cell {
-fx-text-fill: red;
}
.table-row-cell:filled:green .table-cell {
-fx-text-fill: green;
}
Firts you need to get the current ROW :
TableRow<CallLogs> currentRow = getTableRow();
After that you can set the colors as you are doing, but in the currentRow:
if (item.gettest().equals("a") {
currentRow.setStyle("-fx-background-color: #38ee00; -fx-text-fill: green;");
}
if (item.gettest().equals("b") {
currentRow.setStyle("-fx-background-color: #efe939; -fx-text-fill: red;");
}
i have a little problem, i'm using Javafx and just put icon in a Text .
So i found this post which could help me :
Colored Icon Font in JavaFX
The solution given by Derek is working but when i try to put my style in a css , it is not working:
#font-face {
src: url(typeface/fontawesome-webfont.ttf);
}
#font-face {
font-family: 'Indie Flower';
src: url(http://fonts.googleapis.com/css?family=Indie+Flower);
}
#font-face {
src: url(typeface/govicons-webfont.ttf);
}
#font-face {
src: url(typeface/fontawesome-webfont.ttf);
}
#font-face {
font-family: "MaterialIcons";
src: url(typeface/MaterialIcons-Regular.ttf);
}
#i {
-fx-font-family: 'Indie Flower';
-fx-font-size: 80;
-fx-fill: forestgreen;
}
#love {
-fx-font-family: "MaterialIcons";
-fx-font-size: 60;
-fx-fill: firebrick;
}
#u {
-fx-font-family: "Indie Flower";
-fx-font-size: 80;
-fx-fill: forestgreen;
}
And then this is my java class where i call everything :
public class Test extends Application {
#Override
public void start(Stage stage) {
System.setProperty("http.proxyHost", "myProxy");
System.setProperty("https.proxyHost", "myProxy");
System.setProperty("http.proxyPort", "myPort");
System.setProperty("https.proxyPort", "myPort");
Text i = new Text("I");
Text love = new Text("\uE87D");
Text u = new Text("you");
u.setId("u");
i.setId("i");
love.setId("love");
i.getStyleClass().add("i");
love.getStyleClass().add("love");
u.getStyleClass().add("u");
TextFlow textFlow = new TextFlow(i, love, u);
textFlow.setStyle("-fx-padding: 20px; -fx-background-color: azure;");
Scene scene = new Scene(textFlow);
final File externalCSSFile = new File("resources/Style.css");
// Get style from external CSS
scene.getStylesheets().add("file:///" +
externalCSSFile.getAbsolutePath().replace("\\", "/"));
stage.setScene(scene);
stage.show();
}
public static void main(String[] args) {
launch(args);
}
}
of courses the files called exist with the correct path .
So if you have any idea with it is not working , pls help me :)
I have problem to add style to button controll from external css file,I trying something like this,example button.getStyleSheets().add(".../... .css");
I trying to select one button controll,not multiple buttons.I think to set style to button from external css file,and I would change code somewhere to works(I can fix that,over ObservableLis list=button.getStyleSheets(); .......) but I can't add external file to button.
//when I click left mouse button,selected them and if I type delete key delete him
else if(e.getButton() == MouseButton.PRIMARY && e.getClickCount() == 1)
{
//Ako se stisne taster delete da se izbrise dobavljac
universal_dobavljac.addEventHandler(KeyEvent.KEY_PRESSED, (ee) ->{
if(ee.getCode() == KeyCode.DELETE)
{
//Potvrda za brisanje dobavljača
ButtonType da=new ButtonType("Da", ButtonBar.ButtonData.OK_DONE);
ButtonType ne=new ButtonType("Ne", ButtonBar.ButtonData.CANCEL_CLOSE);
Alert alert=new Alert(Alert.AlertType.CONFIRMATION,"Da li želite da obrišete "+dob.getNaziv_firme()+ " dobavljača?",da,ne);
alert.setHeaderText(null);
Optional<ButtonType> result=alert.showAndWait();
if(result.isPresent() && result.get() == da)
{
//brisanje iz tilepane
tilePane.getChildren().remove(universal_dobavljac);
//brisanje dobavljaca iz baze
try{
transaction=session.beginTransaction();
session.delete(dob);
transaction.commit();
}
catch(HibernateException ex)
{
if(transaction != null)
{
transaction.rollback();
}
}
Alert alertt=new Alert(Alert.AlertType.INFORMATION);
alertt.setHeaderText(null);
alertt.setContentText("Uspešno ste izbrisali "+dob.getNaziv_firme()+" dobavljača");
alertt.show();
}
}
});
////////////////
//THIS comments bellow don't works -> Path is good,I check at least hundred times
//universal_dobavljac.getStylesheets().add(getClass().getResource("Finansije/Dobavljaci/kada_je_selektovan_dobavljac.css").toExternalForm());
universal_dobavljac.setStyle("-fx-font-weight: bold; -fx-font-size: 36px; -fx-font-family: Book Antiqua; -fx-pref-width: 303px; -fx-pref-height: 230px; -fx-background-image: url(\"Finansije/icon_hover.png\"); -fx-background-color: transparent; -fx-cursor: hand");
universal_dobavljac.addEventHandler(MouseEvent.MOUSE_EXITED,(event) ->{
//universal_dobavljac.getStylesheets().add(getClass().getResource("Finansije/Dobavljaci/kada_je_selektovan_dobavljac.css").toExternalForm());
universal_dobavljac.setStyle("-fx-font-weight: bold; -fx-font-size: 36px; -fx-font-family: Book Antiqua; -fx-pref-width: 303px; -fx-pref-height: 230px; -fx-background-image: url(\"Finansije/icon_hover.png\"); -fx-background-color: transparent; -fx-cursor: hand");
});
}
The problem is down bellow.
I've set the following custom row factory:
treeTblViewFiles.setRowFactory(new Callback<TreeTableView<FileModel>, TreeTableRow<FileModel>>() {
#Override
public TreeTableRow<FileModel> call(TreeTableView<FileModel> treeTableView) {
final TreeTableRow<FileModel> row = new TreeTableRow<>();
final ContextMenu rowMenu = new ContextMenu();
MenuItem removeItem = new MenuItem("Remove");
removeItem.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent t) {
int currentPlaylistIndex = m_playlists.indexOf(row.getTreeItem().getParent().getValue());
boolean itemRemoved = false;
if (row.getItem().getClass().equals(Song.class)) {
itemRemoved = m_playlists.get(currentPlaylistIndex).getSongs().remove(row.getItem());
m_playlists.get(currentPlaylistIndex).updatePlaylist((Song) row.getItem());
} else if (row.getItem().getClass().equals(Playlist.class)) {
itemRemoved = m_playlists.remove(row.getTreeItem().getValue());
}
TreeItem<FileModel> treeItem = row.getTreeItem();
// may need to check treeItem.getParent() is not null:
treeItem.getParent().getChildren().remove(treeItem);
treeTblViewFiles.getSelectionModel().clearSelection();
if (MyApp.DEBUG) {
System.out.println(m_playlists.size());
if (currentPlaylistIndex > -1) {
System.out.println(m_playlists.get(currentPlaylistIndex).getSongs().size());
}
}
}
});
rowMenu.getItems().add(removeItem);
row.contextMenuProperty().bind(Bindings.when(Bindings.isNotNull(row.itemProperty()))
.then(rowMenu)
.otherwise((ContextMenu) null));
return row;
}
});
and in my css I have:
/******************
* ContextMenu
******************/
.context-menu{
-fx-background-color: transparent;
}
.context-menu .menu-item{
-fx-background-image: url("styles/cm_bg.png");
-fx-background-repeat: no-repeat;
-fx-background-position: center;
-fx-background-color: transparent;
}
.context-menu .menu-item .label{
-fx-text-fill: #ababab;
-fx-font-weight: normal;
-fx-font-size: 12pt;
}
The problem is that it doesn't show the entire image(which is 220x40) but only the width that suits the 'Remove' string. The right-most part is cut.
EDIT:
Simplified version(the same result goes for a contextMenu on a Label):
ContextMenu cm = new ContextMenu();
MenuItem mi = new MenuItem("Test");
cm.getItems().addAll(mi);
lblUploader.setContextMenu(cm);
Why is that happening and how to solve it?
Thanks in advance.
Problem solved with the following .css:
.context-menu {
-fx-background-color: transparent;
-fx-min-width: <image_width>;
-fx-min-height: <image_height>;
}
Just remember to set the preferred(or min) sizes.