I'm in the position where I have to reuse and modify another persons code to create an image processing application. The following code is used to setup the frame and its GUI. The problem I'm having is that when the file word is clicked on the menubar the menuitems are listed below the canvas contained in the originalImage container. Here is the code:
public ImageLoader(){
super("IRIS Application");
JMenu fileMenu = new JMenu("File");
JMenuItem fileOpenChoice = new JMenuItem("Open File");
fileOpenChoice.addActionListener(new FileOpener());
fileMenu.add(fileOpenChoice);
JMenuItem fileSaveChoice = new JMenuItem("Save File");
fileSaveChoice.addActionListener(new FileSaver());
fileMenu.add(fileSaveChoice);
JMenu processMenu = new JMenu("Process");
JMenuItem reduceContrast = new JMenuItem("Reduce Contrast");
reduceContrast.addActionListener(new ReduceContrast());
processMenu.add(reduceContrast);
JMenuItem scale = new JMenuItem("Scale");
scale.addActionListener(new Scaler());
processMenu.add(scale);
JMenuItem sobel = new JMenuItem("Sobel");
sobel.addActionListener(new Sobel());
processMenu.add(sobel);
JMenuItem prewitt = new JMenuItem("Prewitt");
prewitt.addActionListener(new Prewitt());
processMenu.add(prewitt);
originalImage = new BufferedImage(565, 584, BufferedImage.TYPE_BYTE_GRAY);
processedImage = new BufferedImage(565, 584, BufferedImage.TYPE_BYTE_GRAY);
originalRaster = originalImage.getRaster();
processedRaster = processedImage.getRaster();
ic = new ImageCanvas();
pc = new ImageCanvas();
Container content = this.getContentPane();
content.setLayout(new FlowLayout());
JPanel originalContainer = new JPanel();
originalContainer.add(ic);
originalContainer.setSize(ic.getWidth(), ic.getHeight());
originalContainer.setBorder(new EtchedBorder());
JPanel processedContainer = new JPanel();
processedContainer.add(pc);
processedContainer.setSize(pc.getWidth(), pc.getHeight());
processedContainer.setBorder(new EtchedBorder());
JPanel imagePanel = new JPanel();
imagePanel.setLayout(new FlowLayout());
imagePanel.add(originalContainer);
imagePanel.add(processedContainer);
//content.add(imagePanel, BorderLayout.NORTH);
JPanel originalGrid = new JPanel();
originalGrid.setLayout(new GridLayout(0,1,5,0));
JPanel processedGrid = new JPanel();
processedGrid.setLayout(new GridLayout(0,1,5,0));
originalText = new JTextField("Original Text");
JButton originalButton = new JButton("View Coordinates Table");
originalGrid.add(originalText);
originalGrid.add(originalButton);
JTextField processedText = new JTextField("Processed Text");
JButton processedButton = new JButton("View Coordinates Table");
processedGrid.add(processedText);
processedGrid.add(processedButton);
JPanel informationPanel = new JPanel();
informationPanel.setBackground(Color.red);
informationPanel.setLayout(new BorderLayout());
informationPanel.add(originalGrid, BorderLayout.WEST);
informationPanel.add(processedGrid, BorderLayout.EAST);
//content.add(informationPanel, BorderLayout.SOUTH);
ic.addMouseMotionListener(new ImageMouseMotionListener(ic, originalText));
pc.addMouseMotionListener(new ImageMouseMotionListener(pc, processedText));
JMenuBar bar = new JMenuBar();
bar.add(fileMenu);
bar.add(processMenu);
content.add(imagePanel, BorderLayout.NORTH);
content.add(informationPanel, BorderLayout.SOUTH);
setJMenuBar(bar);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(1200, 725);
setResizable(false);
setVisible(true);
setLocation(125, 0);
}
I know the menu bar is fine so I'm assuming its the way I've added the canvas to the JPanel. Should a set its z order in the JPanel? I've read through the books I have at home and nothing mentions this kind of problem. Thanks, Daniel