-1

How can I reach jPanel on an other jFrame ? I want to impel users question.According to answer(yes),I want to get jPanel.setVisible(true) on an other jFrame

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
Zehra
  • 79
  • 1
  • 1
  • 8
  • thanks Andrew,I've solved as you say.My wrong is opening new frame for dialog :) Last case : int sonuc = JOptionPane.showConfirmDialog(rootPane,"Hastanın Dosya Numarası Bulunamadı.Yeni Kayıt Yapılsın mı?", "Kayıt İsteği", JOptionPane.YES_NO_OPTION); if(sonuc==0) jPanel3.setVisible(true); else this.setVisible(true); – Zehra Jul 23 '14 at 08:52

3 Answers3

1

Use some kind of model, which can be altered by your first frame, but which your second frame is listening to.

You should very rarely try and access UI elements that are outside the scope of your current class, as this leads to no end of issues with trying to figure out who is control.

This is at the core of the Model-View-Controller paradigm and observer pattern

You should also have a look at The Use of Multiple JFrames: Good or Bad Practice?

Community
  • 1
  • 1
MadProgrammer
  • 343,457
  • 22
  • 230
  • 366
1

I want to impel users question. According to answer(yes), I want..

See the overloaded methods of JOptionPane.showConfirmDialog(..).

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
0

First of all, please change your question because it is very hard to understand what you want from us.

Now to your problem: I think you want to access a jPanel that is located at the other JFrame.

My Solution: Just make a reference to it! So if you have a class MyFrame, just make it look like this one:

public class MyFrame{
    private JPanel panelThatIsLocatedAtTheSecondFrame

    //Setter and Getter and the other bullshit :D
}

public static void main(String[] args){
MyFrame frame1 = new MyFrame();
MyFrame frame2 = new MyFrame();

JPanel panelIWantToObserve = new JPanel();

frame2.add(panelIWantToObserve);
frame1.setPanelThatIsLocatedAtTheSecondFrame(panelIWantToObserve);
}
romaneso
  • 1,097
  • 1
  • 10
  • 26