-1

I am working with Swings in Netbeans and i am New to this Topic... I am using Drag and Drop Approach and succesfully completed some screens... I Have created 3 GUI's for testing using DRAG and DROP approach (a. SeleniumFramework.java, b.Test Cases.java, c.TEst Suites.java while each one has main method) In the 1st file i.e., SeleniumFramework.java i have 2 Panels , one on left containing 6 JLabels and other on right side which is empty... My Question is when i click on JLabels(Test Cases) on left Panel in 1st file , right Panel Should show TestCases.java screen and similarly when i click on another JLabel(Test Suites) on left PAnel in 1st File , right panel should show TestSuites.java screen... Please Help me in this about HOW TO LINK with JLAbels and JFRame as i am new to this Swings... Kindly note that i have used DRAG and DROP approach..

Sreepad Chitragar
  • 183
  • 1
  • 3
  • 12
  • `JLabel`s aren't really a good choice for user interaction generally, you should consider using `JButton`s instead. Take a look at [The Use of Multiple JFrames, Good/Bad Practice?](http://stackoverflow.com/questions/9554636/the-use-of-multiple-jframes-good-bad-practice), [How to Use Buttons, Check Boxes, and Radio Buttons](http://docs.oracle.com/javase/tutorial/uiswing/components/button.html), [How to Write an Action Listeners](http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html) – MadProgrammer Jan 27 '15 at 06:53
  • The drag n drop approach is fine once you can coop with the Swing principles. It seems to me that you have reached a point where you have to sit and study a good Swing tutorial like this one: http://docs.oracle.com/javase/tutorial/uiswing/, This will allow you to comprehend the way things work. – Costis Aivalis Jan 27 '15 at 06:53

1 Answers1

1

For more attractive and more convenient for your code you should prefer the CardLayout view by merging the frames on a single panel. It will work fine. First go through tutorials according to your need and try this, this will help you most! According to your need by using CardLayout you can simply remove one card and add another card on your panel and you can show the different output on a single place by clicking on different jButton(instead of using jLabel).

Example

 private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) 
{
 CardLayout cardLayout = (CardLayout) jPanel1.getLayout();
    jPanel3.add(RootPanel,"Card 1");
    cardLayout.show(jPanel1, "Card 1");
}
Laxminarayan
  • 188
  • 2
  • 16
  • Thanks a lot for your response with some good example... will try this once and let u know.... – Sreepad Chitragar Jan 27 '15 at 09:24
  • If you feel any need you are free to comment! – Laxminarayan Jan 27 '15 at 10:23
  • Hi Laxmi my goal is exactly like this ....Please refer this link [link](http://docs.oracle.com/javase/6/docs/api/) .... When i click on left JLabel , the right side Which is also a JPanel should show JFrame(TestCases.java) on top of it... Is there any best other way to achieve this goal ? – Sreepad Chitragar Jan 28 '15 at 06:13
  • 1
    My name is 'Laxminarayan' not 'Laxmi' and another thing is that we can't add JFrame on a JPanel. But you can simply do this by adding the multiple jPanels and setting them as a cardLayout. – Laxminarayan Jan 28 '15 at 09:10