इस मुद्दे को हल किया गया। मेरी पूरी परियोजना की प्रतिलिपि बनाना था और फिर कोड गायब होने तक कोड के हिस्सों को हटा देना था।
वैसे भी। मैं मूल रूप से अपने आवेदन में तीन घटक था। एक नेविगेशन घटक, एक टेबल असंतोष, और एक स्टेटस बार असंतोष। यह इस तरह से देखा:
समस्या मैं था कि स्थिति पट्टी और चौड़ाई और तालिका घटक की ऊंचाई की चौड़ाई बढ़ा दिया गया था जब भी मैं तालिका में एक पंक्ति का एक स्नैपशॉट लिया।
जाहिर है, यह स्टेटस बार असंतोष के पैडिंग के कारण था। इसमें 5 पिक्सल का दायां और बायां पैडिंग था, और एक बार जब मैंने पैडिंग हटा दी, तो समस्या गायब हो गई।
चौड़ाई में जोड़े गए 10 पिक्सेल BorderPane
बनाते हैं जिसमें यह सब एक ही पिक्सेल के साथ विस्तारित होता है, और चूंकि तालिका की चौड़ाई BorderPane
चौड़ाई तक सीमित थी, इसलिए यह उसी राशि से बढ़ी। हालांकि मुझे अभी भी समझ में नहीं आता है, इसलिए Stage
जिसमें BorderPane
शामिल है, नई चौड़ाई में समायोजित नहीं होता है।
घटक को Scene.doCSSLayoutSyncForSnapshot(Node node)
से पहले ठीक से गद्देदार किया गया था, इसलिए मुझे समझ में नहीं आया कि दस पिक्सेल की अतिरिक्त चौड़ाई क्यों जोड़ा गया है।
किसी भी तरह: स्टेटस बार घटक से पैडिंग को हटाने और इसके बजाय स्टेटस बार के अंदर घटकों को पैडिंग करने से समस्या ठीक हो गई। अगर किसी के पास इसके लिए एक अच्छा स्पष्टीकरण है, तो मैं सभी कान हूं।
यहाँ एक MCVE जहां तालिका में एक पंक्ति को खींच कर इस मुद्दे को दोबारा कर सकते हैं:
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
import javafx.application.Application;
import javafx.beans.property.SimpleStringProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.geometry.Insets;
import javafx.scene.Node;
import javafx.scene.Scene;
import javafx.scene.control.TableColumn;
import javafx.scene.control.TableRow;
import javafx.scene.control.TableView;
import javafx.scene.input.ClipboardContent;
import javafx.scene.input.Dragboard;
import javafx.scene.input.TransferMode;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.scene.layout.Region;
import javafx.scene.layout.VBox;
import javafx.stage.Stage;
public class MCVE extends Application {
private Stage primaryStage;
private BorderPane rootLayout;
private VBox detailsView;
private StatusBar statusBar;
public void start(Stage primaryStage) throws SQLException {
this.primaryStage = primaryStage;
this.primaryStage.setTitle("MCVE");
initRootLayout();
showStatusBar();
showDetailsView();
detailsView.prefWidthProperty().bind(rootLayout.widthProperty());
detailsView.prefHeightProperty().bind(rootLayout.heightProperty());
}
@Override
public void init() throws Exception {
super.init();
}
public void initRootLayout() {
rootLayout = new BorderPane();
primaryStage.setWidth(1000);
primaryStage.setHeight(600);
Scene scene = new Scene(rootLayout);
primaryStage.setScene(scene);
primaryStage.show();
}
public void showStatusBar() {
statusBar = new StatusBar();
rootLayout.setBottom(statusBar);
}
public void showDetailsView() {
detailsView = new VBox();
rootLayout.setCenter(detailsView);
setDetailsView(new Table(this));
detailsView.prefHeightProperty().bind(primaryStage.heightProperty());
detailsView.setMaxHeight(Region.USE_PREF_SIZE);
}
public static void main(String[] args) {
launch(args);
}
public VBox getDetailsView() {
return detailsView;
}
public void setDetailsView(Node content) {
detailsView.getChildren().add(0, content);
}
public StatusBar getStatusBar() {
return statusBar;
}
class StatusBar extends HBox {
public StatusBar() {
setPadding(new Insets(0, 5, 0, 5));
HBox leftBox = new HBox(10);
getChildren().addAll(leftBox);
/**
* CONTROL SIZES
*/
setPrefHeight(28);
setMinHeight(28);
setMaxHeight(28);
// Leftbox takes all the space not occupied by the helpbox.
leftBox.prefWidthProperty().bind(widthProperty());
setStyle("-fx-border-color: black;");
}
}
class Table extends TableView<ObservableList<String>> {
private ObservableList<ObservableList<String>> data;
public Table(MCVE app) {
prefWidthProperty().bind(app.getDetailsView().widthProperty());
prefHeightProperty()
.bind(app.getDetailsView().heightProperty());
widthProperty().addListener((obs, oldValue, newValue) -> {
System.out.println("Table width: " + newValue);
});
setRowFactory(r -> {
TableRow<ObservableList<String>> row = new TableRow<ObservableList<String>>();
row.setOnDragDetected(e -> {
Dragboard db = row.startDragAndDrop(TransferMode.ANY);
db.setDragView(row.snapshot(null, null));
ArrayList<File> files = new ArrayList<File>();
// We create a clipboard and put all of the files that
// was selected into the clipboard.
ClipboardContent filesToCopyClipboard = new ClipboardContent();
filesToCopyClipboard.putFiles(files);
db.setContent(filesToCopyClipboard);
});
row.setOnDragDone(e -> {
e.consume();
});
return row;
});
ObservableList<String> columnNames = FXCollections.observableArrayList("Col1", "col2", "Col3", "Col4");
data = FXCollections.observableArrayList();
for (int i = 0; i < columnNames.size(); i++) {
final int colIndex = i;
TableColumn<ObservableList<String>, String> column = new TableColumn<ObservableList<String>, String>(
columnNames.get(i));
column.setCellValueFactory((param) -> new SimpleStringProperty(param.getValue().get(colIndex).toString()));
getColumns().add(column);
}
// Adds all of the data from the rows the data list.
for (int i = 0; i < 100; i++) {
// Each column from the row is a String in the list.
ObservableList<String> row = FXCollections.observableArrayList();
row.add("Column 1");
row.add("Column 2");
row.add("Column 3");
row.add("Column 4");
// Adds the row to data.
data.add(row);
}
// Adds all of the rows in data to the table.
setItems(data);
}
}
}
अच्छी तरह से आप पहले आह्वान कि समारोह अपने नोड्स पर बाधाओं की स्थापना की और उन्हें पूर्ववत करने की कोशिश कर सकते हैं, मेरा मतलब, ' setMinSize (Pane.USE_PREF_SIZE, Pane.USE_PREF_SIZE); 'और' setMaxSize (Pane.USE_PREF_SIZE, फलक।USE_PREF_SIZE); 'यह आपकी समस्या का वर्णन करने के तरीके से आपकी सहायता कर सकता है, :) – Elltz
कोड की सभी 2000 लाइनों को पोस्ट न करने के लिए धन्यवाद। लेकिन यदि आप इस समस्या को पुन: पेश करने के लिए एक संक्षिप्त, संकलित नमूना लिख सकते हैं जो उपयोगी होगा। अन्यथा यदि आप एक छोटे नमूने को पुन: उत्पन्न नहीं कर सकते हैं तो अपने सभी कोड का एक लिंक? – Amber
मैं [सीनिक व्यू] (http://fxexperience.com/scenic-view/) का उपयोग करने का सुझाव देता हूं जो आपको GUI के रनटाइम के दौरान दृश्य पर सभी गुणों को देखने की अनुमति देता है। यह आपको कम से कम जांचने देगा कि आप जिस समस्या का वर्णन करते हैं वह वास्तव में समस्या है। आप सीनिक व्यू का उपयोग करके कुछ स्क्रीन शॉट्स भी पोस्ट कर सकते हैं। यह टूल आपको जीयूआई में होने वाली सभी घटनाओं को देखने की अनुमति देता है। मैं इसका बहुत उपयोग करता हूं :-) – Westranger