Io ho fatto così, ma non funziona.
codice:
public class MyFrame extends javax.swing.JFrame implements TreeSelectionListener {
public MyFrame(String titolo) {
super(titolo);
tabbedPane = new JTabbedPane();
this.tabbedPane.setPreferredSize(new Dimension(600, 400));
scrollPane = new JScrollPane(this.tabbedPane);
this.getContentPane().add(scrollPane, BorderLayout.CENTER);
pannelloPulsanti = new JPanel(new FlowLayout());
this.getContentPane().add(pannelloPulsanti, BorderLayout.SOUTH);
this.getContentPane().validate();
this.addWindowListener(new java.awt.event.WindowAdapter() {
@Override
public void windowClosing(java.awt.event.WindowEvent evt) {
closeDialog(evt);
}
});
this.pack();
this.albero = new JTree();
// Crea l'albero e lo tiene aggiornato
creaAlbero();
albero.addTreeSelectionListener(this);
MyScrollPane scrollPaneAlbero = new MyScrollPane(albero);
albero.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
this.getContentPane().add(scrollPaneAlbero, BorderLayout.WEST);
this.getContentPane().validate();
this.pack();
centraSuSchermo();
}
class MyScrollPane extends JScrollPane {
public MyScrollPane(Component view) {
super(view);
}
@Override
public Dimension getPreferredSize() {
return this.getViewport().getView().getPreferredSize();
}
}
}
Evidentemente sto facendo qualche errore che però non riesco a capire / vedere.