2009-12-23 85 views
0

我有这一切对象:爪哇 - 选择在一个框架

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

我想让它更简单,更菜鸟...任何想法?

+1

默认情况下JLabel没有边框,所以你不必做任何事情。 – camickr 2009-12-23 07:15:09

回答

2

尝试

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

如果你只想要JLabel S,不是所有的组件有一个空边界,改变instanceof检查,并投以JLabel

要包括你的答案被camickr评论,JLabel默认没有边框,所以你不必做任何事情。你应该这样做,只有当你在某个时候指定了边界并且想要摆脱边界。

+0

谢谢,那肯定会奏效!我确实有边界,我不想用手写出所有的组件。 – Ali 2009-12-23 17:40:20