So I'm just starting to learn JavaFX, and I made a couple of TextFields with Scene Builder. I assigned some prompt text to every TextField, but when I start my application, the first TextField is already selected, so I don't see the prompt text. Can I do something about it?
One solution is to make the prompt text stay visible when the TextField has focus.
The reason why the prompt text disappears is because modena.css (the default stylesheet used in JavaFX 8+) makes the prompt text's fill transparent when the TextField has focus. You can change this by using your own CSS to style the prompt text. There are a couple ways you can do this:
CSS File:
.text-field:focused {
-fx-prompt-text-fill: inherit;
}
Code:
textField.setStyle("-fx-prompt-text-fill: inherit;");
Note you can set the style from Scene Builder.
Related
in my JAVA FX application I am using TextArea to display certain text content. I am using following property to restrict editing:
templateScriptArea.setEditable(false);
With this, user is not able to write anything on TextArea, but selection is allowed, or if any selection is made by application is able change by user.
My requirement is that TextArea should be completely readonly, no editing no selection. Only scroll should work.
I thought, disabling TextArea is good idea with :
templateScriptArea.setDisable(true);
But, scroll not work with this and grey color appears on TextArea.
Is there any better solution?
I tried to use the TextArea component to let user write multi-line text,
but the problem that I can't set the text alignment to right. By default it starts in the left.
The text will be in Hebrew or Arabic, so I need the user to write in the TextArea from right to left. I didn't find from the TextArea code and docs a way to do that, and in some forums some people said it can't be done. Is that true?
If you are using Scene Builder to build the FXML, then simply set Node Orientation property to RIGHT_TO_LEFT. You should see the result as soon as you run "Preview -> Show Preview in Window", where the cursor and typing happen on the righthand side.
If you are creating the TextArea inside a JavaFX application (no FXML), you use the method setNodeOrientation() on your TextArea object with the enum parameter NodeOrientation.RIGHT_TO_LEFT.
I have a JTextPane which I use for html styled editing. I have one problem which is not exactly critical, but would be nice if I could fix it. The problem is that when I backspace in the text pane up to the end of the line, the style text I had is reset back to the default font and style for the text pane.
How do I stop this from happening and retain the styling.
I have tried setting the JTextPane with
"<html><head></head><body>" +
"<p style = \"font-size:22; font-family:sans-serif\"></p>" +
"</body></html>";
This works until I save or refresh the html. Once it is saved or refreshed all the text returns back to the very tiny JTextPane font and all styling is removed.
How do I make it retain the styling when saving, refreshing, or backspacing?
Update: I have tried doing this, but it only works until I save the text in the text pane and update it. I tested this in java 1.7 like the link said to do.
I'm new to both JavaFX and CSS. I'm using Scene Builder, and have an accordion that I want to use as a menu bar. I want the background of the accordion to either be transparent or to match the background of the page behind it, and the text to be fully opaque and a different color. Also, I do not want the arrows beside the text to appear. I've tried the various options that Scene Builder provides, but none enabled me to do either of these two things. Is this something I'll need to do with CSS, and if so, how?
I solved the issue with css. JavaFX uses a file called caspian.css for its standard styling.
An accordion module contains titled panes that consist of a title and a content area.
To remove the background color of the content you need to overwrite the styleClass of the titled panes:
.accordion .titled-pane > *.content {
-fx-background-color: null;
}
You could also assign a custom styleClass to your titled panes or accordion if you don't want to overwrite the style application-wide.
Hope this helps.
I am trying to change the font of the text in a textarea in Swing. Which listener should I use on textarea to trigger an action that lets the program initiate the font code.
All the examples have all the swing in the same class which lets you access the textarea directly, but I have multiple classes; I know I can pass the textarea in and in and in, but this is sloppy.
I just cannot figure out which listener to initiate.
I am trying to change the font of the
text in a textarea in Swing.
Well a JTextArea can only have a single Font, so if you want to change the Font you would have some other component, maybe a "Change Font" button that you would click. In this case you would add an ActionListener to the button to change the actual Font of the text area.
If you actually need to change the Font on selected pieces of text, then you also can't do this with a JTextArea. You would need to use a JTextPane. Read the JTextPane API and follow the link to the Swing tutorial on "Text Component Features" for an example of changing attributes on selected text. In this cause you use Actions provided by the editor kit.
So basically you need to read the Swing tutorial to find out the basics of using Swing components.
If you're listening to the textarea, then it would depend on how many different ways you want the user to be able to change the font of what they are typing.
You could use MouseListener if you want them to be able to change the font on right click/etc... or a KeyListener if you want to listen for a series of keys.