views:

30

answers:

1

i have this:

jLabel1.setBorder(null);
jLabel2.setBorder(null);
jLabel3.setBorder(null);
jLabel4.setBorder(null);
jLabel5.setBorder(null);
jLabel6.setBorder(null);

i want to make it simpler and less noob... any ideas?

+2  A: 

Try

Component[] components = frame.getContentPane().getComponents();
for (Component component : components) {
   if (component instanceof JComponent) {
       ((JComponent) component).setBorder(null);
   }
}

If you want only JLabels, not all components to have a null border, change the instanceof check and the cast to JLabel

To include the comment on your answer by camickr, a JLabel doesn't have a border by default, so you don't have to do anything. You should do this only in case you have assigned a border at some point and want to get rid of it.

Bozho
thank you, that will certainly work! i do have borders, i didn't want to write out all the components by hand.
Ali