IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaFX Discussion :

tableview au centre de borderpane


Sujet :

JavaFX

  1. #1
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2020
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Djibouti

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2020
    Messages : 18
    Points : 8
    Points
    8
    Par défaut tableview au centre de borderpane
    voila, j'ai une application qui a :
    un login qui ouvre un borderpane au centre duquel je switch des anchorpanes. tout fonctione
    sauf lorsque je veux charger un tableview. j'ai des erreurs que je copie ici. il y a
    une ligne qui génére ces erreurs et lorsque je la mets en commentaire, il n'y a pas d'erreur,
    mais il ne se passe rien aussi. cette ligne est entre guillemet dans "editController".
    quelqu'un peut avoir une idée ??

    voici la partie du code qui génère ces erreurs:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    public class editController implements Initializable{
     
    	@ FXML private BorderPane bp; 
    	@FXML private AnchorPane ap1;
    	@FXML private Pane ape2;
    	@FXML private Label lbl1;
    	@FXML private ComboBox<String> combo;
    	@FXML private Label lbl2;		
    	@FXML private TextField txt0;
    	@FXML private Button btnshow;
    	@FXML private Pane panecenter;	
    	@FXML private tbviewController tbvc;	
    	@FXML private loginController mc;
     
    	public void setMain(loginController mc) {
    		this.mc = mc;
    	}	
     
    	public ObservableList<String> list = FXCollections.observableArrayList("aa","bb","cc","dd","ee","ff");				
    	public ArrayList<String> data = new ArrayList<String>(2);
     
     	@Override
    	public void initialize(URL location, ResourceBundle resources) {
    		// TODO Auto-generated method stub
    		  combo.setItems(list);
    	}  	
     
        public void btn_show() {   
        try {
        	  tbviewController tbvc = new tbviewController(data); 
              FXMLLoader loader = new FXMLLoader(getClass().getResource("/pkgfxml/tabview.fxml"));
    	  loader.setController(tbvc );   
    	  data.add(combochanged().trim());
    	  data.add(txt0.getText().trim());
              AnchorPane ap1_tbv = (AnchorPane) loader.load();
              loader.getController();
              tbvc .setMain(mc);      
            "  mc.getBorderPane().setCenter(ap1_tbv);  "
       	} catch (Exception e) {
               // TODO: handle exception
                  e.printStackTrace();
    	}               
        } 
      	public BorderPane getBorderPane() {
    	    // TODO Auto-generated method stub
                return bp;
    	}       
        public String combochanged() {       
    	   return combo_op.getValue();
    	 }    
    }
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    public class tbviewController implements Initializable{
    	PreparedStatement prepareStatement1 = null;			
    	ResultSet rst1 = null;		
    	Connection conn = null;
     
    	String query1 = null;
     
    	String myvar0 = "";
    	String myvar1 = "";
     
    	@FXML private AnchorPane ap1_tbv;
    	@FXML private TableView<OPerDetails> tb1;
    	@FXML private TableColumn<OPerDetails, String> col_11;
    	@FXML private TableColumn<OPerDetails, String> col_22;
    	@FXML private TableColumn<OPerDetails, String> col_33;
    	@FXML private TableColumn<OPerDetails, String> col_44;
    	@FXML private TableColumn<OPerDetails, String> col_55;
    	@FXML private TableColumn<OPerDetails, String> col_66;
    	@FXML private loginController mc;
    	@FXML private ComboBox<String> combo;	
     
     	public void setMain(loginController mc) {
    		this.mc = mc;
    	}	
     
    	public ObservableList<OPerDetails> list0 = FXCollections.observableArrayList();
    	public ArrayList<String> data = new ArrayList<String>(2);
     
        public tbviewController(ArrayList<String> data)
        {
        	this.data = data;	
        }  	
     
    	@Override
    	public void initialize(URL url, ResourceBundle rb) {
    		 tbviewController tbvc = new tbviewController(data);
    		 myvar0 = etbc.data.get(0);
    		 myvar1 = etbc.data.get(1);
     
    	       try {			
    			  Class.forName("com.mysql.cj.jdbc.Driver");		
    			  String url1 = "jdbc:mysql://localhost:3306/db1";			  
    			  String username = "root";
    			  String password = "";	
    			  Connection conn = DriverManager.getConnection(url1,username,password);		  			  	  
    			  query1 = String.format("SELECT table_db1.var1,table_db1.var2,table_db1.var3,table_db1.var4,table_db1.var5,table_db1.var6 from table_db1 where left(table_db1.var6,6)='%s' and table_db1.var1='%s'",myvar1,myvar0); 			  
    			  prepareStatement1 = conn.prepareStatement(query1);			  
                              rst1 = prepareStatement1.executeQuery();	
     
    	   		   while(rst1.next()) 
    	   		    { 	    	   		  
    		   	     list0.add(new OPerDetails(rst1.getString(1),rst1.getString(2),rst1.getString(3),rst1.getString(4),rst1.getString(5),rst1.getString(6)));  	   			   	    	   		     
                                }   
    	   	        col_11.setCellValueFactory(new PropertyValueFactory<OPerDetails,String>("11"));
    	   	        col_22.setCellValueFactory(new PropertyValueFactory<OPerDetails,String>("22"));
    	   	        col_33.setCellValueFactory(new PropertyValueFactory<OPerDetails,String>("33"));
    	   	        col_44.setCellValueFactory(new PropertyValueFactory<OPerDetails,String>("44"));
    	   	        col_55.setCellValueFactory(new PropertyValueFactory<OPerDetails,String>("55"));        
    	   	        col_66.setCellValueFactory(new PropertyValueFactory<OPerDetails,String>("66"));     
    	   	        tb1.setItems(list0); 	   		   	   		   	   		   	   		   
     
                         conn.close();				  
     
    	        }   catch (Exception e) {
    			  // TODO: handle exception
    		      e.printStackTrace();
    		    }	 		
    	}
    java.lang.NullPointerException
    at app1.editer_tarif_arrController.btn_show(editController.java:64)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
    at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1771)
    at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Node.fireEvent(Node.java:8411)
    at javafx.scene.control.Button.fire(Button.java:185)
    at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
    at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
    at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
    at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
    at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
    at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
    at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
    at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
    at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
    at javafx.event.Event.fireEvent(Event.java:198)
    at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
    at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
    at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
    at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:394)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:432)
    at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:410)
    at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:431)
    at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
    at com.sun.glass.ui.View.notifyMouse(View.java:937)
    at com.sun.glass.ui.win.WinApplication._runLoop(Native Method)
    at com.sun.glass.ui.win.WinApplication.lambda$null$4(WinApplication.java:186)
    at java.lang.Thread.run(Thread.java:748)

  2. #2
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    As-tu vérifié que mc est pas null avec ton déboggeur ? As-tu vérifié que ce composant a bien le bon fx:id dans le FXML (que tu ne nous a pas montré) ? Comment charges-tu ton FXML et son contrôleur ?
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2020
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Djibouti

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2020
    Messages : 18
    Points : 8
    Points
    8
    Par défaut tableview au centre de borderpane
    merci de répondre Bouye. mais je ne sais utiliser le debugger encore.
    en fait, j'ai un login qui affiche un borderpane qui a son tour a un button dans la partie left
    de la borderpane. ce button affiche au centre du borderpane le edit.fxml dont le click de son button "valider"
    affiche à son tour le tableview(tbview.fxml).

    ce même prog fonctionne alors que les *.java et*.fxml sont sous un même répertoire pkg.
    là, j'ai voulu les séparer en rangeant les *.java sous pkg et les .fxml sous pkgfxml.
    c'est là que je n'arrive pas à charger le tableview dans le centre de borderpane.
    tous le reste semble bon.
    voici les fichiers edit.fxml ettbview.fxml.
    edit.fxml
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    <?xml version="1.0" encoding="UTF-8"?>
     
    <?import javafx.scene.control.Button?>
    <?import javafx.scene.control.ComboBox?>
    <?import javafx.scene.control.Label?>
    <?import javafx.scene.control.TextField?>
    <?import javafx.scene.layout.AnchorPane?>
    <?import javafx.scene.layout.Pane?>
    <?import javafx.scene.text.Font?>
     
    <AnchorPane fx:id="ap1" prefHeight="775.0" prefWidth="1263.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1" fx:controller="pkg.editController">  
     <children>
      <Pane fx:id="ape2" layoutX="204.0" layoutY="109.0" prefHeight="503.0" prefWidth="831.0">
       <children>
          <Label fx:id="lbl1" alignment="TOP_LEFT" contentDisplay="CENTER" layoutX="65.0" layoutY="100.0" prefHeight="45.0" prefWidth="231.0" text="Espece">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <ComboBox fx:id="combo" layoutX="344.0" layoutY="100.0" prefHeight="45.0" prefWidth="180.0" promptText="Select_Espece" />
          <Label fx:id="lbl2" alignment="TOP_LEFT" layoutX="65.0" layoutY="176.0" prefHeight="45.0" prefWidth="155.0" text="Période">
             <font>
                <Font size="18.0" />
             </font>
          </Label>
          <TextField fx:id="txt0" layoutX="344.0" layoutY="168.0" prefHeight="45.0" prefWidth="180.0">
                   <font>
                      <Font size="18.0" />
                   </font></TextField>
          <Button fx:id="btnshow" layoutX="326.0" layoutY="340.0" mnemonicParsing="false" onAction="#btn_show" prefHeight="59.0" prefWidth="216.0" text="Valider">
             <font>
                <Font size="24.0" />
             </font>
          </Button>
       </children>
      </Pane>
     </children>     
    </AnchorPane>

    tbview.fxml
    Code xml : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    <?xml version="1.0" encoding="UTF-8"?>
     
    <?import javafx.scene.control.TableColumn?>
    <?import javafx.scene.control.TableView?>
    <?import javafx.scene.layout.AnchorPane?>
     
    <AnchorPane fx:id="ap1_tbv" prefHeight="700.0" prefWidth="700.0" xmlns="http://javafx.com/javafx/11.0.1" xmlns:fx="http://javafx.com/fxml/1">
       <children>
          <TableView fx:id="tb1" layoutX="35.0" layoutY="29.0" prefHeight="700.0" prefWidth="700.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
            <columns>
              <TableColumn fx:id="col_11" prefWidth="75.0" text="11" />
              <TableColumn fx:id="col_22" prefWidth="75.0" text="22" />
              <TableColumn fx:id="col_33" prefWidth="75.0" text="33" />
              <TableColumn fx:id="col_44" prefWidth="75.0" text="44" />
              <TableColumn fx:id="col_55" prefWidth="75.0" text="55" />
              <TableColumn fx:id="col_66" prefWidth="75.0" text="66" />        
            </columns>
          </TableView>
       </children>
    </AnchorPane>

  4. #4
    Rédacteur/Modérateur

    Avatar de bouye
    Homme Profil pro
    Information Technologies Specialist (Scientific Computing)
    Inscrit en
    Août 2005
    Messages
    6 840
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 47
    Localisation : Nouvelle-Calédonie

    Informations professionnelles :
    Activité : Information Technologies Specialist (Scientific Computing)
    Secteur : Agroalimentaire - Agriculture

    Informations forums :
    Inscription : Août 2005
    Messages : 6 840
    Points : 22 854
    Points
    22 854
    Billets dans le blog
    51
    Par défaut
    Ok donc mc est un contrôleur. Et il est toujours null. Tu as été vérifier l'état de la variable dans le débogueur ?
    Merci de penser au tag quand une réponse a été apportée à votre question. Aucune réponse ne sera donnée à des messages privés portant sur des questions d'ordre technique. Les forums sont là pour que vous y postiez publiquement vos problèmes.

    suivez mon blog sur Développez.

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning. ~ Rich Cook

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2020
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Djibouti

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2020
    Messages : 18
    Points : 8
    Points
    8
    Par défaut tableview au centre de borderpane
    je vous ai dit que je ne sais pas encore utiliser le debugger. mais lorsque je fais "System.out.println(mc)" à la ligne juste au dessus de celle qui cause l'erreur, effectivement j'obtiens null. vous avez raison. comment contourner alors cela?

  6. #6
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2020
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Djibouti

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2020
    Messages : 18
    Points : 8
    Points
    8
    Par défaut tableview au centre de borderpane
    il n'y a pas d'idées apparemment!!

  7. #7
    Futur Membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Juillet 2020
    Messages
    18
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : Djibouti

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Juillet 2020
    Messages : 18
    Points : 8
    Points
    8
    Par défaut tableview au centre de borderpane
    j'ai déjà résolu le problème. merci pour le manque d'idées.

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [Swing] Centré un texte dans un JTextPane
    Par titi_22 dans le forum AWT/Swing
    Réponses: 7
    Dernier message: 24/06/2011, 16h09
  2. [Forms6i] positionnement au centre de l'ecran
    Par bargou dans le forum Forms
    Réponses: 11
    Dernier message: 15/12/2004, 17h38
  3. Réponses: 2
    Dernier message: 13/10/2004, 14h52
  4. Rotation d'un rectangle autour du centre de gravité
    Par bucheron dans le forum Algorithmes et structures de données
    Réponses: 13
    Dernier message: 22/06/2004, 11h01

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo