javafx stagestyle UNDECORATED - javafx

I'm using a translator.
enter image description here
Windows desktop appears unexpectedly when you click on the image.
Scrollpane -> BorderPane
Normal at first Occurs like an image later
FXMLLoader loader = new FXMLLoader(getClass().getResource("/View/Main_fx.fxml"));
Parent root = loader.load();
st = new Stage();
final UndecoratorScene undecorator = new UndecoratorScene(st, (Region) root);//NewMainScene lib 사용(프로젝트 및 패키지 명 :Newtable)
undecorator.getStylesheets().add(getClass().getResource("/View/winDec.css").toExternalForm());
st.setScene(undecorator);
stage = (Stage) lb.getScene().getWindow();
st.getIcons().add(new Image(config2.class.getResourceAsStream("/View/207411.jpg" )));
st.initStyle(StageStyle.TRANSPARENT); //스타일 미적용.
st.setResizable(resize);
st.setMaximized(maximized);
st.setTitle(judul);
st.sizeToScene();
// Undecorator undecor = undecorator.getUndecorator();
//최소로 줄이수 있는 화면 크기 값 .
st.setMinWidth(350);
st.setMinHeight(200);
GetStage gs = new GetStage();//트레이 창으로 보낼때 현재 Stage 값 전달.
gs.SetStage(st);
st.toFront();
st.show();
Rectangle2D primScreenBounds = Screen.getPrimary().getVisualBounds();
st.setX((primScreenBounds.getWidth() - st.getWidth()) / 2);
st.setY((primScreenBounds.getHeight() - st.getHeight()) / 2);
createTrayIcon(st);//트레이 창 이벤트 메소드
firstTime = true;
Platform.setImplicitExit(false);
stage.close();//controllSplash stage 종료
Hander_Main controller = (Hander_Main)loader.getController();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:00");
Date sys_date = new Date();
String now= formatter.format(sys_date);
controller.setPrimaryStage(st);
controller.setScene(undecorator);
controller.setFirstDate(now);
st.setOnCloseRequest(new EventHandler<WindowEvent>() {
public void handle(WindowEvent we)
{
hide(st);
}
});
} catch (Exception e) {
st.hide();
dialog(Alert.AlertType.ERROR,"Main_fx Stage ERR\n"+e);
System.exit(0);
}

Related

why javafx mediaplayer status sometimes returns unknown?

First i am sorry for my poor english...
i made Media Player Application with Javafx.
this player can get mulit file media. and play files out of all limits.
it work well. but sometimes not work..
it is not media error. it is mediaplayer error.
error message is 'mediaPlayer Unknown, media Invalid..' why.??
i played same video file(1920 * 1080), sometimes work and sometimes not work..
and javafx is depend on OS ??
player works perfectly on windown7 computer
but player have this error on windown10 computer...
please give me advice..
MediaPlayer mediaPlayer = null;
Stage stage = new Stage();
AnchorPane pane = new AnchorPane();
Scene scene = new Scene(pane);
MediaView mediaView = new MediaView();
int mNextFileIndex = -1;
List<File> fileLists = new ArrayList<>();
Media media;
mediaplayer play Method
public void playNextMedia() {
if (mediaPlayer != null) {
mediaPlayer.dispose();
mediaView.setMediaPlayer(null);
}
mNextFileIndex = (mNextFileIndex + 1) % fileLists.size();
media =new Media(fileLists.get(mNextFileIndex).toURI().toString());
media.setOnError(()-> {
MainApp.makeLog("media error");
});
mediaPlayer = new MediaPlayer(media);
mediaView.setMediaPlayer(mediaPlayer);
mediaPlayer.setOnReady(() -> {
mediaPlayer.play();
});
mediaPlayer.setOnEndOfMedia(() -> {
playNextMedia();
});
mediaPlayer.setOnError(() -> {
systom.out.println("mediaPlayer error");
Systeom.out.println(mediaPlayer.getError().getMessage());
playNextMedia();
});
}
Button Method
#FXML
private void playMedia(ActionEvent event) {
mNextFileIndex = -1;
FileChooser fileChooser = new FileChooser();
fileChooser.getExtensionFilters().addAll(new
FileChooser.ExtensionFilter("Select a File (*.mp4)", "*.mp4"),
new FileChooser.ExtensionFilter("All Files", "*.*"));
List<File> list = fileChooser.showOpenMultipleDialog(null);
if (list != null) {
for (File file : list) {
fileLists.add(file)
}
playNextMedia();
pane.getChildren().add(mediaView);
stage.setScene(scene);
stage.show();
}

How to get data from Tab in Tabpane JavaFX

I want get data from Tab in Tabpane JavaFX
I have 2 Tab in Tabpane, And each Tab I have a TextArea, I want click Button will get data from 2 tab
Here's my code:
btnThem.setOnAction(new EventHandler<ActionEvent>() {
#Override
public void handle(ActionEvent event) {
try {
i++;
FXMLLoader fxmlLoader = new FXMLLoader(
getClass().getResource("/fxml/tab.fxml"));
Parent parent = (Parent) fxmlLoader.load();
Tab tab = new Tab("Điểm " + i);
tab.setContent(parent);
tab.setClosable(true);
tabPane.getTabs().add(tab);
controllerTab = (ControllerTab) fxmlLoader.getController();
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
}
});
Your question is ambiguous but it seems you want to get data from each textArea in tab.To do this you should get nodes (children) from each tab and by using lookup() we confirm and we parse node to textArea.I tried to figure your scene and made this example to help you :
public class example extends Application {
TextArea textArea = new TextArea();
TextArea textArea1 = new TextArea();
Button button = new Button("button");
#Override
public void start(Stage primaryStage) {
Tab tab1 = new Tab("tab1");
Tab tab2 = new Tab("tab2");
tab1.setContent(textArea);
tab2.setContent(textArea1);
TabPane pane = new TabPane();
pane.getTabs().addAll(tab1, tab2);
Node node1 = tab1.getContent();
Node node2 = tab2.getContent();
button.setOnAction((ActionEvent event) -> {
if (node1.lookup("TextArea") != null && node2.lookup("TextArea") != null) {
TextArea area1 = (TextArea) node1.lookup("TextArea");
TextArea area2 = (TextArea) node2.lookup("TextArea");
System.out.println(area1.getText() + " " + area2.getText());
}
});
VBox root = new VBox();
root.setAlignment(Pos.TOP_RIGHT);
root.getChildren().add(pane);
root.getChildren().add(button);
Scene scene = new Scene(root, 300, 250);
primaryStage.setTitle("Hello World!");
primaryStage.setScene(scene);
primaryStage.show();
}
/**
* #param args the command line arguments
*/
public static void main(String[] args) {
launch(args);
}
}
And you can see the result :
Hello ,tab1 Hello ,tab2
Deleting directory C:\Users\Electron\Documents\NetBeansProjects\Buttono\dist\run341573612
jfxsa-run:
BUILD SUCCESSFUL (total time: 22 seconds)

Unable to settext on javafx text at runtime

please i am trying to settext on a textfield after it as been open from login window but the changes it not displaying pls am new to java and javafx below is the code wich open the new window
try {
Statement stmnt= conn.createStatement();
rs=stmnt.executeQuery(sql);
if(rs.next()==true){
String name = null;
Image img = null;
name = rs.getString("name");
img = new Image(rs.getBinaryStream("photo"));
System.out.println(name);
Stage primaryStage = new Stage();
/*FXMLLoader loader = new FXMLLoader();
Pane root = loader.load(getClass().getResource("main.fxml").openStream());
mainController mnctrl = (mainController) loader.getController();
mnctrl.dispOpInfo(name, img);*/
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("main.fxml"));
Parent root = (Parent)fxmlLoader.load();
mainController controller = fxmlLoader.<mainController>getController();
controller.dispOpInfo(name, img);
primaryStage.show();
Scene scene = new Scene(root);
scene.getStylesheets().add(getClass().getResource("application.css").toExternalForm());
primaryStage.setScene(scene);
primaryStage.setTitle("BECE 2017 Validation");;
primaryStage.getIcons().add(new Image(this.getClass().getResourceAsStream("icon.png")));
primaryStage.show();
//
}
and below is the code for the newly open window of it textfield is not changing at runtime
#FXML TextField txtSchName = new TextField();
public void populateCanInfo (String canSchool, String canName, String canState,String canGender, Image canPhoto){
System.out.println(canGender );
txtCanName.setText(canName);
txtSchName.setText(canSchool);
imgViewCan.setImage(canPhoto);
// int index=cmbCanState.getValue().indexOf(canState);
// cmbCanState.getSelectionModel().select(index);
if(canGender.equalsIgnoreCase(canGender)){
rbtMale.setSelected(true);
}else{
rbtFemale.setSelected(true);
}
}

Show gif animation popup while processing in JAVAFX

I have a method inside of one of my controllers that requires some seconds to process. I would like to have a gif animation popup while this occurs but I only get a static image. This is my code:
#FXML
public void search(ActionEvent e) {
final Stage dialog = new Stage();
Group popup = new Group();
Image image = new Image("file:resources/images/bender.gif");
ImageView view = new ImageView(image);
popup.getChildren().add(view);
Scene dialogScene = new Scene(popup);
dialog.setScene(dialogScene);
dialog.show();
Platform.runLater(new Runnable() {
#Override
public void run() {
Match msg = stablishSearchConditions();
TreeItem<String> root = new TreeItem<>("ROOT");
int indexName = 1;
String mensaje = "Mensaje ";
treeLabelResults.setText("");
arbol.setRoot(root);
for (Match message : msg.each()) {
TreeItem<String> nodo = new TreeItem<String>(mensaje + indexName);
root.getChildren().add(nodo);
root.setExpanded(true);
String mens = message.getMessage();
TreeItem<String> nodo2 = new TreeItem<String>(mens);
nodo.getChildren().add(nodo2);
indexName++;
}
dialog.close();
}
});
}
You are blocking the fx application thread by running the expensive operation on this thread. This prevents your UI from updating, including animating the GIF.
Move the expensive operations to a non-application thread instead and only use Platform.runLater() to "commit" the ui updates:
Runnable expensiveTask = () -> {
// expensive operations that should not run on the application thread
Match msg = stablishSearchConditions();
TreeItem<String> root = new TreeItem<>("ROOT");
int indexName = 1;
String mensaje = "Mensaje ";
for (Match message : msg.each()) {
TreeItem<String> nodo = new TreeItem<String>(mensaje + indexName);
root.getChildren().add(nodo);
root.setExpanded(true);
String mens = message.getMessage();
TreeItem<String> nodo2 = new TreeItem<String>(mens);
nodo.getChildren().add(nodo2);
indexName++;
}
// update ui -> application thread
Platform.runLater(() -> {
treeLabelResults.setText("");
arbol.setRoot(root);
dialog.close();
});
};
// start new thread for expensiveTask
new Thread(expensiveTask).start();

Swing component in JavaFx swing node WRONG mouse events

I have a small test a JButton in a SwingNode in a Stage, using Java 8.
Problem: right click is not triggered, the middle click is interpreted as right click ...
Here is the code:
Platform.runLater(new Runnable() {
#Override
public void run() {
HBox hb = new HBox();
SwingNode n = new SwingNode();
JButton b = new JButton("CLICK ME!!!");
b.addMouseListener(new MouseAdapter() {
public final void mousePressed(MouseEvent e) {
boolean isLeftClick = SwingUtilities.isLeftMouseButton(e);
boolean isRightClick = SwingUtilities.isRightMouseButton(e);
if (isLeftClick)
System.out.println("Left");
if (isRightClick)
System.out.println("Right");
}
});
n.setContent(b);
hb.getChildren().add(n);
Stage stage = new Stage();
Scene appScene = new Scene(hb,100, 100);
stage.setScene(appScene);
stage.show();
}
});

Resources