0

I am facing problem during event handling.

The problem is like this:

  1. My GUI has mainPanel (JPanel) which in turn consists of a panel with three buttons (namely btn1, btn2, btn3) at its WEST position.
  2. I have created 3 more panels namely pnl1, pnl2, pnl3 (each panel has one label and one text area) using three different functions of same class.
  3. My requirement is that if I click btn1 / btn2 / btn3 then pnl1 / pnl2 / pnl3 respectively must appear at mainPanel's CENTER position.
Andrew Thompson
169k42 gold badges224 silver badges441 bronze badges
asked Dec 24, 2011 at 10:00
0

3 Answers 3

2

You will have to add action listener to the btn1, btn2, btn3. Then when the respective button is clicked you write a function that will display the required respective panels to the center of GUI. To do so you can use cardLayout.

If you add detail to your question then we can help you with better answer or suggestions.

What's the purpose of the label and text area? Add a screenshot of your GUI and some code that you have written.

answered Dec 24, 2011 at 10:34
Sign up to request clarification or add additional context in comments.

1 Comment

I used the card layout and my problem is solved.Thank you very much subash
2

Sounds like you want to put a CardLayout in the center, here's a tutorial.

answered Dec 24, 2011 at 10:21

Comments

2

You could consider creating a JPanel with a CardLayout for the CENTER panel. The CardLayout could contain 4 UI's ( the pnl1,pnl2,pnl3 and an empty panel ), and clicking on those buttons could activate the correct panel on the CardLayout

answered Dec 24, 2011 at 10:22

2 Comments

I used the card layout and my problem is solved.Thank you very much robin
In that case you might accept the answer (see stackoverflow.com/faq#howtoask)

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.