简体   繁体   中英

Adding a JPanel Array to a Container

Look at the Last line of code, that Is where I specifically would like to add my JPanel array to a container. Thanks alot Guys or Gals!

Code:

private JFrame b = new JFrame("Lotus");
private JLabel currentP = new JLabel();
private int currentS;
private Container pieces = new Container();
private JButton exitt = new JButton("EXIT");
private ImageIcon B1=new ImageIcon("C:\\Users\\Brusty\\Downloads\\p1.jpg");  
private ImageIcon B2=new ImageIcon("C:\\Users\\Brusty\\Downloads\\p2.jpg"); 
LinkedList<Stack<Integer>> spotList = new LinkedList<Stack<Integer>>(); 

//Creation of Gamepiece labels
public void Labels(){

JLabel[] labelsP1 = new JLabel[10];
JLabel[] labelsP2 = new JLabel[10];

for(int i = 0 ; i < labelsP1.length ; i++){
    labelsP1[i] = new JLabel(B1); 
    for(int j = 0 ; j < labelsP2.length ; j++){
        labelsP2[j] = new JLabel(B2); 
}
    Container c = b.getContentPane();
    c.setLayout(new GridLayout(13,3)); 
    c.add(pieces); 
    pieces.add(labelsP1);

Not sure I really see your problem. You just need to loop through the labelsP1 array and add the labels...

for (JLabel label : labelsP1) {
    pieces.add(label);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM