फिट करने के लिए जावाएफएक्स स्क्रॉलपेन सामग्री का आकार कैसे बदलें मेरे पास BorderPane
है ScrollPane
केंद्र तत्व के रूप में। यह स्क्रीन भरने के लिए स्वचालित रूप से आकार बदलता है। ScrollPane
के अंदर HBox
है जिसमें कोई सामग्री नहीं है लेकिन ड्रैग-एंड-ड्रॉप लक्ष्य है। इसलिए मैं इसे अपने माता-पिता ScrollPane
भरना चाहता हूं।वर्तमान आकार
ऐसा करने का पसंदीदा तरीका क्या है?
मैंने अब तक कोशिश की है ScrollPane.resize(...)
HBox
का आकार बदलने के लिए विधि को ओवरराइड कर रहा है लेकिन यह अपेक्षाकृत जटिल और अपरंपरागत लगता है।
संपादित करें: यह करने के लिए कुछ उपयोगी कोड जोड़ने के लिए, यह कैसे मैं इस समस्या वैकल्पिक हल कर सकते हैं, लेकिन मेरा मानना है कि वहाँ यह करने के लिए कुछ बेहतर तरीका हो गया है:
@Override
public void resize(double width, double height) {
super.resize(width, height);
double scrollBarHeight = 2;
double scrollBarWidth = 2;
for (final Node node : lookupAll(".scroll-bar")) {
if (node instanceof ScrollBar) {
ScrollBar sb = (ScrollBar) node;
if (sb.getOrientation() == Orientation.HORIZONTAL) {
System.out.println("horizontal scrollbar visible = " + sb.isVisible());
System.out.println("width = " + sb.getWidth());
System.out.println("height = " + sb.getHeight());
if(sb.isVisible()){
scrollBarHeight = sb.getHeight();
}
}
if (sb.getOrientation() == Orientation.VERTICAL) {
System.out.println("vertical scrollbar visible = " + sb.isVisible());
System.out.println("width = " + sb.getWidth());
System.out.println("height = " + sb.getHeight());
if(sb.isVisible()){
scrollBarWidth = sb.getWidth();
}
}
}
}
hBox.setPrefSize(width-scrollBarWidth, height-scrollBarHeight);
}
कोड आंशिक रूप से यहां से ली गई है: How to access the Scrollbars of a ScrollPane
ठीक है, मैं सिर्फ एक hgrow और vgrow को कभी कभी रखा है और उसे अब काम करता है – user7867610