001package fi.jyu.mit.fxgui; 002 003import javafx.beans.DefaultProperty; 004import javafx.collections.ListChangeListener; 005import javafx.geometry.Insets; 006import javafx.scene.Node; 007import javafx.scene.control.Label; 008import javafx.scene.control.ScrollPane; 009import javafx.scene.layout.VBox; 010 011/** 012 * VBox with borders and ScrollPane inside. Last added child is inside 013 * ScrollPane. Others are after that. 014 * @author vesal 015 * @version 4.2.2017 016 */ 017@DefaultProperty("content") 018public class ScrollBorder extends VBox { 019 020 private ScrollPane sp = new ScrollPane(); 021 private Label labelValitse; 022 023 /** 024 * Initialize component 025 */ 026 public ScrollBorder() { 027 super(); 028 VBox vbox2 = this; 029 vbox2.setPadding(new Insets(10, 10, 10, 10)); 030 VBox.setMargin(vbox2, new Insets(5, 20, 20, 20)); 031 vbox2.setStyle("-fx-border-color: black;"); 032 033 labelValitse = new Label("Valitse:"); 034 super.getChildren().add(labelValitse); 035 036 sp.getStyleClass().add("edge-to-edge"); 037 super.getChildren().add(sp); 038 039 getChildren().addListener(new ListChangeListener<Node>() { 040 @SuppressWarnings("synthetic-access") 041 @Override 042 public void onChanged(Change<? extends Node> c) { 043 if (!c.next()) return; 044 for (Node item: c.getAddedSubList()) 045 sp.setContent(item); 046 } 047 }); 048 } 049 050 051 /** 052 * @return ScrollPane 053 */ 054 public ScrollPane getScrollPane() { 055 return sp; 056 } 057 058 059 /** 060 * @param sp new scrollPane 061 */ 062 public void setScrollPane(ScrollPane sp) { 063 this.sp = sp; 064 } 065 066 067 /** 068 * @param node the box to scroll 069 */ 070 public void setContent(Node node) { 071 sp.setContent(node); 072 } 073 074 075 /** 076 * @return current content 077 */ 078 public final Node getContent() { 079 return sp.getContent(); 080 } 081 082 083 084 /** 085 * @param text caption for component 086 */ 087 public void setCaption(String text) { 088 labelValitse.setText(text); 089 } 090 091 092 /** 093 * @return current caption 094 */ 095 public String getCaption() { 096 return labelValitse.getText(); 097 } 098 099}