2012-10-28 2 views
2

저는 이미지 처리 응용 프로그램을 만들기 위해 다른 사람 코드를 재사용하고 수정해야하는 위치에 있습니다. 다음 코드는 프레임과 GUI를 설정하는 데 사용됩니다. 내가 가지고있는 문제는 파일 단어가 menubar에서 클릭되면 menuitems가 originalImage 컨테이너에 포함 된 캔버스 아래에 나열된다는 것입니다. 나는 메뉴 모음 그래서 나는 내가 JPanel의에 캔버스를 추가 한 그 길을 믿고있어 잘 알고바의 내 메뉴가 컨테이너의 JPanel 아래에 표시되는 이유는 무엇입니까?

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); 

} 

: 다음은 코드입니다. JPanel에서 z 순서를 설정해야합니까? 저는 집에있는 책을 읽었으며 이런 종류의 문제에 대해서는 언급하지 않았습니다. 덕분에, AWT와 스윙 구성 요소를 혼합 다니엘

+0

코드를 제거하고 SSCCE에 입력하십시오. – kleopatra

+0

[답변 : @Michael Dunn] (http://www.coderanch.com/t/596384/GUI/java/JMenuBar-menu-displaying-below-component) – mKorbel

+0

@mKorbel 믹싱 _should_ 더 이상 문제가되지 않으며 올바르게 수행됩니다. :-) Daniel, 예고없이 교차 게시하는 것은 조롱받는쪽에 약간 있다고 생각됩니다 (도우미의 노력이 중복 될 수 있기 때문에) – kleopatra

답변

0

이 겹치는 문제가 발생합니다, 캔버스는 AWT 구성 요소입니다, JDK1.6_12 후 JPanel을 대신 를 사용하여, 당신은 모두의 안전을 사용할 수 있습니다.

관련 문제