Good day.

Is there any way to set parameters for a specific group of elements? (for example, for JButton buttons)

How to create this group?

If not, can one element, in any way, inherit the parameters from another element?

  • Can you clarify which parameters you want to set / set / inherit? If you still give an example will be generally wonderful. - default locale
  • Well, for example, the parameters setSize (), setLocation (), etc. - TrueASL
  • What about the option of adding all the necessary elements to an array or a list and then setting the necessary values ​​in a loop? - Regent
  • You can create your own component and add these features to it. - Mikhail Vaysman

1 answer 1

You can for example:

public class MyJButton extends JButton { public MyJButton(final int xLoc, final int yLoc) { this.setSize (new Dimension (100, 20)); this.setLocation (xLoc, yLoc); } } 

You can pass some parameters to the constructor, just set some of them inside. You can still like this:

 public class JButtonFactory { public static JButton giveMeButton(final int xLoc, final int yLoc) { JButton jButton = new JButton (); jButton.setSize (new Dimension (100, 20)); jButton.setLocation (xLoc, yLoc); return jButton; } } 

Naturally, you will need to add button lebels, cover the container, location coordinates, etc.