svkvvenky
svkvvenky

Reputation: 1120

Related to GUI creation using Swing in Java

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.

Upvotes: 0

Views: 78

Answers (3)

Subash
Subash

Reputation: 7256

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.

Upvotes: 2

Robin
Robin

Reputation: 36601

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

Upvotes: 2

Tom
Tom

Reputation: 44821

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

Upvotes: 2

Related Questions