2014-02-14 1 views
0

WindowBuilderPro를 사용하여 프로그램을 작성했으며 정상적으로 작동합니다. 그러나 이제는 새로운 프로젝트에서 2 개의 클래스를 재사용하고 싶지만 처음 프로젝트에 복사하면 Eclipse에서 2 개의 오류가 발생합니다. 다음과 같이 내가 할WindowBuilderPro로 만든 시각적 클래스 재사용

import java.awt.BorderLayout; 
import java.awt.EventQueue; 

import javax.swing.JFrame; 
import javax.swing.JPanel; 
import javax.swing.border.EmptyBorder; 
import javax.swing.JTextField; 
import javax.swing.JLabel; 
import java.awt.Font; 
import org.eclipse.wb.swing.FocusTraversalOnArray; 
import java.awt.Component; 

public class ExampleFrame extends JFrame { 

    private JPanel contentPane; 
    private JTextField textField; 
    private JTextField textField_1; 

    /** 
    * Launch the application. 
    */ 
    public static void main(String[] args) { 
     EventQueue.invokeLater(new Runnable() { 
      public void run() { 
       try { 
        ExampleFrame frame = new ExampleFrame(); 
        frame.setVisible(true); 
       } catch (Exception e) { 
        e.printStackTrace(); 
       } 
      } 
     }); 
    } 

    /** 
    * Create the frame. 
    */ 
    public ExampleFrame() { 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setBounds(100, 100, 450, 300); 
     contentPane = new JPanel(); 
     contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); 
     setContentPane(contentPane); 
     contentPane.setLayout(null); 

     textField = new JTextField(); 
     textField.setBounds(106, 32, 74, 28); 
     contentPane.add(textField); 
     textField.setColumns(10); 

     JLabel lblNewLabel = new JLabel("Box 1"); 
     lblNewLabel.setFont(new Font("Tahoma", Font.PLAIN, 18)); 
     lblNewLabel.setBounds(31, 39, 46, 14); 
     contentPane.add(lblNewLabel); 

     JLabel lblBox = new JLabel("Box 2"); 
     lblBox.setFont(new Font("Tahoma", Font.PLAIN, 18)); 
     lblBox.setBounds(31, 101, 46, 14); 
     contentPane.add(lblBox); 

     textField_1 = new JTextField(); 
     textField_1.setColumns(10); 
     textField_1.setBounds(106, 94, 74, 28); 
     contentPane.add(textField_1); 
     contentPane.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{lblNewLabel, textField, lblBox, textField_1})); 
    } 
} 

2 개의 오류가 있습니다 : 여기에 문제를 보여주는 SSCCE입니다

import org.eclipse.wb.swing.FocusTraversalOnArray; 

FocusTraversalOnArray cannot be resolved to a type 

상기 라인에

The import org.eclipse cannot be resolved 

라인

contentPane.setFocusTraversalPolicy(new FocusTraversalOnArray(new Component[]{lblNewLabel, textField, lblBox, textField_1})); 

이 줄들은 탭 순서를 설정할 때 나타납니다. 아무도 이것을 극복하는 방법을 알고 있습니까? Java의 핵심은 컴포넌트를 재사용 할 수 있다는 것입니다.

답변

0

이전 프로젝트에서 사용한 모든 라이브러리를 새 프로젝트의 빌드 경로에 추가해야했습니다.

0

Window Builder로 작성된 클래스를 복사 한 후 동일한 문제가 발생했습니다. 나는 다음 파일이 누락되었음을 발견했다 :

\src\org\eclipse\wb\swinger\FocusTraversalOnArray.java 

이것은 Window Builder가 외부 적으로 추가하는 유일한 파일 인 것 같다. 누군가가 필요로 할 경우에 대비하여 여기에 코드를 게시 할 것입니다.

/******************************************************************************* 
* Copyright (c) 2011 Google, Inc. 
* All rights reserved. This program and the accompanying materials 
* are made available under the terms of the Eclipse Public License v1.0 
* which accompanies this distribution, and is available at 
* http://www.eclipse.org/legal/epl-v10.html 
* 
* Contributors: 
* Google, Inc. - initial API and implementation 
*******************************************************************************/ 
package org.eclipse.wb.swing; 

import java.awt.Component; 
import java.awt.Container; 
import java.awt.FocusTraversalPolicy; 

/** 
* Cyclic focus traversal policy based on array of components. 
* <p> 
* This class may be freely distributed as part of any application or plugin. 
* 
* @author scheglov_ke 
*/ 
public class FocusTraversalOnArray extends FocusTraversalPolicy { 
    private final Component m_Components[]; 
    //////////////////////////////////////////////////////////////////////////// 
    // 
    // Constructor 
    // 
    //////////////////////////////////////////////////////////////////////////// 
    public FocusTraversalOnArray(Component components[]) { 
     m_Components = components; 
    } 
    //////////////////////////////////////////////////////////////////////////// 
    // 
    // Utilities 
    // 
    //////////////////////////////////////////////////////////////////////////// 
    private int indexCycle(int index, int delta) { 
     int size = m_Components.length; 
     int next = (index + delta + size) % size; 
     return next; 
    } 
    private Component cycle(Component currentComponent, int delta) { 
     int index = -1; 
     loop : for (int i = 0; i < m_Components.length; i++) { 
      Component component = m_Components[i]; 
      for (Component c = currentComponent; c != null; c = c.getParent()) { 
       if (component == c) { 
        index = i; 
        break loop; 
       } 
      } 
     } 
     // try to find enabled component in "delta" direction 
     int initialIndex = index; 
     while (true) { 
      int newIndex = indexCycle(index, delta); 
      if (newIndex == initialIndex) { 
       break; 
      } 
      index = newIndex; 
      // 
      Component component = m_Components[newIndex]; 
      if (component.isEnabled() && component.isVisible() && component.isFocusable()) { 
       return component; 
      } 
     } 
     // not found 
     return currentComponent; 
    } 
    //////////////////////////////////////////////////////////////////////////// 
    // 
    // FocusTraversalPolicy 
    // 
    //////////////////////////////////////////////////////////////////////////// 
    public Component getComponentAfter(Container container, Component component) { 
     return cycle(component, 1); 
    } 
    public Component getComponentBefore(Container container, Component component) { 
     return cycle(component, -1); 
    } 
    public Component getFirstComponent(Container container) { 
     return m_Components[0]; 
    } 
    public Component getLastComponent(Container container) { 
     return m_Components[m_Components.length - 1]; 
    } 
    public Component getDefaultComponent(Container container) { 
     return getFirstComponent(container); 
    } 
} 
+0

답변 해 주셔서 감사합니다. 제 경우에는 누락 된 줄이 없었습니다. 내 대답에 넣은 문제는 (답장이 내 사서함에 나타날 때까지는 그것을 잊어 버렸습니다.) 모든 라이브러리를 빌드 경로에 추가해야했습니다. –