有几次我因为建议使用以下方法而受到批评:
在Swing组件上.当我想在显示的组件之间定义比例时,我没有看到任何替代它们的用法.我被告知这个:
对于布局,答案总是相同的:使用合适的LayoutManager
我在网上搜索了一下,但我没有找到任何关于这个主题的综合分析.所以我有以下问题:
我在这里读了一些帖子,我开始为什么有些人这样做
@Override
public Dimension getPreferredSize() {
return new Dimension(500, 500);
}
Run Code Online (Sandbox Code Playgroud)
代替
setPreferredSize(new Dimension(500, 500));
Run Code Online (Sandbox Code Playgroud)
不是第二个更好,因为它只创建一个Dimension对象,而第一个可能创建几个(即使它没有那么多浪费的内存)?还是我错了?有什么不同吗?
我正在尝试使用鼠标滚轮进行缩放。放大更大效果完美。但是,当我滚动较小时,它不会无限缩小。这意味着,在窗格达到特定大小之后,它不会继续缩小。这是我的方法:
package application;
import javafx.application.Application;
import javafx.beans.InvalidationListener;
import javafx.beans.Observable;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ScrollPane;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.shape.SVGPath;
import javafx.scene.transform.Affine;
import javafx.stage.Stage;
public class fab extends Application {
private Stage stage;
private Pane pane;
private BorderPane borderPane;
private Scene scene;
private Affine affine = new Affine();
private ScrollPane scrollPane;
private String coords = "M545.296,92.562c-1.399-1.758-2.823-3.852-4.732-4.777c-8.87-4.309-17.83-8.47-26.933-12.256 c-4.268-1.775-7.49-4.035-8.735-8.65c-0.269-1-0.755-2.084-1.473-2.799c-4.492-4.455-4.533-4.447,0.808-7.854 c0.698-0.445,1.567-0.624,1.73-0.685c-0.412-2.179-0.637-3.901-1.102-5.557c-0.225-0.804-0.755-1.681-1.408-2.179 c-3.211-2.419-7.021-4.264-9.629-7.193c-2.566-2.885-5.186-2.742-8.307-2.448c-1.044,0.098-2.513,0.13-3.146-0.473 c-3.672-3.55-8.731-1.82-13.031-3.321c-3.75-1.31-8.928,1.493-13.477,2.448c-0.633,0.13-1.399,0.293-1.946,0.065 c-7.797-3.284-14.378-1.281-19.689,4.859c-0.262,1.359-0.625,2.905-1.596,3.66c-3.696,2.864-7.854,5.182-11.326,8.274 c-2.424,2.158-4.981,5.01-5.708,7.984c-0.73,2.995-2.171,4.023-4.521,4.77c-2.529,0.8-4.859,1.579-4.949,4.953 c-0.024,0.841-1.562,1.55-1.885,2.497c-0.682,1.995-1.098,4.096-1.473,6.177c-0.208,1.154,0.253,2.554-0.241,3.505 c-1.758,3.415-3.888,6.638-5.699,10.024c-1.588,2.958-4.48,6.328-3.995,9.004c0.588,3.231-0.216,6.389,0.531,9.335 c1.252,4.961-1.191,8.45-3.48,12.24c-1.869,3.088-3.729,6.259-5.002,9.612c-1.122,2.966-3.428,5.826-1.616,9.531 …Run Code Online (Sandbox Code Playgroud)