Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

in the below code, i created a GridLayot with 3 rows and 3 columns, what i want to do is,,to add jpanel_1 into a specifc cell of the Gridlayout, lets say in the grid cell number (2,3).

Code:

private void setUpGUI2() {
    // TODO Auto-generated method stub
    jFrame_2 = new JFrame("Border Demo");
    GridLayout gridLayOut = new GridLayout(3,3);
    jFrame_2.setLayout(gridLayOut);

    jPanel_1 = new JPanel(new BorderLayout());
    jPanel_2 = new JPanel(new BorderLayout());

    jPanel_1.setBorder(BorderFactory.createTitledBorder("title"));
    //jPanel_1.setBounds(30, 100, 110, 300);
    jPanel_1.add(jLabel_Hello, BorderLayout.EAST);

    jPanel_2.setBorder(BorderFactory.createLoweredBevelBorder());
    //jPanel_2.setBounds(20, 50, 120, 80);
    jPanel_2.add(jLabel_Hello, BorderLayout.SOUTH);

    //jFrame_2.setBounds(0, 0, 600, 600);
    jFrame_2.add(jPanel_1);//how to add jpanel_1 to a specific cell of Gridlayout defined above
    //jPanel_1.add(jPanel_2);
    jFrame_2.add(jPanel_2);
    jFrame_2.pack();
    jFrame_2.setVisible(true);
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
316 views
Welcome To Ask or Share your Answers For Others

1 Answer

I think there is no chance. You need to add them one by one. frame.add(...); frame.add(...);
I don't clearly understand what you want as result, but using GridLayout(3, 3) with only 2 panels is the same as use GridLayout(0, 2).
P.S. Check out GridBagLayout - it can be more useful for you.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...