I m having trouble using JEditorPane.
I want to do left align and right align text on the same line.
Here is my code:
INFO_AREA = new JEditorPane();
INFO_AREA.setBorder(BorderFactory.createCompoundBorder(BORDER,
BorderFactory.createEmptyBorder(10, 10, 10, 10)));
HTMLEditorKit kit = new HTMLEditorKit();
INFO_AREA.setEditorKit(kit);
StyleSheet styleSheet = kit.getStyleSheet();
styleSheet.addRule(".alignleft{color : rgb(0,128,25); font-weight: bold; float: left;}");
styleSheet.addRule(".alignright{color : rgb(0,128,25); font-weight: bold; float: right;}");
INFO_AREA.setText("<html>" +
"<center><b><font size=6>Important Information</font></b></center>"
"<div id=textbox><p class='alignleft'>left</p><p class='alignright'>right</p></div>" +
"</html>");
INFO_AREA.setLocation(305, 10);
INFO_AREA.setSize(275, 200);
INFO_AREA.setEditable(false);
PANE.add(INFO_AREA);
It doesn't work it seems like JEditorPane does not support float.
So maybe anyone has any ideas how I can achieve left align and right align text on the same line?
Swing's HTML renderer is old. It supports HTML 3.2 and CSS 1.0, and it does not even support all capabilities of those specifications.
Looking at the documentation of the CSS class, we see that it lists all of the CSS properties it supports. There is a list of what is supported, following by a list prefaced with "The following are modeled, but currently are not rendered." In that list is the float property.
So, Swing HTML rendering does not currently support the float property. At all.
There is a long-standing open bug, Java Bug ID 4296022, for this issue.
Related
I want to apply CSS for Vaadin 23 label but its not working properly. Please suggest me appropriate process.
Label label1 = new Label("Temp");
label1.addClassName("bold-label");
vaadin-label.css:
:host(.bold-label) [part~="label"] {
font-weight: bold;
color:red;
}
Label is standard HTML element. See Mozilla Developer documentation. Not a specific Vaadin crafted component with shadow DOM (where you would need the vaadin-*.css in the components folder).
Instead you can put your css inside styles.css and use a simple label.bold-label selector.
In my Enunciate API documentation report, I need to change the font of some comment text to "Courier New" font type.
Is is possible?
Found a way for this feature -
Use Font html tag in the comment, Java doc code reads it as a html tag and displays in courier font.
/* Sample URL - <font face="courier">https://{Hostname}/programs/FireIn</font>, Replace the host name with the respective environment name</br>
*/
Starting with 1.2, Javadoc supports HTML style sheets. You can make these changes to stylesheet.css (located at the root directory of the Javadoc HTML files).
To choose a smaller, sans-serif fonts for the left-hand frames, change this:
#FrameItemFont { font-size: normal; font-family: normal }
To:
#FrameItemFont { font-size: 10pt; font-family: helvetica arial sans-serif }
Customize this yourself for whatever font you want.
I'm using JavaFX version 8.0.40-b27 and trying to embed a custom/external font via CSS. I've also tried programmatic approaches, all of which have failed. A System.out.print of "font" returns null, which I suspect to be the cause.
Java:
Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream( "application/stratum.ttf"), 10);
System.out.println(font); // Prints "null"
nowPlayingTitle.setFont(font);
CSS:
#font-face {
font-family: stratum;
src: url('stratum.ttf');
}
.text{
-fx-font-family: "stratum", "Segoe UI Light";
-fx-font-weight: 100;
-fx-text-fill: white;
}
Directory:
http://i.stack.imgur.com/c92ii.png
EDIT:
System.out.println(font); now prints Font[name=StratumNo1-Thin, family=StratumNo1, style=Thin, size=10.0], so the file is being accessed correctly. However the font is still not being rendered on screen: http://i.stack.imgur.com/bueUk.png
For the URL in Java code, try either
// relative to classpath, with leading /
Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream( "/application/stratum.ttf"), 10);
or
// relative to class:
Font font = Font.loadFont( Main.class.getClassLoader().getResourceAsStream( "stratum.ttf"), 10);
The CSS looks right to me... are you sure your ttf file is being deployed along with the compiled code as css, etc?
I have a GWT application with some SimplePanel.
How can I make its border dashed?
I tried myPanel.addStyleName(Style.BorderStyle.DOTTED.getCssName());, but it didn't work.
This should work using Element#getStyle() method to update the element's Style object.
SimplePanel myPanel=new SimplePanel();
myPanel.getElement().getStyle().setBorderStyle(BorderStyle.DOTTED);
but I suggest you to keep the styling in the CSS file instead of directly applying it in Java file that is more difficult to manage and change in future mostly in case of themes.
CSS:
.dashedBorder{
border: 1px dotted black;
}
JAVA:
SimplePanel myPanel=new SimplePanel();
myPanel.setStyleName("dashedBorder");
I have a label with style class "test" in my javafx application.
I wanted to add white border around this label, so in the css file I tried:
-fx-border-width: 2;
-fx-border-color: white;
but that didnt worked so then i tried to add:
-fx-border-style: solid;
but that didnt worked either, following javafx css reference I didn't find anything useful.
what am I doing wrong?
Can you try:
System.out.println(label);
it should print something like
Label#1858c80c[styleClass=label]
Is your css class printing too after styleClass=label ... ?
Or can you remove css class of the label and try setting the label style in code directly by:
label.setStyle("-fx-border-color: white;");
if you can see the changes then maybe you are unintentionally overriding css class definiton in css file. Check it.