2014-09-01 4 views
2

은 내가 JPanelGridBaglayout에 별도의 항목에 대한 JTabbedPane,하지만 모든 시간의 JTabbedPane 버그 내 텍스트 필드 객체의 두 번째 탭 ... 내 동물 레지스터입니다JTabbedPane에, JPanel의 및 GridBagLayout을

을 만들려면 클래스, 확장 클래스 및 기본 클래스 문제는 두 번째 테이블의 텍스트 필드에 있습니다.

하는 문제 코드 ...

코드 :

public class Cad_Animals extends Register_Screen{ 
    JTextField number = new JTextField(10); 
    JTextField name = new JTextField(30); 
    JTabbedPane pane1 = new JTabbedPane(1); 
    JTabbedPane pane2 = new JTabbedPane(1); 

    JTextField race = new JTextField(10); 
    JTextField proprietario = new JTextField(10); 
    JPanel jl1 = new JPanel(); 
    JPanel jl2 = new JPanel(); 

    JTextField father = new JTextField(10); 
    JTextField mother = new JTextField(10); 

    public Cad_Animals(){ 
     super("Animal Register"); 
     jl1.setLayout(new GridBagLayout()); 
     jl2.setLayout(new GridBagLayout()); 
     addComponent(1, 1, 1, 1, number,jl1); 
     addComponent(2, 1, 1, 1, name,jl2); 

     addComponent(3, 1, 1, 1, proprietario,jl1); 
     addComponent(2, 1, 1, 1, race,jl2); 
     addComponent(6, 1, 1, 1, father,jl1); 
     addComponent(7, 1, 1, 1, mother,jl1); 


     //pane1.addTab("table1", jl2); 
     //pane2.addTab("table2", jl1); 

     //addComponent(8, 1, 6, 6, pane1,1); 
     // addComponent(8, 2, 3, 3, pane2,1); 

     //painels("new2",jl2); 
     //painels("new2", jl1); 

     pack(); 
    } 
} 

.

public class Register_Screen extends JFrame { 

    JTabbedPane la = new JTabbedPane(); 

    public Register_Screen(String titulo) { 
     super(titulo); 
     getContentPane().setLayout(new BorderLayout());  

     setVisible(true); 
     pack(); 

    } 

     public void addComponent(int line, int column, int height, int width, JComponent component,JComponent compnum) { 
     GridBagConstraints gbc = new GridBagConstraints(); 
     gbc.gridy = line; 
     gbc.gridx = column; 
     gbc.gridheight = 1; //1 
     gbc.gridwidth = 1; //1 
     gbc.anchor = GridBagConstraints.WEST; 
     gbc.insets = new Insets(1, 5, 3, 5); 
     gbc.weightx = 1.0; 
     gbc.weighty = 1.0; 



     gbc.gridx++; 
     gbc.gridheight = height; 
     gbc.gridwidth = width; 
     //jpCampos.add(component, gbc); 
     compnum.add(component, gbc); 

     getContentPane().add(la); 


     la.addTab("West",compnum); 
     //jtpTabs.add("asdsa",jpCampos);    
    } 
} 

.

public class MainClass { 
     public static void main(String args[]) throws InterruptedException{ 
    try { 
      UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel"); 

     } catch (Exception e) { 
      JOptionPane.showMessageDialog(null, "Não foi possivel Carregar NimbusLookandFeel"); 
     } 
     Cad_Animals cad = new Cad_Animals(); 
+0

이것이 내 문제 였고 여기서 도움을 얻으 려했다면 [최소 예제 프로그램] (http://stackoverflow.com/help/mcve)을 만들고 게시하는 데 약간의 시간이 필요했습니다. 사람들이 내 문제를 완전히 이해하고 나를 도울 수있는 가장 빠르고 가장 빠른 방법이라고 생각합니다. –

+0

CALL_TEST에 레이아웃 관리자가없는 것 같습니다. – MadProgrammer

+0

다른 모든 사람의 정 결함에 대해서는 [Java 코딩 규칙] (http://www.oracle.com/technetwork/java/codeconvtoc-136057. html) – MadProgrammer

답변

2

추측 :

당신은 weightx에는도 당신의 GridBagConstraint의 무게를 설정하지 않고, 그래서 당신의 GridBagConstraints이 남자 0.0의 기본값이되는 것이다 무리까지 모든 구성 요소에 센터. weightx W weighty 제한 조건 필드에 1.0 값을 제공하십시오. 이 답변이 도움이되지 않는 경우

즉,

gbc.gridy = line; 
gbc.gridx = column; 
gbc.gridheight = 1; 
gbc.gridwidth = 1; 
gbc.anchor = GridBagConstraints.WEST; 
gbc.insets = new Insets(1, 5, 3, 5); 

// ***** add these two lines 
gbc.weightx = 1.0; 
gbc.weighty = 1.0; 

, 나는 당신이 작성하고 minimal example program을 게시하는 데 다소 시간이 걸릴 것을, 내가 원래 질문에 대한 코멘트에서 만든 추천에 의해 서있다.

+0

나는 이것을하지만 텍스트 필드가 아니라 주석 만 정렬합니다. –

+0

@SamuelRonha : 그러면 [mcve] (http://stackoverflow.com/help/mcve)를 작성하고 게시 할 때가 있습니다. –

+0

@SamuelRonha : 또한 'gbc.fill' 속성을 할당하지 않습니다. JTextField의 GridBagConstraints 객체에'GridBagConstraints.HORIZONTAL'의 채우기 프로퍼티를 부여하는 것을 고려하십시오. –