ciao!
si mi ero risposto da solo nel frattempo.
scemenza mia:
codice:
import java.awt.BorderLayout;
import java.awt.Dimension;
import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.WindowConstants;
public class MainWindow extends JFrame {
private JTextPane textPane;
private JScrollPane scrollPane;
private JMenuBar menuBar;
private JMenu menuFile;
private JMenuItem itemChoose;
private JMenuItem itemSave;
private JMenuItem itemExit;
public MainWindow() {
super("Lista directory");
createGui();
}
private void createGui() {
textPane = new JTextPane();
scrollPane = new JScrollPane();
menuBar = new JMenuBar();
menuFile = new JMenu();
itemChoose = new JMenuItem();
itemSave = new JMenuItem();
itemExit = new JMenuItem();
setPreferredSize(new Dimension(700, 700));
setLayout(new BorderLayout());
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setResizable(false);
textPane.setEditable(false);
scrollPane.setViewportView(textPane);
getContentPane().add(scrollPane, BorderLayout.CENTER);
menuFile.setText("File");
menuFile.add(itemChoose);
menuFile.add(itemSave);
menuFile.add(itemExit);
menuBar.add(menuFile);
setJMenuBar(menuBar);
pack();
setLocationRelativeTo(null);
}
public static void main(String args[]) {
if (System.getProperty("os.name").toLowerCase().contains("mac")) {
System.setProperty("apple.laf.useScreenMenuBar", "true");
} else {
try {
for (UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
SwingUtilities.invokeLater(() -> {
new MainWindow().setVisible(true);
});
}
}
grazie!!