Question

When i add another JPanel into frame previous will dissapper (or probably overlaps the previous one). How can i stop this overlapping?

public Attack() {
    JFrame frame = new JFrame("Oracle Padding Attack");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    panel1.setLayout(null);
    JLabel label1 = new JLabel("Inicialization vector:");
    createTextField(10, 40, arrayIV, panel1, "HH", true, false);
    label1.setBounds(10, 0, 120, 50);
    panel1.add(label1);

    panel2.setLayout(null);
    JLabel label2 = new JLabel("Encrypted text:");
    createTextField(400, 40, encryptedTextArray, panel2, "00", true, false);
    label2.setBounds(400, 0, 120, 50);
    panel2.add(label2);

    frame.add(panel1);
    frame.add(panel2);
    frame.setSize(900, 400);
    frame.setVisible(true);
}
Was it helpful?

Solution

It depends on how you want your two panels placed inside your frame. You will need a layout for your frame. If you want to be able to "jump" from one to the other, cardLayout is your answer.

Otherwise if you want both side to side for example, you will have to use a layout inside your frame. I like the MigLayout, but GridLayout will do the job just fine.

http://docs.oracle.com/javase/tutorial/uiswing/layout/grid.html

All build in layout handlers can be found here: http://docs.oracle.com/javase/tutorial/uiswing/layout/visual.html

Also it's not recommended to use null layout at all since it will break the look if the window is resized.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top