没有可见的网格线

时间:2016-08-07 19:19:27

标签: gridpane gridlines

我已经完成了我需要的代码示例,但是我得到了不可见的网格线。不知道为什么它不起作用,我尝试了不同的设置,但没有运气,这是代码。对不起代码中的混乱:

FXMLdocument.fxml

<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.canvas.*?>
<?import javafx.scene.text.*?>
<?import javafx.scene.paint.*?>
<?import javafx.scene.effect.*?>
<?import javafx.embed.swing.*?>
<?import javafx.scene.chart.*?>
<?import javafx.geometry.*?>
<?import javafx.scene.shape.*?>
<?import java.lang.*?>
<?import java.util.*?>
<?import javafx.scene.*?>
<?import javafx.scene.control.*?>
<?import javafx.scene.layout.*?>

<AnchorPane id="AnchorPane" fx:id="anchorPane" prefHeight="1006.0" prefWidth="1219.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="GUI.FXMLDocumentController">
    <children>
      <MenuBar layoutX="-1.0" layoutY="2.0" prefHeight="25.0" prefWidth="826.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="2.0">
        <menus>
          <Menu mnemonicParsing="false" onAction="#menuOverview" text="Overview">
               <items>
                  <CheckMenuItem fx:id="RR_Status" mnemonicParsing="false" onAction="#enableCheckBox" text="1" />
                  <CheckMenuItem fx:id="RRAnt_Status" mnemonicParsing="false" text="2" />
                  <CheckMenuItem fx:id="IFF_Status" mnemonicParsing="false" onAction="#enableCheckBox" text="3" />
                  <CheckMenuItem fx:id="ESM_Status" mnemonicParsing="false" onAction="#enableCheckBox" text="4" />
                  <CheckMenuItem fx:id="Link_Status" mnemonicParsing="false" onAction="#enableCheckBox" text="5" />
                  <CheckMenuItem fx:id="C2_Status" mnemonicParsing="false" onAction="#enableCheckBox" text="6" />
                  <CheckMenuItem fx:id="Ais_Status" mnemonicParsing="false" onAction="#enableCheckBox" text="7" />
                  <CheckMenuItem fx:id="Msr_Status" mnemonicParsing="false" onAction="#enableCheckBox" text="8" />
                  <CheckMenuItem fx:id="EOS_Status" mnemonicParsing="false" onAction="#enableCheckBox" text="9" />
               </items>
          </Menu>
        </menus>
         <effect>
            <InnerShadow />
         </effect>
      </MenuBar>
      <Group />
      <SwingNode layoutX="28.0" layoutY="171.0" />
      <Pane fx:id="GridPane" layoutX="34.0" layoutY="51.0" prefHeight="553.0" prefWidth="1160.0">
         <children>
            <ScrollPane layoutX="43.0" layoutY="337.0" prefHeight="200.0" prefWidth="1049.0" vbarPolicy="NEVER">
               <content>
                  <GridPane fx:id="grid" gridLinesVisible="true">
                    <columnConstraints>
                      <ColumnConstraints hgrow="SOMETIMES" minWidth="10.0" prefWidth="100.0" />
                    </columnConstraints>
                    <rowConstraints>
                      <RowConstraints minHeight="10.0" prefHeight="30.0" vgrow="SOMETIMES" />
                    </rowConstraints>
                  </GridPane>
               </content>
            </ScrollPane>
         </children>
      </Pane>
    </children>
</AnchorPane>

FXMLDocumentController.java

package GUI;

import java.net.URL;
import java.util.ResourceBundle;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Label;
import javafx.scene.control.MenuItem;
import javafx.scene.control.CheckMenuItem;
import javafx.scene.layout.GridPane;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

public class FXMLDocumentController implements Initializable {

    @FXML
    private MenuItem mnuClose;
    @FXML
    private AnchorPane anchorPane;
    @FXML
    private CheckMenuItem RR_Status;
    @FXML
    private CheckMenuItem IFF_Status;
    @FXML
    private CheckMenuItem ESM_Status;
    @FXML
    private CheckMenuItem Link_Status;
    @FXML
    private CheckMenuItem C2_Status;
    @FXML
    private CheckMenuItem Ais_Status;
    @FXML
    private CheckMenuItem EOS_Status;
    @FXML
    private CheckMenuItem Msr_Status;
    //clickable grid
    @FXML
    private GridPane grid; 

    //Variable used by table
    Integer i = 0;
    Integer i_overMsg = 0;
    Integer rr_status_row_index;
    Integer iff_bit_row_index;
    Integer iff_status_row_index;
    Integer c2_status_row_index;
    Integer esm_status_row_index;
    Integer ais_status_row_index;
    Integer link_status_row_index;


    static Integer doSwitch(Boolean in){
        Integer out;

        if (in==true)
            out = 1;  
        else 
            out = 0; 

        return out;
    } 


    @Override
    public void initialize(URL url, ResourceBundle rb) {                

        if (doSwitch(RR_Status.isSelected())==1) {
            String colorname = "Red";
            //Status of messages into an array
            String[] ArrayColor = new String[11];
            ArrayColor[0] = "Red";
            ArrayColor[1] = "Green";
            ArrayColor[2] = "Yellow";
            ArrayColor[3] = "Yellow";
            ArrayColor[4] = "Yellow";
            ArrayColor[5] = "Yellow";

            rr_status_row_index=i;
            i++;
            i_overMsg++;       
        }  

        if (doSwitch(IFF_Status.isSelected())==1) {
            //For the clickable grid
            grid.addRow(i, new Label("3"));
            System.out.println(i);
            iff_status_row_index=i;
            i++;
            grid.addRow(i, new Label("3"));
            iff_bit_row_index=i;
            i++;
        }         
        //grid.getRowConstraints().add(new RowConstraints(30));
        grid.addRow(i, new Label("I am fixed!"));   
    }    


    //Method to draw the Grid Panels when action in Menu Overview
    @FXML
    private void menuOverview(ActionEvent event) {
      Integer i = 0;  
    // CLear previously created Grid Panel
      grid.getChildren().clear(); 
      grid.setGridLinesVisible(true);
      grid.setStyle("-fx-grid-lines-visible: true;");


      if (RR_Status.isSelected()) {
      //draw row in Grid Panel 
            String colorname = "Red";
            //Status of messages into an array
            String[] ArrayColor = new String[11];
            ArrayColor[0] = "Red";
            ArrayColor[1] = "Green";
            ArrayColor[2] = "Yellow";
            ArrayColor[3] = "Yellow";
            ArrayColor[4] = "Yellow";
            ArrayColor[5] = "Yellow";


            //Add label for the RR Status Row
            grid.addRow(i, new Label("1"));

            for(int count=0; count<11; count++){ 

              Label txt = new Label("  ");  
              grid.add(txt,count,i); 
              grid.setGridLinesVisible(true);    
              grid.setStyle("-fx-grid-lines-visible: true;");

              if (count ==3) { 
                txt.setStyle("-fx-background-color: black;"); 
              }   
              if (count ==5) { 
                txt.setStyle("-fx-background-color: blue;"); 
              }  

            } 
            rr_status_row_index=i;
            i++;
            //END draw row for RR_Status
            grid.setGridLinesVisible(true);    
            grid.setStyle("-fx-grid-lines-visible: true;");

      }    

      if (IFF_Status.isSelected()) {

            //draw row in Grid Panel 
            grid.addRow(i, new Label("3"));
            System.out.println(i);
            iff_status_row_index=i;
            i++;
            grid.addRow(i, new Label("3"));
            iff_bit_row_index=i;
            i++;
            //END draw row in Grid Panel
      }
      if (ESM_Status.isSelected()) {

            //draw row in Grid Panel 
            grid.addRow(i, new Label("4"));
            System.out.println(i);
            esm_status_row_index=i;
            i++;
            //END draw row in Grid Panel
      }
      if (C2_Status.isSelected()) {        
            //draw row in Grid Panel 
            grid.addRow(i, new Label("6"));
            System.out.println(i);
            c2_status_row_index=i;
            i++;
            //END draw row in Grid Panel
      }
      if (Ais_Status.isSelected()) {      
            //draw row in Grid Panel 
            grid.addRow(i, new Label("7"));
            System.out.println(i);
            ais_status_row_index=i;
            i++;
            //END draw row in Grid Panel
      }
      if (Link_Status.isSelected()) {

            //draw row in Grid Panel 
            grid.addRow(i, new Label("5"));
            System.out.println(i);
            link_status_row_index=i;
            i++;
            //END draw row in Grid Panel
      }

      //Draw the fixed row in Grid Panel
      grid.addRow(i, new Label("I am fixed!"));
      grid.setGridLinesVisible(true); 
      grid.setStyle("-fx-grid-lines-visible: true;");
    }

// NOT USED IN THIS EXAMPLE
    //Method to handle the checkboxes connected to the Menu Items
    @FXML
    private void enableCheckBox(ActionEvent event) {        
      //Check if RR Menu item is enabled 
      if (RR_Status.isSelected()) {

      }     
      else {        

      }
      //Check if IFF Menu item is enabled or disabled 
      if (IFF_Status.isSelected()) {

      }
      else   {     

      }
      //Check if ESM Menu item is enabled or disabled 
      if (ESM_Status.isSelected()) {

      }     
       else  {      

      }
      //Check if C2 Menu item is enabled or disabled 
      if (C2_Status.isSelected())  {

      }     
       else  {      

      }      
      //Check if AIS Menu item is enabled or disabled 
      if (Ais_Status.isSelected())  {

      }      
      else  {      

      }      
      //Check if LINK Menu item is enabled or disabled 
      if (Link_Status.isSelected())  {

       }     
       else   {     

      }     
      //Check if MSR Menu item is enabled or disabled 
      if (Msr_Status.isSelected())  {

      }     
       else   {     

      }     
      //Check if EOS Menu item is enabled or disabled 
      if (EOS_Status.isSelected())  {

      }     
       else  {      

      }
    }
// END NOT USED IN THIS EXAMPLE

}

JavaFXApplication1.java

package GUI;

import javafx.fxml.FXMLLoader;
import javafx.scene.Parent;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class JavaFXApplication1 extends Application {

    @Override
    public void start(Stage stage) throws Exception {
        Parent root = FXMLLoader.load(getClass().getResource("FXMLdocument.fxml"));

        Scene scene = new Scene(root);

        stage.setScene(scene);
        stage.setTitle("Tester");
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }

}

因此,在概览菜单中选择菜单项之前,会显示网格线,但在选择/取消选择菜单项后,会创建一个新的网格布局,但没有可见的网格线。如何显示网格线?

谢谢!

0 个答案:

没有答案