Manu
Manu

Reputation: 3247

how to create multiple frames in java swing component

i am new to java swing component. please tell me how to create multiple frames. My requirement is ,base frame should contain 2 radio buttons and if i click anyone radio button it should go to other frame and it should display 4 check boxes.

Please advice

Upvotes: 0

Views: 2397

Answers (2)

matt93
matt93

Reputation: 366

check out how CardLayout works

https://docs.oracle.com/javase/tutorial/uiswing/layout/card.html

if you only want to switch between the windows:

  1. Add jPanel to your jFrame which will contain all jPanels you want to switch between (let's call it jPanelMain)
  2. Set CardLayout in jPanelMain
  3. Create jPanels you want to switch between with the stuff you need there
  4. Add Action Listener to the radio button, example

    private void jButtonActionPerformed(java.awt.event.ActionEvent e) {                                          
        jPanelMain.removeAll();
        jPanelMain.repaint();
        jPanelMain.revalidate();
        jPanelMain.add(jPanel1);
        jPanelMain.repaint();
        jPanelMain.revalidate();
    }  
    

Upvotes: 1

Eugene Ryzhikov
Eugene Ryzhikov

Reputation: 17359

Why don't you read the docs and tutorial? http://download.oracle.com/docs/cd/E17409_01/javase/tutorial/uiswing/components/frame.html

Upvotes: 1

Related Questions