// -*- mode:java; encoding:utf-8 -*-
// vim:set fileencoding=utf-8:
// @homepage@

package example;

import java.awt.*;
import java.util.Objects;
import javax.swing.*;

public final class MainPanel extends JPanel {
  private MainPanel() {
    super(new BorderLayout());

    Object showHiddenProperty = Toolkit.getDefaultToolkit().getDesktopProperty("awt.file.showHiddenFiles");
    System.out.println("awt.file.showHiddenFiles: " + showHiddenProperty);

    JFileChooser chooser = new JFileChooser();
    JPopupMenu pop = searchPopupMenu(chooser);
    pop.addSeparator();
    JCheckBoxMenuItem mi = new JCheckBoxMenuItem("isFileHidingEnabled");
    mi.addActionListener(e -> chooser.setFileHidingEnabled(((JCheckBoxMenuItem) e.getSource()).isSelected()));
    mi.setSelected(chooser.isFileHidingEnabled());
    pop.add(mi);

    JTextArea log = new JTextArea();
    JButton button = new JButton("showOpenDialog");
    button.addActionListener(e -> {
      int retvalue = chooser.showOpenDialog(getRootPane());
      if (retvalue == JFileChooser.APPROVE_OPTION) {
        log.setText(chooser.getSelectedFile().getAbsolutePath());
      }
    });

    JPanel p = new JPanel();
    p.setBorder(BorderFactory.createTitledBorder("JFileChooser"));
    p.add(button);
    add(p, BorderLayout.NORTH);
    add(new JScrollPane(log));
    setPreferredSize(new Dimension(320, 240));
  }

  private static JPopupMenu searchPopupMenu(Container parent) {
    for (Component c: parent.getComponents()) {
      if (c instanceof JComponent && Objects.nonNull(((JComponent) c).getComponentPopupMenu())) {
        return ((JComponent) c).getComponentPopupMenu();
      } else {
        JPopupMenu pop = searchPopupMenu((Container) c);
        if (Objects.nonNull(pop)) {
          return pop;
        }
      }
    }
    return null;
  }

  public static void main(String[] args) {
    EventQueue.invokeLater(MainPanel::createAndShowGui);
  }

  private static void createAndShowGui() {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
      ex.printStackTrace();
      Toolkit.getDefaultToolkit().beep();
    }
    JFrame frame = new JFrame("@title@");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().add(new MainPanel());
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
  }
}

@@ -139,16 +139,43 @@
 bjects;%0A
+import java.util.Optional;%0A
 import j
@@ -188,16 +188,16 @@
 wing.*;%0A
-
 %0Apublic 
@@ -526,33 +526,36 @@
 ();%0A    
-JPopupMenu pop = 
+Optional.ofNullable(
 searchPo
@@ -570,22 +570,43 @@
 chooser)
-;%0A
+).ifPresent(pop -%3E %7B%0A 
     
+ 
 pop.addS
@@ -613,24 +613,26 @@
 eparator();%0A
+  
     JCheckBo
@@ -688,24 +688,26 @@
 gEnabled%22);%0A
+  
     mi.addAc
@@ -809,16 +809,18 @@
 ));%0A    
+  
 mi.setSe
@@ -854,24 +854,26 @@
 Enabled());%0A
+  
     pop.add(
@@ -876,16 +876,24 @@
 add(mi);
+%0A    %7D);
 %0A%0A    JT
@@ -1024,17 +1024,17 @@
  int ret
-v
+V
 alue = c
@@ -1084,17 +1084,17 @@
  if (ret
-v
+V
 alue == 

assert popup not null