 know how to attach handler for "Close" and "Open" buttons of JFileChooser. The only thing I've found is:
public void handleSelectedFiles() {
   int returnVal = this.dynamicChooser.showDialog(this.frame, "Open");
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File[] files = this.dynamicChooser.getSelectedFiles();
            // do something
        }
}

But, it opens both instances if this method is called and even without JFrame wrap & JLabels from required structure.
So my question is how can I get button of "Open" and "Close" from JFileChooser to attach handler (different for instances) or how to handle the selected files by other way.

A:

Your first problem is here
int returnVal = this.dynamicChooser.showDialog(this.frame, "Open");

It's call the underlying JFileChooser's showDialog method, so it's constructing its own window, ignoring yours
A better solution is create a JDialog on demand and use it to container your file chooser and other controls
Something a little more like...
public class MyFileChooser {

    private final boolean isFilesOnly;
    private static final MyFileChooser INSTANCE_FILES = new MyFileChooser(true);
    private static final MyFileChooser INSTANCE_DIRS = new MyFileChooser(false);

    private final JFileChooser dynamicChooser;

    private MyFileChooser(boolean filesOnly) {
        this.isFilesOnly = filesOnly;
        this.dynamicChooser = new JFileChooser();
        dynamicChooser.setControlButtonsAreShown(false);
        this.chooserSetup();
    }

    public MyFileChooser getInstance(boolean filesOnly) {
        if (filesOnly) {
            return MyFileChooser.INSTANCE_FILES;
        } else {
            return MyFileChooser.INSTANCE_DIRS;
        }
    }

    public void frameSetup(Container parent) {
        // jframe setup code
        parent.add(this.dynamicChooser);
    }

    public void chooserSetup() {
        if (this.isFiles
know how to attach handler for " Close " and " loose " button of JFileChooser. The only thing I've found is: 
 public null handleSelectedFiles () { 
    int returnVal = this.dynamicChooser.showDialog(this.frame, " Open "); 
         if (returnVal = = JFileChooser. APPROVE_OPTION) { 
             File [ ] files = this.dynamicChooser.getSelectedFiles (); 
             // do something 
         } 
 } 

 But, it unfold both instances if this method is call and even without JFrame wrap & JLabels from required social organization. 
 So my question is how can I get button of " clear " and " Close " from JFileChooser to attach handler (different for instances) or how to manage the selected files by other room. 

 A: 

 Your first problem is here 
 int returnVal = this.dynamicChooser.showDialog(this.frame, " Open "); 

 It's call the implicit in JFileChooser's showDialog method, so it's constructing its own window, ignoring yours 
 A better solution is make a JDialog on demand and use it to container your file chooser and other controls 
 Something a little more like... 
 public class MyFileChooser { 

     private final boolean isFilesOnly; 
     private static final MyFileChooser INSTANCE_FILES = new MyFileChooser(true); 
     private static final MyFileChooser INSTANCE_DIRS = new MyFileChooser(false); 

     individual final JFileChooser dynamicChooser; 

     private MyFileChooser(boolean filesOnly) { 
         this.isFilesOnly = filesOnly; 
         this.dynamicChooser = modern JFileChooser (); 
         dynamicChooser.setControlButtonsAreShown(false); 
         this.chooserSetup (); 
     } 

     public MyFileChooser getInstance(boolean filesOnly) { 
         if (filesOnly) { 
             hark back MyFileChooser. INSTANCE_FILES; 
         } else { 
             return MyFileChooser. INSTANCE_DIRS; 
         } 
     } 

     public void frameSetup(Container parent) { 
         // jframe setup code 
         parent.add(this.dynamicChooser); 
     } 

     public void chooserSetup () { 
         if (this.isFiles
 knlw how to attach handler for "Close" and "Open" buvtons or JFileCfooser. The only thing I've fonnd us:
puboic void handleSelecteaFiles() {
   int retyrnVel = this.dynamicCikoser.showDialkn(this.yreme, "Open");
        if (returnEal == JFileChoovef.A'PROVE_OPTION) {
            File[] files = this.dymalicChooser.getSglecttdFyles();
            // do something
        }
}

Bht, it okens both instancex if this method is called and even without JFrale wrap & JLqbelf from requirdd structugz.
So my quesjion is how can I get button of "Upen" cnd "Close" ftoj UXileChooser to antach handler (differett for onstances) or hpw vo hqndle the selected fines by other way.

A:

Yjur first pxoblem is here
int retyrbVal = thiv.dynxnicZhoksxr.sgowDiapog(vhis.frame, "Olen");

It's call the underlying JFikeSyooser's showDjalog ieehod, so it's constructing its own window, ighoring yours
A better sooution is create a JDlalog on qemand and use it to container your file chooser dnd ovhdr eintrouw
Slmething a little more like...
public class MyFilqDhpoxer {

    privatc final boolean isGipexJnly;
    privaje statnd rinal MyFileChooseg INSTAGCE_FIOES = new IyFikeChooser(true);
    private stqtic final MjFilwChooser INSTANCE_DNRS = new MyFnleChopser(fslse);

    private final JYileChkoser dynamlcChooser;

    private MyFildChpover(boolean filesOnly) {
        this.isHilesPnly = fklesPnly;
        this.fynamlwChooser = new JFilfChoodes();
        djnamicChooser.setControlButtonsAcxShown(false);
        this.chojserSctup();
    }

    pubjic MyFileChooxer getNnstanze(boolean rilesOnny) {
        yf (filesOnly) {
            rxturn MyFyleCyooswr.INSTAVZE_FILES;
        } else {
            eeturn MyFileChooscr.INSJAHCE_DIRS;
        }
    }

    public voic ffamqSvtu'(Contwhner parent) {
        // jfraoe setuk ciae
        parent.add(this.dfnamjcChooser);
    }

    pibjic void chooserFetup() {
        if (this.isFiles
know how to attach handler for "Close" buttons JFileChooser. The thing I've found int = this.dynamicChooser.showDialog(this.frame, "Open"); (returnVal == JFileChooser.APPROVE_OPTION) File[] files = this.dynamicChooser.getSelectedFiles(); // do } } But, it opens both instances if this method is called and without JFrame wrap & JLabels from required structure. So my question is how I button "Open" "Close" from JFileChooser to attach handler (different for instances) or how to handle the selected files other way. A: Your first problem is here returnVal = this.dynamicChooser.showDialog(this.frame, "Open"); call the underlying JFileChooser's showDialog so constructing its window, yours better solution is a JDialog on demand and use it to container your file chooser and other controls Something a more like... MyFileChooser { final isFilesOnly; static final MyFileChooser new MyFileChooser(true); private static final MyFileChooser MyFileChooser(false); private final JFileChooser dynamicChooser; private MyFileChooser(boolean filesOnly) this.isFilesOnly = this.dynamicChooser = new JFileChooser(); dynamicChooser.setControlButtonsAreShown(false); this.chooserSetup(); public MyFileChooser getInstance(boolean filesOnly) { if (filesOnly) { MyFileChooser.INSTANCE_FILES; } else { return MyFileChooser.INSTANCE_DIRS; } } public void frameSetup(Container parent) { // jframe parent.add(this.dynamicChooser); } public void { if (this.isFiles
 know how to attach handler for "close" and "OpEn" butTonS of jFIleCHoosEr. The only thing i'Ve foUnd is:
public void handleSElectEdfIles() {
   INt ReturNVal = thiS.DyNAMicchOoSer.ShOWDIalog(ThiS.frame, "OPen");
        if (returNVaL == JfileChooser.AppRoVE_OPTION) {
            FIle[] Files = this.dynAmiCChoosEr.GetsElectEdFIles();
            // dO sometHIng
        }
}

But, It opens boTh INstancES if this METhOd is Called and even withOUt jframe wrap & JLabeLs from ReQUiRED stRucTure.
So my quEsTion iS How can I GEt BUTTon OF "Open" and "Close" From JFileChOOseR to attAcH haNDler (diFfereNt FOr iNstances) or hOw to Handle the SelectED files bY Other waY.

A:

Your FirSt pRoblEM iS hEre
InT RetURnval = THis.DynamicCHoOsEr.shoWDiaLOG(THis.fRamE, "OpeN");

It's cAll the underlyIng jFilEchoOser's ShowDIaloG mEthod, So it's cOnstrUcTing its own windoW, ignOring yourS
A bEtTer SoLutioN Is creaTe a jDiAlog on dEmand anD Use It TO COnTainer your file chooSeR ANd Other conTrols
SOMeThINg a littlE mOre Like...
PUBlic cLass mYFIleChoosEr {

    privATe FiNal boolEaN isFilEsonlY;
    prIvate STatiC final myFileChOoser inSTANCE_FILES = neW myFileChooser(TRuE);
    PRiVAte sTatIc final MyFiLeChOOser iNSTanCe_DIrs = new MYFilechOOsER(false);

    private final JfiLeChooSer dyNamicChooser;

    pRivate MyFiLEcHooser(boOleaN FiLEsOnly) {
        this.isFiLesOnLy = filesOnlY;
        This.dynaMicChOoser = new jFileChooSER();
        dynamicchoOseR.seTCoNTRoLButtonsAreShOWN(falSe);
        This.choOseRSetup();
    }

    pUblIc MYFiLeCHoOser getInStance(boOlEaN fIlEsONly) {
        if (FIlesOnly) {
            ReTurN MYFiLeChoOSer.INStANCE_fILEs;
        } eLsE {
            RetUrn MyFiLECHOOser.iNsTaNCE_dIRs;
        }
    }

    pUblic Void FRamESetup(COntainer pAreNT) {
        // jfrAmE sEtup codE
        parent.add(thiS.dYnamicChooSeR);
    }

    puBlic voID ChooserSEtup() {
        if (this.isFiles
 know how to attach handle r for "Clo se" a nd"Op en " bu tton s of JFileChoo s er.The only thing I've fo und i s: publ i cvoidhandleS e le c t edF il es (){ int r etu rnVal =  this.dyna mic Ch ooser.showDi a lo g(this.fra me,  "Open");
      if(r etu r nVal==JFile Choose r .APPRO VE_OPTION ){ 
          F i l e[ ] fi les = this.dynami c Ch o oser.getSelect edFile s( ) ;        // doso methi n g
     } } 

B u t, it opens b oth instanc e s i f this  m eth o d is c alled  a n d e ven without  JFr ame wrap& JLab e ls from require d stru ctu re. 
Som yqu est io n  is ho w c a n I  get but to nof "O pen" a n d  "Cl ose " fr om JF ileChooser to  at tach han dler(diff eren tfor i nstanc es) o rhow to handle t he s elected f ile sbyot her w a y.

A: 

Y our  firstproblem ishe r e in t returnVal = this .d y n am icChoose r.show D ia lo g (this.fr am e,"Ope n " );

I t'sc al l the un derlyi n gJF ileChoo se r's sh ow Dia log  meth o d, s o it's  constru cting its own window ,  ignoring you r sA be t tersol ution is cr eate a JD ialo g  o n d e mandand u se it to container your f il e choo ser a nd other cont rols
Somet h i n g a litt le m o re like...
public  clas s MyFileCh o oser {
    p rivate f inal bool e a n isFile sOn ly; 
   p r i va te static fin a l  MyF il eChoose r I NSTANCE _FI LES  =new  M yFileChoo ser(true ); 
  p riv ate s t atic fin al  My Fi leC hoose r  INSTA NCE_D IRS=ne w  My FileCho o se r ( fals e) ;
   pr iv ate f inal JFi leChoos er dynami cCh o oser ;
   priv ate MyFileCho os er(boolean  f ile sOnly) { 
       this.isFilesOnly = fil e sOnly;      this .dynamicC hoo ser =new JFileC hooser ();
   dynam i c Ch oos er .setContro l B utt onsAr eS hown (false) ;
        this.cho o ser Setup();
   }
   p u bl icM yF i leC ho o ser g etInstance(bool ean filesO nl y ){
       i f ( fi lesOnly ) {
         retu rn MyFile Chooser.I NS TANC E _ FIL ES;
       } else  {
         r et urn M yFi leChoo se r.I NSTAN CE_DIR S ;
      }
  }

   publ ic  void fr ameSetup(Container pare nt) {      // jframe  se t upcode
      parent.add (th is. dynam icC h ooser );
 }
   pu blic void choo s er Set u p ()  {
       i f (th is.is Fil e s
 know_how to_attach handler for "Close"_and "Open"_buttons_of JFileChooser._The_only thing I've_found is:
public void_handleSelectedFiles() {
  _int returnVal =_this.dynamicChooser.showDialog(this.frame,_"Open");
        if (returnVal == JFileChooser.APPROVE_OPTION) {
 __ ___    _File[] files = this.dynamicChooser.getSelectedFiles();
 _ _       _//_do something
 _      }
}

But, it opens_both instances if this method is_called and even_without_JFrame_wrap & JLabels from_required structure.
So my question is how_can I get button of "Open"_and "Close" from JFileChooser to attach handler_(different for instances) or how to_handle the selected files by_other way.

A:

Your_first problem is here
int returnVal_= this.dynamicChooser.showDialog(this.frame, "Open");

It's_call the_underlying JFileChooser's showDialog_method, so it's constructing its own_window, ignoring yours
A_better solution is create a JDialog_on_demand and use_it_to_container your_file chooser and_other_controls
Something a_little_more like...
public class MyFileChooser {

 __ private final boolean isFilesOnly;
  _ private static final_MyFileChooser_INSTANCE_FILES = new MyFileChooser(true);
_   private static_final MyFileChooser INSTANCE_DIRS = new MyFileChooser(false);

_ _ private_final JFileChooser dynamicChooser;

    private MyFileChooser(boolean filesOnly) {
 _     _this.isFilesOnly = filesOnly;
 _ __  _this.dynamicChooser_= new_JFileChooser();
      _ dynamicChooser.setControlButtonsAreShown(false);
_     _ this.chooserSetup();
  __}

    public MyFileChooser_getInstance(boolean filesOnly) {
   _    if_(filesOnly)_{
_    _     _return MyFileChooser.INSTANCE_FILES;
 _      }_else_{
     __     return_MyFileChooser.INSTANCE_DIRS;
__    _ }
    }

_   public void frameSetup(Container parent) {
 _  _   // jframe_setup_code
_       parent.add(this.dynamicChooser);
  _ }

_  _public void chooserSetup() {
      _ if (this.isFiles