ho inserito il menù con add a north,comunque proverò anche con setMenuBar(),nel frattempo ecco il codice.GRAZIE
package swingtest;
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
import javax.media.jai.*;
import java.awt.image.RenderedImage;
import javax.media.jai.widget.ScrollingImagePanel;
import com.sun.media.jai.codec.FileSeekableStream;
/**
*
Title: </p>
*
Description: </p>
*
Copyright: Copyright (c) 2004</p>
*
Company: </p>
* @author not attributable
* @version 1.0
*/
public class FinestraSwing extends JFrame{
private JMenuBar barra = new JMenuBar();
private JMenu file = new JMenu("File");
private JMenu effect = new JMenu("Effect");
private JMenuItem esci = new JMenuItem("Esci");
private JMenuItem salva = new JMenuItem("Salva");
private JMenuItem salvaas = new JMenuItem("Salva con nome");
private JMenuItem apri = new JMenuItem("Apri");
private JOptionPane pannello = new JOptionPane();
private JFileChooser aprifile = new JFileChooser();
Container contentPane = getContentPane();
private JLabel srclabel;
private JLabel dstlabel;
private JPanel srcpanel;
private JPanel dstpanel;
private JPanel panelbar;
private JPanel panel;
private JPanel panelimg=new JPanel();
private ScrollingImagePanel srcimg;
private JPanel panelmain;
private JPanel fine;
/* Costruttore della classe*/
public FinestraSwing() throws HeadlessException {
super("Visualizzatore D'immagini");
setSize(500,500);
barra.add(file);
barra.add(effect);
file.add(apri);
file.add(salva);
file.add(salvaas);
file.add(esci);
getContentPane().setLayout(new BorderLayout());
/*Pannello diviso in due parti uguali*/
panelimg = new JPanel();
panelimg.setLayout(new GridLayout(1,2));
panelimg.setDoubleBuffered(true);
panelimg.setBackground(Color.white);
panelimg.setBorder(BorderFactory.createLineBorder( Color.black));
JLabel srclabel = new JLabel("Pannello sorgente");
JLabel dstlabel = new JLabel("Pannello destinazione");
panelimg.add(srclabel);
panelimg.add(dstlabel);
getContentPane().add(barra,BorderLayout.NORTH);
getContentPane().add(panelimg,BorderLayout.CENTER) ;
esci.addActionListener(new AscoltaEsci());
apri.addActionListener(new AscoltaApri());
}
public class AscoltaEsci implements ActionListener {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
}
public class AscoltaApri implements ActionListener {
public void actionPerformed(ActionEvent e) {
aprifile.setDialogTitle("Scegli Immagine");
aprifile.showOpenDialog (pannello);
String fileName = new String(aprifile.getSelectedFile().toString());
RenderedImage img=JAI.create("fileload",fileName);
srcimg=new ScrollingImagePanel(img,ScrollPaneConstants.HORIZO NTAL_SCROLLBAR_ALWAYS,ScrollPaneConstants.VERTICAL _SCROLLBAR_ALWAYS);
srcimg.setOrigin(0,0);
srcimg.setSize(400,600);
srcimg.doLayout();
panelimg.add(srcimg);
getContentPane().add(panelimg);
}
}
public static void main(String[] args) throws HeadlessException {
FinestraSwing finestraSwing1 = new FinestraSwing();
finestraSwing1.setVisible(true);
}
}