如何在其他窗格中显示我的面板?

时间:2015-08-24 16:28:24

标签: java javafx

嗨,这是我的问题,我不能将面板显示到根面板,我做类似的聊天有些像skype但我需要显示的部分(消息),它没有显示,当我发送消息给用户。 enter image description here 那么这是我发送信息的代码:

btnSend.setOnAction(new EventHandler<ActionEvent>() {


            @Override
            public void handle(ActionEvent event) {


                String empty = "";
                String sendMessage = txtMensajes.getText();
                String[] talkTo_array = lstDisplayBuddys.getSelectionModel().getSelectedItem().toString().split("-");
                String talkTo = talkTo_array[talkTo_array.length - 1]+"@mpns.mcm.net.mx";

                try{
                    // CONDITION IF ARE EMPTY THE MESSAGES 

                    if (sendMessage.equals(empty)) {
                        JOptionPane.showMessageDialog(null, "Add some message");
                    }
                    else{
                        if (talkTo != sendMessage) {
                            while (true) {

                                try {

                                    sendMessage(XMPPChatHelper.encodeBase64(sendMessage), talkTo);
                                    System.out.println("send message");

                                    //SHOW MY MESSAGES WHEN I SEND IT
                                    Platform.runLater(()->{
                                        pnContArea.getChildren().addAll(drawSendMessage(sendMessage));
                                        txtMensajes.setText("");
                                    });



                                } catch (XMPPException e) {

                                    e.printStackTrace();
                                }
                                break;
                            }
                            ConnectionDBHistorialHelper ConnectionDBHistorialHelper=new ConnectionDBHistorialHelper();
                            ConnectionDBHistorialHelper.saveMessageSend(sendMessage);
                        }
                    }
                }catch(Exception e){

                }
            }

        });

这是将图像和文本绘制到另一个面板的方法:

public StackPane drawSendMessage(String message){
        StackPane paneSend=new StackPane();
        Platform.runLater(()->{
            Text sendMessageText=new Text(message);
            ImageView imaSend=new ImageView(HomeController.class.getResource("/image/isend.png").toExternalForm());
            paneSend.getChildren().addAll(imaSend,sendMessageText);
            paneSend.setAlignment(Pos.BASELINE_LEFT);

        });
        return paneSend;
    }

thnks advanced。

1 个答案:

答案 0 :(得分:0)

他很容易做到这一点你只需要在这种情况下启动任何变量所有窗格

context.sendBroadcast(yourintent);