Fachbereich
Automatisierung und Informatik Wernigerode
Handbuch für Java FX im Fach
Grafische Nutzerschnittstellen
WiSe 2019/20
Inhaltsverzeichnis
1 Abbildungsverzeichnis _____________________________________________________________ 6 2 Java FX Basisklassen ______________________________________________________________ 7 2.1 Control ____________________________________________________________________________ 7
2.1.1 Properties _________________________________________________________________________________ 7 2.1.2 Methoden _________________________________________________________________________________ 7 2.2 Region ____________________________________________________________________________ 7 2.3 Labeled ____________________________________________________________________________ 9 2.4 TextInputControl ___________________________________________________________________ 11 3 Einfache Controls ________________________________________________________________ 12
3.1 Button ___________________________________________________________________________ 12 3.1.1 Konstruktoren _____________________________________________________________________________ 12 3.1.2 Methoden ________________________________________________________________________________ 12 3.1.3 Event ____________________________________________________________________________________ 12 3.2 CheckBox _________________________________________________________________________ 12
3.2.1 Konstruktor: ______________________________________________________________________________ 12 3.2.2 Methoden ________________________________________________________________________________ 12 3.2.3 Event ____________________________________________________________________________________ 13 3.3 ChoiceBox ________________________________________________________________________ 14
3.3.1 Konstruktor: ______________________________________________________________________________ 14 3.3.2 Methoden ________________________________________________________________________________ 14 3.3.3 Abfragen _________________________________________________________________________________ 15 3.3.4 Event ____________________________________________________________________________________ 15 3.4 ComboBox ________________________________________________________________________ 15
3.4.1 Konstruktor: ______________________________________________________________________________ 15 3.4.2 Methoden ________________________________________________________________________________ 15 3.4.3 Abfragen _________________________________________________________________________________ 16 3.4.4 Beispiele: _________________________________________________________________________________ 16 3.4.5 Event: ___________________________________________________________________________________ 16 3.5 Label _____________________________________________________________________________ 17
3.5.1 Konstruktoren _____________________________________________________________________________ 17 3.6 MenuBar _________________________________________________________________________ 17
3.6.1 Konstruktor: ______________________________________________________________________________ 17 3.7 Menu ____________________________________________________________________________ 17
3.7.1 Konstruktor: ______________________________________________________________________________ 17 3.7.2 Methoden ________________________________________________________________________________ 17 3.8 MenuItem ________________________________________________________________________ 18
3.8.1 Konstruktor: ______________________________________________________________________________ 18 3.8.2 Methoden ________________________________________________________________________________ 18 3.8.3 SeparatorMenuItem ________________________________________________________________________ 18 3.8.4 ShortKey _________________________________________________________________________________ 18 3.8.5 CSS: _____________________________________________________________________________________ 18 3.9 RadioButton _______________________________________________________________________ 19
3.9.1 Konstruktor: ______________________________________________________________________________ 19 3.9.2 Methoden ________________________________________________________________________________ 19 3.9.3 Event ____________________________________________________________________________________ 20 3.9.4 Abfragen _________________________________________________________________________________ 20 3.9.5 Beispiele: _________________________________________________________________________________ 20 3.9.6 Event: ___________________________________________________________________________________ 20
3.10 Slider ____________________________________________________________________________ 21 3.10.1 Konstruktor: ____________________________________________________________________________ 21 3.10.2 Methoden______________________________________________________________________________ 21 3.10.3 Abfragen _______________________________________________________________________________ 22 3.10.4 Event __________________________________________________________________________________ 22 3.10.5 Beispiele: ______________________________________________________________________________ 22 3.11 Spinner ___________________________________________________________________________ 23
3.11.1 Konstruktor: ____________________________________________________________________________ 23 3.11.2 Methoden______________________________________________________________________________ 23 3.11.3 SpinnerValueFactory _____________________________________________________________________ 24 3.11.4 Spinner-Styles __________________________________________________________________________ 24 3.11.5 Abfragen _______________________________________________________________________________ 25 3.11.6 Event __________________________________________________________________________________ 25 3.11.7 Beispiel mit Liste ________________________________________________________________________ 25 3.12 TextArea __________________________________________________________________________ 25
3.12.1 Konstruktoren __________________________________________________________________________ 25 3.12.2 Methoden______________________________________________________________________________ 25 3.12.3 eEvent _________________________________________________________________________________ 26 3.13 TextField __________________________________________________________________________ 27
3.13.1 Konstruktoren __________________________________________________________________________ 27 3.13.2 Methoden______________________________________________________________________________ 27 3.14 HTMLEditor _______________________________________________________________________ 28 3.15 Platform __________________________________________________________________________ 28 3.15.1 Dialog beenden _________________________________________________________________________ 28
4 Canvas Control __________________________________________________________________ 29
4.1.1 Konstruktor: ______________________________________________________________________________ 29 4.1.2 Methoden ________________________________________________________________________________ 29 4.2 GraphicsContext ___________________________________________________________________ 29
4.2.1 Wichtige Funktionen________________________________________________________________________ 29 4.2.2 Farben ___________________________________________________________________________________ 30 4.2.3 FontWeight _______________________________________________________________________________ 30 4.2.4 Fillfunktionen _____________________________________________________________________________ 31 4.2.5 Textfunktionen ____________________________________________________________________________ 31 4.2.6 Restliche Funktionen _______________________________________________________________________ 31 4.2.7 Beispiele _________________________________________________________________________________ 33 4.2.8 Color ____________________________________________________________________________________ 38
5 Komplexe Controls _______________________________________________________________ 41 5.1 ListView __________________________________________________________________________ 41
5.1.1 Konstruktor: ______________________________________________________________________________ 41 5.1.2 Methoden ________________________________________________________________________________ 41 5.1.3 Beispiel: __________________________________________________________________________________ 42 5.1.4 Event ____________________________________________________________________________________ 42 5.1.5 Abfragen _________________________________________________________________________________ 42 5.1.6 CellFactory _______________________________________________________________________________ 43 5.1.7 ContextMenu _____________________________________________________________________________ 43 5.1.8 onClick ___________________________________________________________________________________ 44 5.1.9 Aktionen zur ListView _______________________________________________________________________ 44 5.1.10 FXML __________________________________________________________________________________ 45 5.2 TableView ________________________________________________________________________ 45
5.2.1 Konstruktor: ______________________________________________________________________________ 45 5.2.2 Methoden ________________________________________________________________________________ 46 5.2.3 Einfaches Beispiel: _________________________________________________________________________ 46 5.2.4 Beispiel Mit Farbe der Noten (CellFactory): _____________________________________________________ 47 5.2.5 Beispiel Sortierung nach Lastname/Firstname ___________________________________________________ 48 5.2.6 Beispiel Filter nach Lastname/Firstname ________________________________________________________ 49
5.2.7 Abfragen _________________________________________________________________________________ 50 5.2.8 ContextMenu _____________________________________________________________________________ 50 5.2.9 onClick ___________________________________________________________________________________ 51 5.2.10 Aktionen zur TableView ___________________________________________________________________ 51 5.3 TabPane __________________________________________________________________________ 52 5.4 TreeTableView _____________________________________________________________________ 52 5.5 TreeView _________________________________________________________________________ 52 6 Control-Container ________________________________________________________________ 53
6.1 Accordion _________________________________________________________________________ 53 6.1.1 Konstruktoren _____________________________________________________________________________ 53 6.1.2 Methoden ________________________________________________________________________________ 53 6.2 ButtonBar _________________________________________________________________________ 57
6.2.1 Konstruktoren _____________________________________________________________________________ 57 6.2.2 Methoden ________________________________________________________________________________ 58 6.3 ButtonData _______________________________________________________________________ 58 6.4 Pagination ________________________________________________________________________ 59 6.5 ProgressIndicator ___________________________________________________________________ 59 6.6 ScrollBar __________________________________________________________________________ 59 6.7 ScrollPane ________________________________________________________________________ 60 6.7.1 Konstruktor: ______________________________________________________________________________ 60 6.7.2 Methoden ________________________________________________________________________________ 60 6.8 Separator _________________________________________________________________________ 60 6.9 SplitPane _________________________________________________________________________ 60 6.9.1 Konstruktor: ______________________________________________________________________________ 60 6.9.2 Methoden ________________________________________________________________________________ 60 6.10 TabPane __________________________________________________________________________ 65
6.10.1 Konstruktor: ____________________________________________________________________________ 65 6.10.2 Methoden______________________________________________________________________________ 65 6.10.3 Event __________________________________________________________________________________ 65 6.10.4 insertTab ______________________________________________________________________________ 66 6.10.5 getActualTab ___________________________________________________________________________ 66 6.11 ToolBar ___________________________________________________________________________ 66
6.11.1 Konstruktoren __________________________________________________________________________ 67 6.11.2 Methoden______________________________________________________________________________ 67
7 Layout _________________________________________________________________________ 69 7.1 AnchorPane _______________________________________________________________________ 69
7.1.1 Beispiel __________________________________________________________________________________ 70 7.2 BorderPane _______________________________________________________________________ 72 7.3 HBox _____________________________________________________________________________ 74 7.4 FlowPane _________________________________________________________________________ 75 7.5 GridPane _________________________________________________________________________ 76 7.5.1 Kurzbeispiele: _____________________________________________________________________________ 77 7.5.2 Beispiele _________________________________________________________________________________ 78 7.6 ColumnConstraints _________________________________________________________________ 80
7.6.1 Kontruktoren: _____________________________________________________________________________ 80 7.6.2 Methoden ________________________________________________________________________________ 81 7.7 StackPane _________________________________________________________________________ 81
7.7.1 Kompletter Quellcode ______________________________________________________________________ 83 7.8 VBox _____________________________________________________________________________ 89
7.8.1 Beispiel __________________________________________________________________________________ 89
8 Mouse-Event ____________________________________________________________________ 91 8.1 Mouse-Clock ______________________________________________________________________ 91 8.2 ContextMenu ______________________________________________________________________ 91 9 CSS____________________________________________________________________________ 93 10 Zusatzklassen ___________________________________________________________________ 94 10.1 Border ___________________________________________________________________________ 94
10.1.1 Konstruktor: ____________________________________________________________________________ 94 10.2 BorderStroke ______________________________________________________________________ 94
10.2.1 Konstruktor: ____________________________________________________________________________ 94 10.3 BorderStrokeStyle __________________________________________________________________ 95
10.3.1 Konstructor ____________________________________________________________________________ 95 10.4 CornerRadii _______________________________________________________________________ 96
10.4.1 Konstruktor_ ___________________________________________________________________________ 96 10.5 BorderWidths _____________________________________________________________________ 96
10.5.1 Konstruktor_ ___________________________________________________________________________ 96 10.6 Orientation _______________________________________________________________________ 96 10.7 FileChooser _______________________________________________________________________ 96 10.7.1 showOpenDialog ________________________________________________________________________ 97 10.7.2 showOpenMultipleDialog _________________________________________________________________ 97 10.7.3 showSaveDialog(Window ownerWindow) ____________________________________________________ 97
11 Spezielle Klasse __________________________________________________________________ 98 12 Tools __________________________________________________________________________ 99 12.1 getDoubleNumber __________________________________________________________________ 99 12.2 errorBox __________________________________________________________________________ 99 12.3 insertString _______________________________________________________________________ 99 13 Beispiellösungen _______________________________________________________________100
13.1 StatusBar ________________________________________________________________________ 100 13.2 BaseLine _________________________________________________________________________ 100 14 Stichwortverzeichnis ____________________________________________________________101
1
Abbildungsverzeichnis
Abbildung 1 Sliderbeispiel ... 23
Abbildung 2 draw-Beispiel1 ... 34
Abbildung 3 draw-Beispiel2 ... 35
Abbildung 4 draw-Beispiel3 ... 36
Abbildung 5 draw-Beispiel4, Beachten Sie den Scrollbalken ... 37
Abbildung 6 draw-Beispiel5, Beachten Sie die Transparenzfarbe (rechts) ... 38
Abbildung 7 UIBspTableView01.java ... 47
Abbildung 8 UIBspTableView02.java ... 48
Abbildung 9 UIBspTableView03.java ... 49
Abbildung 10 UIBspTableView04.java ... 50
Abbildung 11 Accordion statt StackPane (Bild1) ... 57
Abbildung 12 Accordion statt StackPane (Bild2) ... 57
Abbildung 13 Accordion statt StackPane (Bild3) ... 57
Abbildung 14 MDI, Split Pane mit einem Editor ... 63
Abbildung 15 MDI, Split Pane mit zwei Editoren ... 64
Abbildung 16 MDI, Split Pane mit drei Editoren ... 64
Abbildung 17 MDI, Split Pane mit vier Editoren ... 64
Abbildung 18 MDI, Split Pane mit vier Editoren und zwei SplitPanes ... 65
Abbildung 19 AnchorPane Bereiche ... 69
Abbildung 20 Beispiel AnchorPane (der Editor hat eine feste Höhe) ... 70
Abbildung 21 Editor ist Top; Der Schalter liegt bei BorderPane unterhalb von Top (nicht daneben) .. 71
Abbildung 22 Editor ist Center; Der Schalter liegt jetzt rechts vom Editor ... 71
Abbildung 23 Editor 0/0, Schalter(1/0) ... 72
Abbildung 24 BorderPane (Top ist komplett über die gesamte Breite) ... 73
Abbildung 25 GridPane mit Label und TextField ... 78
Abbildung 26 UIGridPane02 ... 79
Abbildung 27 UIGridPane03 ... 80
Abbildung 28 StackPanel ... 82
Abbildung 29 StackPane, Seite 1 ... 82
Abbildung 30 StackPane, Seite 2 ... 83
Abbildung 31 StackPane, Seite 3 ... 83
Abbildung 32 BaseLine eines Label mit einem TextField ... 100
2 Java FX Basisklassen
2.1 Control
Class: javafx.scene.control.Control Link:
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/Control.html
2.1.1 Properties
background
border
height,
insets,
maxHeight,
maxWidth,
minHeight,
minWidth,
opaqueInsets,
padding,
prefHeight,
prefWidth,
scaleShape,
snapToPixel,
width
2.1.2 Methoden
void setContextMenu(ContextMenu value)
void setSkin(Skin<?> value)
void setTooltip(Tooltip value)
ObjectProperty<Skin<?>> skinProperty()
ObjectProperty<Tooltip> tooltipProperty()
2.2 Region
javafx.scene.layout.Region
backgroundProperty
Border borderProperty
Background getBackground()
getBorder()
getHeight
getInsets
double getMaxHeight()
double getMaxWidth()
double getMinHeight()
double getMinWidth()
getOpaqueInsets
getPadding
getPrefHeight
getPrefWidth
double getWidth()
heightProperty
insetsProperty
isCenterShape
isScaleShape
isSnapToPixel
maxHeight
maxHeightProperty
maxWidth
maxWidthProperty
minHeight
minHeightProperty
minWidth
minWidthProperty
opaqueInsetsProperty
paddingProperty
positionInArea
positionInArea
prefHeight
prefHeightProperty
prefWidth
prefWidthProperty
resize
scaleShapeProperty
setBackground(Background value) o javafx.scene.layout.Background
Background(BackgroundFill... fills)
Background(BackgroundFill[] fills, BackgroundImage[] images)
Background(BackgroundImage... images)
Background(List<BackgroundFill> fills, List<BackgroundImage> images)
o javafx.scene.layout.BackgroundFill
setBorder(Border border)
o javafx.scene.layout.Border
Border(BorderImage... images)
Creates a new Border by supplying an array of BorderImages.
Border(BorderStroke... strokes)
Creates a new Border by supplying an array of BorderStrokes.
Border(BorderStroke[] strokes, BorderImage[] images)
Creates a new Border by supplying an array of BorderStrokes and BorderImages.
Border(List<BorderStroke> strokes, List<BorderImage> images)
Creates a new Border by supplying a List of BorderStrokes and BorderImages.
import javafx.scene.layout.Border;
import javafx.scene.layout.BorderStroke;
import javafx.scene.layout.BorderStrokeStyle;
import javafx.scene.layout.BorderWidths;
import javafx.scene.paint.Color;
label.setBorder(new Border(new BorderStroke(Color.GREEN,
BorderStrokeStyle.SOLID, new CornerRadii(10), new BorderWidths(3))));
BorderStrokeStyle o DASHED o DOTTED o NONE o SOLID
setHeight(double value)
setMaxHeight(double value)
setMaxSize(double value)
setMaxWidth(double value)
setMinHeight(double value)
setMinSize(double value)
setMinWidth(double value)
setOpaqueInsets
setPadding(Insets value) InnenRand (Rand zum Text) o javafx.geometry.Insets
o Insets(double topRightBottomLeft)
o Insets(double top, double right, double bottom, double left) o new Insets(10)
o new Insets(0, 10, 0, 10)
setPrefHeight
setPrefSize
setPrefWidth
setSnapToPixel
setWidth
widthProperty
2.3 Labeled
ObjectProperty<Pos> alignmentProperty()
o Specifies how the text and graphic within the Labeled should be aligned when there is empty space within the Labeled.
ObjectProperty<ContentDisplay> contentDisplayProperty() o Specifies the positioning of the graphic relative to the text.
StringProperty ellipsisStringProperty()
o Specifies the string to display for the ellipsis when text is truncated.
ObjectProperty<Font> fontProperty()
Pos getAlignment()
ContentDisplay getContentDisplay()
String getEllipsisString()
Font getFont()
Node getGraphic()
double getGraphicTextGap()
Insets getLabelPadding()
double getLineSpacing()
String getText()
TextAlignment getTextAlignment()
Paint getTextFill()
OverrunStyle getTextOverrun()
ObjectProperty<Node> graphicProperty() o An optional icon for the Labeled.
DoubleProperty graphicTextGapProperty()
o The amount of space between the graphic and text
boolean isMnemonicParsing()
o Gets the value of the property mnemonicParsing.
boolean isUnderline()
boolean isWrapText()
ReadOnlyObjectProperty<Insets> labelPaddingProperty() o The padding around the Labeled's text and graphic content.
DoubleProperty lineSpacingProperty()
o Specifies the space in pixel between lines.
BooleanProperty mnemonicParsingProperty()
o MnemonicParsing property to enable/disable text parsing.
void setAlignment(Pos value) o import javafx.geometry.Pos;
BASELINE_CENTER
BASELINE_LEFT
BASELINE_RIGHT
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
CENTER_LEFT
CENTER_RIGHT
TOP_CENTER
TOP_LEFT
TOP_RIGHT
o label.setAlignment(Pos.BASELINE_LEFT);
void setContentDisplay(ContentDisplay value)
void setEllipsisString(String value)
void setFont(Font value)
o import javafx.scene.text.Font;
o new Font(22)
o new Font("Courier New",22)
void setGraphic(Node value)
void setGraphicTextGap(double value)
void setLineSpacing(double value)
void setMnemonicParsing(boolean value)
void setText(String value)
void setTextAlignment(TextAlignment value)
void setTextFill(Paint value)
void setTextOverrun(OverrunStyle value)
void setUnderline(boolean value)
void setWrapText(boolean value)
ObjectProperty<TextAlignment> textAlignmentProperty()
o Specifies the behavior for lines of text when text is multiline Unlike
contentDisplayProperty() which affects the graphic and text, this setting only affects multiple lines of text relative to the text bounds.
ObjectProperty<Paint> textFillProperty() o The Paint used to fill the text.
ObjectProperty<OverrunStyle> textOverrunProperty()
o Specifies the behavior to use if the text of the Labeled exceeds the available space for rendering the text.
StringProperty textProperty()
o The text to display in the label.
String toString()
BooleanProperty underlineProperty()
BooleanProperty wrapTextProperty()
2.4 TextInputControl
3 Einfache Controls 3.1 Button
3.1.1 Konstruktoren
Button()
Button (String text)
Button (double value, Node graphic)
3.1.2 Methoden
BooleanProperty cancelButtonProperty()
protected Skin<?> createDefaultSkin()
o Create a new instance of the default skin for this control.
BooleanProperty defaultButtonProperty()
void fire()
o Invoked when a user gesture indicates that an event for this ButtonBase should occur.
boolean isCancelButton()
boolean isDefaultButton()
void setCancelButton(boolean value)
void setDefaultButton(boolean value)
3.1.3 Event
bn. setOnAction(e->action());
3.2 CheckBox
Hinweise:
Normalerweise hat eine CheckBox zwei Zustände.
Für Datenbank benötigt man zusätzlich noch den Zustand „undefined“
chkbox.setAllowIndeterinate(true) // Aktivieren import javafx.scene.control.CheckBox
3.2.1 Konstruktor:
public CheckBox()
public CheckBox (String text)
public CheckBox (String text, Node graphic)
3.2.2 Methoden
void setAllowIndeterminate(boolean value)
void setIndeterminate(boolean value)
void setSelected(boolean value)
boolean isSelected()
boolean isAllowIndeterminate()
void setText(String)
void setWrapText(String)
void setDisable(boolean value)
void setVisible(boolean value)
void setTextAlignment(TextAlignment value) // javafx.scene.text.TextAlignment o CENTER
o LEFT o RIGHT o JUSTIFY
void setAlignment(Pos value) o import javafx.geometry.Pos;
BASELINE_CENTER
BASELINE_LEFT
BASELINE_RIGHT
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
CENTER_LEFT
CENTER_RIGHT
TOP_CENTER
TOP_LEFT
void setFont(Font value)
o import javafx.scene.text.Font;
o new Font(22)
o new Font("Courier New",22)
3.2.3 Event
chkbox.selectedProperty().addListener(new ChangeListener<Boolean>() { @Override
public void changed(ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) {
if(newValue){
// aktion }else{
// aktion } }
});
chk.setOnAction(new EventHandler<ActionEvent>() { @Override
public void handle(ActionEvent e) { aktion();
} });
3.3 ChoiceBox
import javafx.scene.control.ChoiceBox
3.3.1 Konstruktor:
public ChoiceBox()
public ChoiceBox(ObservableList<T> items)
3.3.2 Methoden
getItems().add(String)
Object getValue()
ObservableList<T> getItems()
void setItems(ObservableList<T> value) o import javafx.collections.*;
void show()
o öffnet die Liste
void setDisable(boolean value)
void setVisible(boolean value)
void setTextAlignment(TextAlignment value) // javafx.scene.text.TextAlignment o CENTER
o LEFT o RIGHT o JUSTIFY
void setAlignment(Pos value) o import javafx.geometry.Pos;
BASELINE_CENTER
BASELINE_LEFT
BASELINE_RIGHT
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
CENTER_LEFT
CENTER_RIGHT
TOP_CENTER
TOP_LEFT
void setFont(Font value) o geht nicht
o Alternative
choicePizzaName.setPrefWidth(150);
choicePizzaName.getItems().addAll("Käse","Käse Schinken");
choicePizzaName.setStyle("-fx-font: 22px \"Serif\";");
3.3.3 Abfragen
String pizza = (String)choicePizzaName.getValue();
if (pizza==null) {
errorBox("Bitte geben Sie einen Pizzanamen ein","Hinweis");
return;
}
3.3.4 Event
import javafx.beans.value.*; // ChangeListener // wenn editable(true), dann feuert das Event nicht
choicePizzaName.getSelectionModel().selectedIndexProperty().addListener(
new ChangeListener<Number>() { @Override
public void changed(
ObservableValue<? extends Number> observableValue, Number number,
Number number2) {
showChoicePizzaName(number2);
} });
private void showChoicePizzaName(Number index) {
System.out.println("cbPizzaName: index: "+ index);
}
3.4 ComboBox
import javafx.scene.control.ComboBox<T>
3.4.1 Konstruktor:
public ComboBox()
public ComboBox(ObservableList<T> items)
ComboBox<Student> cb = ComboBox<>();
3.4.2 Methoden
getItems().add(String)
getItems().addAll(String, String, String)
getItems().addAll(T,T, T)
void setItems(ObservableList<T> value) o import javafx.collections.*;
Object getValue()
ObservableList<T> getItems()
void setPromptText(String)
void setEditable(boolean)
void setVisibleRowCount(int)
void setButtonCell(ListCell<T> value)
void show()
o öffnet die Liste
void setDisable(boolean value)
void setVisible(boolean value)
void setTextAlignment(TextAlignment value) // javafx.scene.text.TextAlignment o CENTER
o LEFT o RIGHT o JUSTIFY
void setAlignment(Pos value) o import javafx.geometry.Pos;
BASELINE_CENTER
BASELINE_LEFT
BASELINE_RIGHT
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
CENTER_LEFT
CENTER_RIGHT
TOP_CENTER
TOP_LEFT
void setFont(Font value)
o import javafx.scene.text.Font;
o new Font(22)
o new Font("Courier New",22)
3.4.3 Abfragen
String pizza = (String)cbPizzaName.getValue();
if (pizza==null) {
errorBox("Bitte geben Sie einen Pizzanamen ein","Hinweis");
return;
}
3.4.4 Beispiele:
String week_days[] = {
"Monday", "Tuesday", "Wednesday", "Thrusday", "Friday" };
ComboBox cb =
new ComboBox(FXCollections.observableArrayList(week_days));
3.4.5 Event:
EventHandler<ActionEvent> event = new EventHandler<ActionEvent>() { public void handle(ActionEvent e) {
selected.setText(combo_box.getValue() + " selected");
} };
// Set on action
cb.setOnAction(event);
// Set on action
cb.setOnAction(new EventHandler<ActionEvent>() { public void handle(ActionEvent e) {
selected.setText(combo_box.getValue() + " selected");
} });
3.5 Label
3.5.1 Konstruktoren
Label()
Label (String text)
Label(String text, Node graphic)
3.6 MenuBar
3.6.1 Konstruktor:
public MenuBar()
public MenuBar(Menu, Menu, Menu)
3.7 Menu
3.7.1 Konstruktor:
public Menu()
public Menu(String text)
public Menu(String text, Node graphic)
3.7.2 Methoden
void setAccelerator(KeyCombination value) void setDisable(boolean value)
void setVisible(boolean value)
3.8 MenuItem
3.8.1 Konstruktor:
public MenuItem()
public MenuItem(String text)
public MenuItem(String text, Node graphic)
3.8.2 Methoden
void setAccelerator(KeyCombination value) void setDisable(boolean value)
void setVisible(boolean value) Weitere MenuItems:
RadioMenuItem { text: "Font 1", toggleGroup: fontGroup }
CheckMenuItem
3.8.3 SeparatorMenuItem new SeparatorMenuItem()
3.8.4 ShortKey
import javafx.scene.input.KeyCombination
menuOpen.setAccelerator(KeyCombination.keyCombination("Ctrl+O"));
3.8.5 CSS:
scene.getStylesheets().add("Menu.css");
1. Beispiel
.menu, .menu-item { -fx-text-fill: blue ; -fx-font-size:22;
}
2. Beispiel:
.menu-item .label{
-fx-text-fill: greenyellow;
}
*.popup-menu {
-fx-background-color:
linear (0%,0%) to (0%,100%) stops (0%,#383838) (100%,#141414);
}
3. Beispiel:
.menu {
-fx-text-fill: #ffffff;
}
*.menu-item {
-fx-text-fill: #ffffff;
}
4. Beispiel:
root.setStyle("-fx-padding: 10;" + "-fx-border-style: solid inside;" + "-fx-border-width: 2;" +
"-fx-border-insets: 5;" + "-fx-border-radius: 5;" + "-fx-border-color: blue;");
3.9 RadioButton
import javafx.scene.control.RadioButton 3.9.1 Konstruktor:
public RadioButton ()
public RadioButton(String)
3.9.2 Methoden
void setSelected(boolean);
bn1.setToggleGroup(group); // javafx.scene.control.ToggleButton
boolean isSelected()
String getText()
void setDisable(boolean value)
void setVisible(boolean value)
void setTextAlignment(TextAlignment value) // javafx.scene.text.TextAlignment o CENTER
o LEFT o RIGHT o JUSTIFY
void setAlignment(Pos value) o import javafx.geometry.Pos;
BASELINE_CENTER
BASELINE_LEFT
BASELINE_RIGHT
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
CENTER_LEFT
CENTER_RIGHT
TOP_CENTER
TOP_LEFT
void setFont(Font value)
o import javafx.scene.text.Font;
o new Font(22)
o new Font("Courier New",22)
3.9.3 Event
rb.setOnAction(new EventHandler<ActionEvent>() { @Override
public void handle(ActionEvent e) { setAction();
} });
3.9.4 Abfragen
String pizza = (String)cbPizzaName.getValue();
if (pizza==null) {
errorBox("Bitte geben Sie einen Pizzanamen ein","Hinweis");
return;
}
3.9.5 Beispiele:
RadioButton rb1 = new RadioButton("Mündliche Prüfung");
RadioButton rb2 = new RadioButton("Hausarbeit");
RadioButton rb3 = new RadioButton("Klausur");
ToggleGroup group1 = new ToggleGroup(); // javafx.scene.control.ToggleButton rb1.setToggleGroup(group1);
rb2.setToggleGroup(group1);
rb3.setToggleGroup(group1);
rb1.setSelected(true);
RadioButton rb4 = new RadioButton("Morgens");
RadioButton rb5 = new RadioButton("Mittags");
RadioButton rb6 = new RadioButton("Nachmittags");
ToggleGroup group2 = new ToggleGroup();
Rb4.setToggleGroup(group2);
rb5.setToggleGroup(group2);
rb6.setToggleGroup(group2);
3.9.6 Event:
ToggleGroup togglegroup = new ToggleGroup(); // javafx.scene.control.ToggleButton rbTyp1 = new MyRadioButton("Typ1", group1, vbox1, 0);
rbTyp2 = new MyRadioButton("Typ2", group1, vbox1, 1);
rbTyp3 = new MyRadioButton("Typ3", group1, vbox1, 1);
rbTyp4 = new MyRadioButton("Typ4", group1, vbox1, 2);
togglegroup.selectedToggleProperty().addListener(new ChangeListener<Toggle>() {
public void changed(ObservableValue<? extends Toggle> ob, Toggle o, Toggle n) { RadioButton rb = (RadioButton)togglegroup.getSelectedToggle();
if (rb != null) {
// Action showPane(rb.getText());
} } });
3.10 Slider
import javafx.scene.control.Slider 3.10.1 Konstruktor:
public Slider()
public Slider(double min, double max, double value);
3.10.2 Methoden
void adjustValue(double newValue)
void decrement()
void increment()
void setBlockIncrement(double value)
setLabelFormatter(StringConverter<Double> value)
setMajorTickUnit(double value)
setMax(double value)
void setMin(double value)
void setMinorTickCount(int)
void setMajorTickUnit(double);
void setOrientation(Orientation value) o javafx.geometry.Orientation
void setShowTickLabels(boolean value)
void setShowTickMarks(boolean value)
void setSnapToTicks(boolean value)
void setValue(double value)
double getValue()
void setDisable(boolean value)
void setVisible(boolean value)
void setTextAlignment(TextAlignment value) // javafx.scene.text.TextAlignment o CENTER
o LEFT o RIGHT o JUSTIFY
void setAlignment(Pos value) o import javafx.geometry.Pos;
BASELINE_CENTER
BASELINE_LEFT
BASELINE_RIGHT
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
CENTER_LEFT
CENTER_RIGHT
TOP_CENTER
TOP_LEFT
void setFont(Font value)
o import javafx.scene.text.Font;
o new Font(22)
o new Font("Courier New",22)
3.10.3 Abfragen
double size = sliderSize.getValue();
3.10.4 Event
import javafx.beans.value.*; // ChangeListener
sliderSize.valueProperty().addListener(new ChangeListener<Number>() { @Override public void changed(
ObservableValue<? extends Number> observableValue, Number oldValue, Number newValue) {
showSliederGroesse(newValue);
} });
private void showSliederGroesse(Number value) {
System.out.println("SpinnerGroesse: index: "+ value);
}
3.10.5 Beispiele:
sliderSize = new Slider(5, 25.0, 2.0);
sliderSize.setMajorTickUnit(1.0);
sliderSize.setMinorTickCount(4.0);
sliderSize.setShowTickLabels(true);
sliderSize.setShowTickMarks(true);
sliderSize.setSnapToTicks(true);
Abbildung 1 Sliderbeispiel
3.11 Spinner
import javafx.scene.control.Spinner
3.11.1 Konstruktor:
public Spinner()
Spinner(double min, double max, double initialValue)
Spinner(double min, double max, double initialValue, double amountToStepBy)
Spinner(int min, int max, int initialValue)
Spinner(int min, int max, int initialValue, int amountToStepBy)
Spinner(ObservableList<T> items)
o import javafx.collections.*;
Spinner(SpinnerValueFactory<T> valueFactory)
3.11.2 Methoden
Object getValue()
void decrement()
void decrement(int steps)
void increment()
void increment(int steps)
boolean isEditable()
void setEditable(boolean value)
void setDisable(boolean value)
void setVisible(boolean value)
void setTextAlignment(TextAlignment value) // javafx.scene.text.TextAlignment o CENTER
o LEFT o RIGHT
o JUSTIFY
void setAlignment(Pos value) o import javafx.geometry.Pos;
BASELINE_CENTER
BASELINE_LEFT
BASELINE_RIGHT
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
CENTER_LEFT
CENTER_RIGHT
TOP_CENTER
TOP_LEFT
void setFont(Font value) o geht nicht
o Alternative
sp1.setPrefWidth(150);
sp1.setStyle("-fx-font: 22px \"Serif\";");
3.11.3 SpinnerValueFactory
Integer:
int min=1;
int max=10;
int initialValue=3;
SpinnerValueFactory<Integer> valueFactory = new
SpinnerValueFactory.IntegerSpinnerValueFactory(min, max, initialValue);
spinner.setValueFactory(valueFactory);
Double:
double min=1.0;
double max=10.0;
double initialValue=0.5;
SpinnerValueFactory<Double> valueFactory = new
SpinnerValueFactory. DoubleSpinnerValueFactory(min, max, initialValue);
spinner.setValueFactory(valueFactory);
3.11.4 Spinner-Styles
Spinner.STYLE_CLASS_ARROWS_ON_RIGHT_HORIZONTAL
Spinner.STYLE_CLASS_ARROWS_ON_LEFT_VERTICAL
Spinner.STYLE_CLASS_ARROWS_ON_LEFT_HORIZONTAL
Spinner.STYLE_CLASS_SPLIT_ARROWS_VERTICAL
Spinner.STYLE_CLASS_SPLIT_ARROWS_HORIZONTAL
spinner.getStyleClass().add(StyleClass);
3.11.5 Abfragen
String pizza = (String)spPizzaName.getValue();
if (pizza==null) {
errorBox("Bitte wählen Sie einen Pizzanamen aus","Hinweis");
return;
}
3.11.6 Event
import javafx.beans.value.*; // ChangeListener
spGroesse.valueProperty().addListener(
(obs, oldValue, newValue) -> showSpinnerGroesse(newValue));
private void showSpinnerGroesse(Object obj) {
System.out.println("SpinnerGroesse: objindex: "+ obj);
}
3.11.7 Beispiel mit Liste
import javafx.collections.*;
private Spinner spTypen = new Spinner();
ObservableList<String> typen = FXCollections.observableArrayList(
"Typ1", "Typ2", "Typ3", "Typ4");
SpinnerValueFactory<String> valueFactory = new
SpinnerValueFactory.ListSpinnerValueFactory<String>( typen);
// Default value setzen
valueFactory.setValue("Hawaii");
spTypen.setValueFactory(valueFactory);
spTypen.setStyle("-fx-font: 22px \"Serif\";");
3.12 TextArea
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TextArea.html
3.12.1 Konstruktoren
TextArea()
TextArea(String text)
3.12.2 Methoden
String getText()
void setText(String str)
void setEditable(boolean)
void cut()
void copy()
void paste()
int getCaretPosition()
void positionCaret(int pos)
selectPositionCaret(int pos)
void clear()
void undo()
void redo()
String getSelectedText()
void setPrefColumnCount(int value)
void setPrefRowCount(int value)
void setWrapText(boolean value)
void setContextMenu(ContextMenu value)
void setTextAlignment(TextAlignment value)
void setOnAction(EventHandler<ActionEvent> value)
void setAlignment(Pos value) o import javafx.geometry.Pos;
BASELINE_CENTER
BASELINE_LEFT
BASELINE_RIGHT
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
CENTER_LEFT
CENTER_RIGHT
TOP_CENTER
TOP_LEFT
TOP_RIGHT
void setFont(Font value)
o import javafx.scene.text.Font;
o new Font(22)
o new Font("Courier New",22)
3.12.3 eEvent
setOnContextMenuRequested
setOnDragDetected
setOnDragDone
setOnDragDropped
setOnDragEntered
setOnDragExited
setOnDragOver
setOnInputMethodTextChanged
setOnKeyPressed
setOnKeyReleased
setOnKeyTyped
setOnMouseClicked
setOnMouseDragEntered
setOnMouseDragExited
setOnMouseDragged
setOnMouseDragOver
setOnMouseDragReleased
setOnMouseEntered
setOnMouseExited
setOnMouseMoved
setOnMousePressed
setOnMouseReleased
setOnRotate
setOnRotationFinished
setOnRotationStarted
setOnScroll
setOnScrollFinished
setOnScrollStarted
setOnSwipeDown
setOnSwipeLeft
setOnSwipeRight
setOnSwipeUp
setOnTouchMoved
setOnTouchPressed
setOnTouchReleased
setOnTouchStationary
3.13 TextField
https://docs.oracle.com/javase/8/javafx/api/javafx/scene/control/TextField.html
3.13.1 Konstruktoren
TextField()
TextField(String text)
3.13.2 Methoden
String getText()
void setText(String str)
void setPromptText(String value)
void setEditable(boolean)
void setTextFormatter(TextFormatter<?> value)
void setContextMenu(ContextMenu value)
void setTextAlignment(TextAlignment value)
void setOnAction(EventHandler<ActionEvent> value)
void setAlignment(Pos value) o import javafx.geometry.Pos;
BASELINE_CENTER
BASELINE_LEFT
BASELINE_RIGHT
BOTTOM_CENTER
BOTTOM_LEFT
BOTTOM_RIGHT
CENTER
CENTER_LEFT
CENTER_RIGHT
TOP_CENTER
TOP_LEFT
TOP_RIGHT
void setContentDisplay(ContentDisplay value)
void setEllipsisString(String value)
void setFont(Font value)
o import javafx.scene.text.Font;
o new Font(22)
o new Font("Courier New",22)
3.14 HTMLEditor
3.15 Platform
import javafx.application.Platform;
3.15.1 Dialog beenden Platform.exit();
4 Canvas Control
import javafx.scene.paint.*;
import javafx.scene.canvas.*;
import javafx.scene.canvas.Canvas
4.1.1 Konstruktor:
public Canvas () // nicht verwenden
public Canvas (double width, double height)
4.1.2 Methoden
void setAccelerator(KeyCombination value) void setDisable(boolean value)
void setVisible(boolean value) void setHeight(double value) void setWidth(double value) void setCache(boolean value) void setClip(Node value) void setCursor(Cursor value) void setDisable(boolean value) void setDisabled(boolean value) void setVisible(boolean value) Beispiel:
Canvas canvas = new Canvas(250,250);
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.setFill(Color.BLUE);
gc.fillRect(75,75,100,100);
root.getChildren().add(canvas);
4.2 GraphicsContext
javafx.scene.canvas.GraphicsContext
4.2.1 Wichtige Funktionen
void beginPath()
o Resets the current path to empty.
void clearRect(double x, double y, double w, double h)
o Clears a portion of the canvas with a transparent color value.
void closePath() o Closes the path.
void lineTo(double x1, double y1)
o Adds segments to the current path to make a line to the given x,y coordinate.
void moveTo(double x0, double y0)
o Issues a move command for the current path to the given x,y coordinate.
void rect(double x, double y, double w, double h)
o Adds path elements to the current path to make a rectangle.
void setLineDashes(double... dashes)
o Sets the current stroke line dash pattern to a normalized copy of the argument.
void setLineDashOffset(double dashOffset) o Sets the line dash offset.
void setLineWidth(double lw) o Sets the current line width.
void stroke()
o Strokes the path with the current stroke paint.
void strokeLine(double x1, double y1, double x2, double y2) o Strokes a line using the current stroke paint.
void strokeOval(double x, double y, double w, double h) o Strokes an oval using the current stroke paint.
void strokePolygon(double[] xPoints, double[] yPoints, int nPoints)
o Strokes a polygon with the given points using the currently set stroke paint.
void strokePolyline(double[] xPoints, double[] yPoints, int nPoints)
o Strokes a polyline with the given points using the currently set stroke paint attribute.
void strokeRect(double x, double y, double w, double h) o Strokes a rectangle using the current stroke paint.
void strokeRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
o Strokes a rounded rectangle using the current stroke paint.
void bezierCurveTo(double xc1, double yc1, double xc2, double yc2, double x1, double y1) o Adds segments to the current path to make a cubic Bezier curve.
void clearRect(double x, double y, double w, double h)
o Clears a portion of the canvas with a transparent color value.
4.2.2 Farben
Color.BLACK / Color.RED
Color.rgb(230, 230, 230)
Color.web("0x5555FF",1.0)
setStroke(Color) // LinienFarben
setFill( Color )
4.2.3 FontWeight
javafx.scene.text.FontWeight Konstanten:
THIN
EXTRA_LIGHT
LIGHT
NORMAL
MEDIUM
SEMI_BOLD
BOLD
EXTRA_BOLD 800
BLACK 900
Beispiel:
gc.setFont(Font.font("Verdana", FontWeight.THIN, 40));
4.2.4 Fillfunktionen
void fillOval(double x, double y, double w, double h) o Fills an oval using the current fill paint.
void fillPolygon(double[] xPoints, double[] yPoints, int nPoints)
o Fills a polygon with the given points using the currently set fill paint.
void fillRect(double x, double y, double w, double h) o Fills a rectangle using the current fill paint.
void fillRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight) o Fills a rounded rectangle using the current fill paint.
4.2.5 Textfunktionen
void strokeText(String text, double x, double y)
o Draws the given string of text at position x, y with the current stroke paint attribute.
void strokeText(String text, double x, double y, double maxWidth)
o Draws text with stroke paint and includes a maximum width of the string.
o Umrandeter Text, besser fillText
void fillText(String text, double x, double y)
o Fills the given string of text at position x, y with the current fill paint attribute.
void fillText(String text, double x, double y, double maxWidth) o Fills text and includes a maximum width of the string.
void setTextAlign(TextAlignment align)
o Defines horizontal text alignment, relative to the text x origin.
void setTextBaseline(VPos baseline) o Sets the current Text Baseline.
Textlänge, Texthöhe
o javafx.geometry.Bounds
o Bounds bounds = TextBuilder.create().text(text).font(font).build().getLayoutBounds();
o double width=bounds.getWidth();
o double height=bounds.getHeight();
4.2.6 Restliche Funktionen
void arc(double centerX, double centerY, double radiusX, double radiusY, double startAngle, double length)
o Adds path elements to the current path to make an arc that uses Euclidean degrees.
void arcTo(double x1, double y1, double x2, double y2, double radius)
o Adds segments to the current path to make an arc.
void beginPath()
o Resets the current path to empty.
void clip()
o Intersects the current clip with the current path and applies it to subsequent rendering operation as an anti-aliased mask.
void closePath() o Closes the path.
void drawImage(Image img, double x, double y)
o Draws an image at the given x, y position using the width and height of the given image.
void drawImage(Image img, double x, double y, double w, double h) o Draws an image into the given destination rectangle of the canvas.
void drawImage(Image img, double sx, double sy, double sw, double sh, double dx, double dy, double dw, double dh)
o Draws the specified source rectangle of the given image to the given destination rectangle of the Canvas.
void fill()
o Fills the path with the current fill paint.
void fillArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
o Fills an arc using the current fill paint.
Canvas getCanvas()
o Gets the Canvas that the GraphicsContext is issuing draw commands to.
Effect getEffect(Effect e)
o Gets a copy of the effect to be applied after the next draw call.
Paint getFill()
o Gets the current fill paint attribute.
FillRule getFillRule()
o Get the filling rule attribute for determining the interior of paths in fill and clip operations.
Font getFont()
o Gets the current Font.
FontSmoothingType getFontSmoothingType() o Gets the current Font Smoothing Type.
double getGlobalAlpha()
o Gets the current global alpha.
boolean isPointInPath(double x, double y)
o Returns true if the the given x,y point is inside the path.
void quadraticCurveTo(double xc, double yc, double x1, double y1) o Adds segments to the current path to make a quadratic Bezier curve.
void restore()
o Pops the state off of the stack, setting the following attributes to their value at the time when that state was pushed onto the stack.
void rotate(double degrees)
o Rotates the current transform in degrees.
void save()
o Saves the following attributes onto a stack.
void scale(double x, double y)
o Scales the current transform by x, y.
void setEffect(Effect e)
o Sets the effect to be applied after the next draw call, or null to disable effects.
void setFill(Paint p)
o Sets the current fill paint attribute.
void setFillRule(FillRule fillRule)
o Set the filling rule attribute for determining the interior of paths in fill or clip operations.
void setFont(Font f) o Sets the current Font.
void setFontSmoothingType(FontSmoothingType fontsmoothing) o Sets the current Font Smoothing Type.
void setGlobalAlpha(double alpha)
o Sets the global alpha of the current state.
void setGlobalBlendMode(BlendMode op) o Sets the global blend mode.
void setLineCap(StrokeLineCap cap) o Sets the current stroke line cap.
void setLineJoin(StrokeLineJoin join) o Sets the current stroke line join.
void setMiterLimit(double ml) o Sets the current miter limit.
void setStroke(Paint p)
o Sets the current stroke paint attribute.
void setTransform(Affine xform) o Sets the current transform.
void setTransform(double mxx, double myx, double mxy, double myy, double mxt, double myt) o Sets the current transform.
void stroke()
o Strokes the path with the current stroke paint.
void strokeArc(double x, double y, double w, double h, double startAngle, double arcExtent, ArcType closure)
o Strokes an Arc using the current stroke paint.
void strokeRoundRect(double x, double y, double w, double h, double arcWidth, double arcHeight)
o Strokes a rounded rectangle using the current stroke paint.
void transform(Affine xform)
o Concatenates the input with the current transform.
void transform(double mxx, double myx, double mxy, double myy, double mxt, double myt) o Concatenates the input with the current transform.
void translate(double x, double y)
o Translates the current transform by x, y.
4.2.7 Beispiele
import javafx.scene.canvas.*;
private final int MAX=700
// man muss eine Breite und Höhe angeben
// mit dem ScrollPane kann die Canvasgröße deutlich größer // als die Fenstergröße sein
Canvas canvas = canvas = new Canvas(1000,1000) ;
public void start(Stage stage) { this.stage = stage;
BorderPane root = new BorderPane();
root.setTop( setTopElements() );
root.setCenter( new ScrollPane(canvas) );
root.setBottom( setBottomElements() );
draw?();
Scene scene= new Scene(root, 590, 650);
stage.setTitle("UIBsp15_Canvas");
stage.setScene(scene);
stage.show();
}
private void draw1() {
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.beginPath();
gc.clearRect(0,0, MAX, MAX);
gc.setFill(Color.RED);
gc.setLineWidth(12);
gc.setStroke(Color.GREEN); // Linienfarbe gc.moveTo(MAX,0);
gc.lineTo(0, MAX);
gc.stroke();
}
Abbildung 2 draw-Beispiel1
private void draw2() {
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.beginPath();
gc.clearRect(0,0, MAX, MAX);
gc.setStroke(Color.YELLOW); // Linienfarbe gc.setFill(Color.BLUE);
gc.fillRect(75,75,100,100);
gc.setLineWidth(12);
gc.setFill(Color.RED);
gc.strokeRect(5,5,55,100);
gc.setLineWidth(12);
gc.setStroke(Color.GREEN);
gc.strokeRect(65,5,55,100);
}
Abbildung 3 draw-Beispiel2
private void draw3() {
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.beginPath();
gc.clearRect(0,0,MAX,MAX);
gc.setFill(Color.RED);
gc.setLineWidth(5);
gc.setStroke(Color.GREEN); // Linienfarbe gc.strokeRect(65,5,55,100);
gc.setStroke(Color.BLUE); // Linienfarbe gc.rect(165,5,55,100);
gc.setLineWidth(4);
gc.setStroke(Color.MAGENTA); // Linienfarbe gc.setLineDashes(30,10);
gc.setLineDashOffset(20.0);
gc.strokeLine(500,0, 0,500);
gc.stroke();
}
Abbildung 4 draw-Beispiel3
private void draw4() {
GraphicsContext gc = canvas.getGraphicsContext2D();
gc.beginPath();
gc.clearRect(0,0,MAX,MAX);
gc.setLineWidth(4);
gc.setStroke(Color.MAGENTA); // Linienfarbe gc.setLineDashes(30,10);
gc.setLineDashOffset(20.0);
gc.strokeOval(200,200,150,150); // x,y,w,h gc.setLineWidth(2);
gc.setStroke(Color.RED); // Linienfarbe gc.setLineDashes(100,10);
gc.setLineDashOffset(40.0);
// x,y,w,h roundx, roundy
gc.strokeRoundRect(200,200,150,150,30,10);
gc.stroke(); // nun zeichnen }