Is it contraindicated to use several presetted dimension objects to set the preferred size of non resizable components on the screen.
E.g.: two textfields both should be 80×20 px so:
Dimension d = new Dimension(80, 20);
tf1.setPreferredSize(d);
tf2.setPreferredSize(d);
Yes, it is “safe”. Quote from Java Performance Tuning:
Depends on what you want though. Note that the implementation in
Componentdoes not copy the content of the argument, but stores the reference:so changing
dwill affect the dimension object stored in bothtf1andtf2.(What I’m saying is that the code below may not do what you would expect.)