2014-10-07 2 views
0

새로 고침 아이콘 앞에 삽입하고 javafx의 각 treeItem 레이블에 넣으려고합니다. 어떻게 할 수 있습니까?javafx treeItem의 레이블 앞에 아이콘을 삽입하는 방법 (자체 그래픽 제외)?

예를 들어
private final Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("topic.png"))); 

TreeItem<String> rootNode = new TreeItem<String>("root",rootIcon); 

:

Example

내가 두 개의 작은 이미지를 가져다가 만든 :

private final Node rootIcon = new ImageView(new Image(getClass().getResourceAsStream("topic.png"))); 
    ImageView icon = new ImageView(new Image(getClass().getResourceAsStream("refresh.png"))); 
    TreeItem<String> rootNode = new TreeItem<String>("root" + icon ,rootIcon); 

답변

0

HEJ의 호세인,

내가 당신이 이런 식으로 뭔가를 구축 할 생각 새 클래스 TopicPanel, 01을 확장 할 수 있습니다. 234,및 예를 들어이 HBox 지금 당신이 하나 개의 주제 이미지와 새로 고침 이미지를 가지고 .. 여기

어떻게 당신이 할 수있는, 클래스

import java.io.File; 
import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.util.logging.Level; 
import java.util.logging.Logger; 
import javafx.scene.image.Image; 
import javafx.scene.image.ImageView; 
import javafx.scene.layout.HBox; 
import javafx.scene.layout.Pane; 


public class TopicPanel extends Pane { 

    private ImageView topicImage; 
    private ImageView refreshImage; 
    private HBox pane; 


    public TopicPanel(final String topicImageUrl) { 
     try { 

      pane = new HBox(5.0); 
      this.refreshImage = new ImageView(new Image(new FileInputStream(new File("/Users/ottp/MyCloud/TreeNodeExample/src/main/resources/refresh.png")))); 

      this.topicImage = new ImageView(new Image(new FileInputStream(new File(topicImageUrl)))); 


      pane.getChildren().add(this.topicImage); 
      pane.getChildren().add(this.refreshImage); 

      this.getChildren().add(pane); 
     } catch (FileNotFoundException ex) { 
      Logger.getLogger(TopicPanel.class.getName()).log(Level.SEVERE, null, ex); 
     } 
    } 


} 

가 여기에있다 아주 간단한 예입니다, 두 ImageView들 추가 당신은 도메인 클래스 Person

필요한 경우 앱

import de.professional_webworkx.treenodeexample.domain.Person; 
import de.professional_webworkx.treenodeexample.panes.TopicPanel; 
import java.io.File; 
import java.io.FileInputStream; 
import java.util.ArrayList; 
import java.util.List; 
import javafx.application.Application; 
import static javafx.application.Application.launch; 
import javafx.scene.Node; 
import javafx.scene.Scene; 
import javafx.scene.control.TreeItem; 
import javafx.scene.control.TreeView; 
import javafx.scene.image.Image; 
import javafx.scene.image.ImageView; 
import javafx.stage.Stage; 


public class MainApp extends Application { 

    @Override 
    public void start(Stage stage) throws Exception { 

     final List<Person> persons = new ArrayList<>(); 



     Person p = new Person("Patrick", "Tester", "[email protected]", null); 
     Person p1 = new Person("Hans", "Meier", "[email protected]", p); 
     Person p2 = new Person("Karl", "Mueller", "[email protected]", p); 
     Person p3 = new Person("Heinz", "Glas", "[email protected]", null); 
     Person p4 = new Person("Beate", "Kriegtkeinab", "[email protected]", p3); 

     persons.add(p); 
     persons.add(p1); 
     persons.add(p2); 
     persons.add(p3); 
     persons.add(p4); 

     Node images = new ImageView(new Image(new FileInputStream(new File("/Users/ottp/MyCloud/TreeNodeExample/src/main/resources/alert.png")))); 
     TreeItem<Person> rootNode = new TreeItem<>(p, images); 
     for(Person person : persons) { 
      if(person.getSuperior() != null && person.getSuperior().equals(p)) { 
       Node img = new TopicPanel("/Users/ottp/MyCloud/TreeNodeExample/src/main/resources/alert.png"); 
       rootNode.getChildren().add(new TreeItem<>(person, img)); 
      } 
     } 
     TreeView<Person> treeView = new TreeView<>(rootNode); 
     Scene scene = new Scene(treeView, 1024, 768); 



     stage.setTitle("JavaFX and Maven"); 
     stage.setScene(scene); 
     stage.show(); 
    } 

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

} 

TopicPanel 클래스를 사용 내가 당신을 도움이되기를 바랍니다

import java.util.Objects; 

public class Person { 

    private String firstName; 
    private String lastName; 
    private String email; 

    private Person superior; 

    public Person(String firstName, String lastName, String email, Person superior) { 
     this.firstName = firstName; 
     this.lastName = lastName; 
     this.email = email; 
     this.superior = superior; 
    } 

    /** 
    * @return the firstName 
    */ 
    public String getFirstName() { 
     return firstName; 
    } 

    /** 
    * @param firstName the firstName to set 
    */ 
    public void setFirstName(String firstName) { 
     this.firstName = firstName; 
    } 

    /** 
    * @return the lastName 
    */ 
    public String getLastName() { 
     return lastName; 
    } 

    /** 
    * @param lastName the lastName to set 
    */ 
    public void setLastName(String lastName) { 
     this.lastName = lastName; 
    } 

    /** 
    * @return the email 
    */ 
    public String getEmail() { 
     return email; 
    } 

    /** 
    * @param email the email to set 
    */ 
    public void setEmail(String email) { 
     this.email = email; 
    } 

    @Override 
    public int hashCode() { 
     int hash = 5; 
     hash = 23 * hash + Objects.hashCode(this.getFirstName()); 
     hash = 23 * hash + Objects.hashCode(this.getLastName()); 
     hash = 23 * hash + Objects.hashCode(this.getEmail()); 
     return hash; 
    } 

    @Override 
    public boolean equals(Object obj) { 
     if (obj == null) { 
      return false; 
     } 
     if (getClass() != obj.getClass()) { 
      return false; 
     } 
     final Person other = (Person) obj; 
     if (!Objects.equals(this.firstName, other.firstName)) { 
      return false; 
     } 
     if (!Objects.equals(this.lastName, other.lastName)) { 
      return false; 
     } 
     if (!Objects.equals(this.email, other.email)) { 
      return false; 
     } 
     return true; 
    } 


    @Override 
    public String toString() { 
     return "Person{" + "firstName=" + getFirstName() + ", lastName=" + getLastName() + ", email=" + getEmail() + '}'; 
    } 

    /** 
    * @return the superior 
    */ 
    public Person getSuperior() { 
     return superior; 
    } 

    /** 
    * @param superior the superior to set 
    */ 
    public void setSuperior(Person superior) { 
     this.superior = superior; 
    } 
} 

...

패트릭

관련 문제