Try making a method that takes different "JComponents" as a parameter and set the size that way. Since JComponents are superclass of JOptionPane and others like it, you should be able to pass in a component parameter and set its size inside the method. I haven't tried it but It's something to look into.
setComponentSize(JComponent jc){
jc.setPreferredSize(new Dimension(300, 300));//set size here
jc.setLocation(new Point(10, 10)); //set location here
//do other stuf partaining to certain components
//like JOptionPanes, JDialogs
if(jc instnceof JOptionPane){
//stuff
}else if(jc instance of JDialog){
jc.show();
}
}
JOptionPane pane = new JOptionPane();
JDialog dialog = pane.createDialog("ej");
setComponentSize(dialog);
of course if you do other stuff with each type you can rename the method.
I found something you might check on for max sizes too.
JComponent: how to set maximum width?
If it doesn't compile for some reason check this one out.Why doesn't instanceof work with JPanel and JComponent?