ciao!
mi sono reso conto che a forza di creare gui con gli editor visuali, mi sono dimenticato parecchie cose.
così, dovendo riscrivere un programmino, ho pensato di creare la gui a mano.
solo che quando lancio il programma, la finestra praticamente non compare a video.
come se non venisse diesgnata:
codice:
public class MainWindow extends JFrame {
private JFrame mainFrame;
private JTextPane textPane;
private JScrollPane scrollPane;
private JMenuBar menuBar;
private JMenu menuFile;
private JMenuItem itemChoose;
private JMenuItem itemSave;
private JMenuItem itemExit;
public MainWindow() {
createGui();
}
private void createGui() {
mainFrame = new JFrame("Lista directory");
textPane = new JTextPane();
scrollPane = new JScrollPane();
menuBar = new JMenuBar();
menuFile = new JMenu();
itemChoose = new JMenuItem();
itemSave = new JMenuItem();
itemExit = new JMenuItem();
mainFrame.setSize(new Dimension(700, 700));
mainFrame.setLayout(new BorderLayout());
mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
mainFrame.setResizable(false);
mainFrame.setLocationRelativeTo(null);
textPane.setEditable(false);
scrollPane.setViewportView(textPane);
menuFile.setText("File");
menuFile.add(itemChoose);
menuFile.add(itemSave);
menuFile.add(itemExit);
menuBar.add(menuFile);
mainFrame.setJMenuBar(menuBar);
mainFrame.getContentPane().add(scrollPane, BorderLayout.CENTER);
mainFrame.pack();
}
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());
}
}
EventQueue.invokeLater(() -> {
new MainWindow().setVisible(true);
});
}
}
dove sto sbagliando??