Display color in a JavaFX TableRow - colors

I would like to change the color of the text displayed in a TableRow.
The instruction setStyle("-fx-background-color: green"); is working well,
but the instruction setTextFill doesn't work. Is it normal ?
tableView.setRowFactory(new Callback<TableView<Person>, TableRow<Person>>() {
#Override
public TableRow<Person> call(TableView<Person> param) {
final TableRow<Person> row = new TableRow<Person>() {
#Override
protected void updateItem(Person person, boolean empty) {
super.updateItem(person, empty);
setTextFill(Color.RED);
//setStyle("-fx-background-color: green");
}
};
return row;
}
});

The easiest way is to set the default CSS file in your application with:
.cell {
-fx-background-color: #FFCCAA;
-fx-text-fill: #000000;
}
/* if you want more different colours for even and odds: */
.cell:odd {
-fx-background-color: #FFDDDD;
-fx-text-fill: green;
}
You can add this file.css to your scene:
scene.getStylesheets().add("file.css");

Related

I want to change the value of the variable [$margen] when changing the direction to rtl

/* $margen var = left change page dir to rtl i want to change $margen value to right */
$margen: left;
html{
[dir=rtl] & {
$margen: right;
}
}
button {
margin-#{$margen}: 10px;
}
Code Editor Page

Drawing Tool with Processing

I am trying to create a little drawing tool with processing. The final drawing should be exportable as a .svg file – so i thought this to be pretty easy… but actually it isnt…
I put the background function into setup – to be able to draw – the safed svg file unfortunately only contains a single frame – and not the whole drawing. :-(
What am I missing – how could I achieve that! I would be thankful for any kind of help!
This is my code so far:
import processing.svg.*;
boolean record;
void setup () {
size(1080, 1080);
background(255);
}
void draw() {
if (record) {
beginRecord(SVG, "frame-####.svg");
}
fill(255);
strokeWeight(1);
ellipse(mouseX, mouseY, 100, 100);
if (record) {
endRecord();
record = false;
}
}
void mousePressed() {
record = true;
}
Tried different things in organizing the code lines in different orders – but could not manage it…
Thank you!
That's because you're creating an image every time you beginRecord and endRecord. If you want to save the image as you see it, you can use save(fileName.png) instead. Here's a code snippet to demonstrate:
void setup() {
size(800, 600);
background(255);
fill(255);
strokeWeight(1);
}
void draw() {
ellipse(mouseX, mouseY, 100, 100);
}
void mousePressed() {
save("myImage.png");
}
If, on the other hand, you really want to use beginRecord, know that it'll save everything you draw between beginRecord and endRecord. You could programatically create an image file this way, as an example, but you cannot just add snapshots to an existing image (which is why you only see "one frame" with your current code). Every time you begin recording, you create a new image. I'm not especially familiar with this method, but one obvious way to do things would be to "save" whatever the user is doing and reproduce those instructions to save them. Here's an example which does this (it saves when you right-click, and I also took the liberty of drawing only when the left mouse button is down):
import processing.svg.*;
boolean record;
ArrayList<PVector> positionsList;
void setup() {
size(800, 600);
positionsList = new ArrayList<PVector>();
}
void draw() {
background(255);
fill(255);
strokeWeight(1);
for (PVector p : positionsList) {
ellipse(p.x, p.y, 100, 100);
}
ellipse(mouseX, mouseY, 100, 100);
if (record) {
positionsList.add(new PVector(mouseX, mouseY));
}
}
void mousePressed() {
record = mouseButton == LEFT;
if (mouseButton == RIGHT) {
beginRecord(SVG, "frame.svg");
fill(255);
strokeWeight(1);
for (PVector p : positionsList) {
ellipse(p.x, p.y, 100, 100);
}
endRecord();
}
}
void mouseReleased() {
record = false;
}
While drawing:
The file (as a png here but it was saved as a svg on my computer):
Hope it helps. Have fun!
import processing.pdf.*;
PShape shape;
void setup () {
size(1080, 1080);
beginRecord(PDF, "drawing.pdf");
shape = loadShape("shape.svg");
shapeMode(CENTER);
background(0,255,0);
}
void draw() {
shape.disableStyle();
fill(255);
strokeWeight(10);
shape(shape, mouseX, mouseY, 200, 200);
}
void keyPressed() {
if (key == 's') {
endRecord();
exit();
}
}

Make vertical Menu Bar in JavaFX

Since my interaction with computer, I have seen only menu bar in horizontal direction only. The menuitem of such menubar will be popping downwards. In JavaFX it is easy to create such a menu with a horizontal menubar.
Is it possible to create a vertical menubar in JavaFX ? Also I want the menuitems to be popped out either to left or right, not downwards.
Can I implement such a menu of my desire ? Someone please help.
You can leverage the MenuButton for that:
#Override
public void start(Stage primaryStage) {
MenuButton m = new MenuButton("Eats");
m.setPrefWidth(100);
m.setPopupSide(Side.RIGHT);
m.getItems().addAll(new MenuItem("Burger"), new MenuItem("Hot Dog"));
MenuButton m2 = new MenuButton("Drinks");
m2.setPrefWidth(100);
m2.setPopupSide(Side.RIGHT);
m2.getItems().addAll(new MenuItem("Juice"), new MenuItem("Milk"));
VBox root = new VBox();
root.getChildren().addAll(m, m2);
Scene scene = new Scene(root, 300, 250);
scene.getStylesheets().add(getClass().getResource("style.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.show();
}
where the style.css is
.menu-button {
-fx-skin: "com.sun.javafx.scene.control.skin.MenuButtonSkin";
-fx-background-color: red, green, green, lightgreen;
-fx-background-insets: 0 0 -1 0, 0, 1, 2;
-fx-background-radius: 0;
-fx-padding: 0.0em; /* 0 */
-fx-text-fill: -fx-text-base-color;
}
/* TODO workaround for RT-19062 */
.menu-button .label { -fx-text-fill: -fx-text-base-color; }
.menu-button:focused {
-fx-color: beige;
-fx-background-color: -fx-focus-color, -fx-outer-border, -fx-inner-border, -fx-body-color;
-fx-background-insets: -1.4, 0, 1, 2;
-fx-background-radius: 0;
}
.menu-button:hover {
-fx-color: darkgreen;
}
.menu-button:armed {
-fx-color: greenyellow;
}
These selectors are partially taken and overriden from caspian.css. Change the color preferences as your needs and you can also remove the arrow of the buttons through css.
The drawback of this approach is the difficulty of making nested menu items.

Slick-Util (in lwjgl): Importing a texture and displaying it results in weird, extra pixels (in lines) created near the texture

Code: http://www.lwjgl.org/wiki/index.php?title=Slick-Util_Library_-_Part_1_-_Loading_Images_for_LWJGL
Output:
(It's supposed to be just a rectangle; but the extra lines at the right, bottom, and the pixel at the bottom right appear.)
I tested it out with .jpg also, it appears that the only difference is that the line at the bottom acquires the same width as the rectangle to be displayed.
Can anyone help me with why / how to fix this / how to import an image correctly?
import java.io.IOException;
import org.lwjgl.LWJGLException;
import org.lwjgl.opengl.Display;
import org.lwjgl.opengl.DisplayMode;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.Color;
import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;
public class TextureExample {
/** The texture that will hold the image details */
private Texture texture;
/**
* Start the example
*/
public void start() {
initGL(800,600);
init();
while (true) {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
render();
Display.update();
Display.sync(100);
if (Display.isCloseRequested()) {
Display.destroy();
System.exit(0);
}
}
}
/**
* Initialise the GL display
*
* #param width The width of the display
* #param height The height of the display
*/
private void initGL(int width, int height) {
try {
Display.setDisplayMode(new DisplayMode(width,height));
Display.create();
Display.setVSyncEnabled(true);
} catch (LWJGLException e) {
e.printStackTrace();
System.exit(0);
}
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
// enable alpha blending
GL11.glEnable(GL11.GL_BLEND);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glViewport(0,0,width,height);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
GL11.glMatrixMode(GL11.GL_PROJECTION);
GL11.glLoadIdentity();
GL11.glOrtho(0, width, height, 0, 1, -1);
GL11.glMatrixMode(GL11.GL_MODELVIEW);
}
/**
* Initialise resources
*/
public void init() {
try {
// load texture from PNG file
texture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/image.png"));
System.out.println("Texture loaded: "+texture);
System.out.println(">> Image width: "+texture.getImageWidth());
System.out.println(">> Image height: "+texture.getImageHeight());
System.out.println(">> Texture width: "+texture.getTextureWidth());
System.out.println(">> Texture height: "+texture.getTextureHeight());
System.out.println(">> Texture ID: "+texture.getTextureID());
} catch (IOException e) {
e.printStackTrace();
}
}
/**
* draw a quad with the image on it
*/
public void render() {
Color.white.bind();
texture.bind(); // or GL11.glBind(texture.getTextureID());
GL11.glBegin(GL11.GL_QUADS);
GL11.glTexCoord2f(0,0);
GL11.glVertex2f(100,100);
GL11.glTexCoord2f(1,0);
GL11.glVertex2f(100+texture.getTextureWidth(),100);
GL11.glTexCoord2f(1,1);
GL11.glVertex2f(100+texture.getTextureWidth(),100+texture.getTextureHeight());
GL11.glTexCoord2f(0,1);
GL11.glVertex2f(100,100+texture.getTextureHeight());
GL11.glEnd();
}
/**
* Main Class
*/
public static void main(String[] argv) {
TextureExample textureExample = new TextureExample();
textureExample.start();
}
}
The resolution of textures need to be a power of two. Once they are initialized, they can be resized to whatever dimensions are needed.

display icons in p:column filteroptions

i'm trying to display icons as filterOptions on my p:datatable.
the current situation is that i display a list of unicode symbols , but the client wants them to be colorful.
the code below shows how i fill my list of states (my filter options) in my backingbean.
private static final String LABEL_DEACTIVATED = "\u24E7";
private static final String LABEL_ACTIVATED = "\u2714";
private void fillSelectItem() {
userStates = new SelectItem[3];
userStates[0] = new SelectItem("", LABEL_ALL);
userStates[1] = new SelectItem(USER_ACTIVATED.name(), LABEL_ACTIVATED);
userStates[2] = new SelectItem(USER_DEACTIVATED.name(),
LABEL_DEACTIVATED);
}
You could use CSS to style each individual icon, as long as your target browser supports CSS2 attribute selectors (ie. almost all modern browsers). Put the following in your css file:
option[value='USER_ACTIVATED'] {
/* for example */
background-image: url(.....);
background-color: #123456;
color: #123123;
}
option[value='USER_DEACTIVATED'] {
/* for example */
background-image: url(.....);
background-color: #888111;
color: #222222;
}

Resources