2012-08-24 6 views
3

DialogBoxMigLayout을 사용합니다.텍스트 필드 크기 및 세로 맞춤

모든 패널은 MigLayout을 사용합니다.

쇼 행을위한 패널이 있습니다. 모든 열 (전달 유형, 요소, Sortie 선택)에 대한 패널이 있습니다. 출력 파일 행을위한 패널이 있습니다. 버튼을위한 패널이 있습니다.

아마도 패널을 너무 많이 사용하는 것이 더 좋은 방법일까요?

example with miglayout

내 창을 이동시킬 때까지 내 텍스트 필드가 더 크기가 없습니다

//set global layout 
this.setLayout(new MigLayout("wrap 3, debug")); 

this.add(getSearchPanel(), "span 3, wrap"); 

// middle section 
this.add(getLivraison(), "width 33%"); 
this.add(getChoixElement(), "width 33%"); 
this.add(getProfile(), "width 33%"); 

JLabel lblFichierSortie = new JLabel("Output file"); 
JTextField txtFichierSortie = new JTextField(); 
this.add(lblFichierSortie, "span 2, right"); 
this.add(txtFichierSortie, "width 33%, wrap"); 

this.add(getButton(), "span 3, right"); 

private JPanel getSearchPanel() { 
    JPanel searchPanel = new JPanel(new MigLayout()); 

    JLabel lblEmission = new JLabel("Show"); 
    JTextField txtEmission = new JTextField(10); 
    JTextField txtEM = new JTextField(5); 

    searchPanel.add(lblEmission, "width 2%"); 
    searchPanel.add(txtEmission, "split 2,right,width 60%, growx"); 
    searchPanel.add(txtEM, "width 38%, growx"); 

    return searchPanel; 
} 

private JPanel getLivraison() { 
    JPanel livraisonPanel = new JPanel(new MigLayout()); 
    JLabel lblComponent1 = new JLabel("Delivery type"); 
    JCheckBox chkFluxElementaire = new JCheckBox("Flux"); 
    JCheckBox chkTranscoding = new JCheckBox("Transcoding"); 

    livraisonPanel.add(lblComponent1, "wrap"); 
    livraisonPanel.add(chkFluxElementaire, "wrap"); 
    livraisonPanel.add(chkTranscoding, "wrap"); 

    return livraisonPanel; 
} 

private JPanel getChoixElement() { 
    JPanel component2 = new JPanel(new MigLayout()); 
    JLabel lblChoix = new JLabel("Choose element"); 
    JLabel lblVideo = new JLabel("Vidéo"); 


    JLabel lblAudio = new JLabel("Audio"); 
    JLabel lblAudio2 = new JLabel("Audio 2"); 
    JLabel lblSubTitle = new JLabel("ST"); 
    JLabel lblMontage = new JLabel("Montage"); 

    //todo put combobox below every label 
    component2.add(lblChoix, "wrap"); 
    component2.add(lblVideo,"wrap"); 
    component2.add(lblAudio,"wrap"); 
    component2.add(lblAudio2, "wrap"); 
    component2.add(lblSubTitle, "wrap"); 
    component2.add(lblMontage, "wrap"); 

    return component2; 
} 

private JPanel getProfile() { 
    JPanel component3 = new JPanel(new MigLayout()); 
    JLabel lblSortie = new JLabel("Sortie"); 
    component3.add(lblSortie, "wrap"); 

    JLabel lblProfil = new JLabel("Profil"); 
    component3.add(lblProfil, "wrap"); 

    JComboBox cbxProfil = new JComboBox(); 
    component3.add(cbxProfil, "wrap"); 

    return component3; 
} 

private JPanel getButton() { 
    JPanel buttonPanel = new JPanel(new MigLayout("fillx,insets 0")); 

    JButton okButton = new JButton("Ok"); 
    okButton.setMnemonic('O'); 
    buttonPanel.add(okButton, "split,right,width 100!"); 

    // Cancel button 
    JButton cancelButton = new JButton("Cancel"); 
    cancelButton.setMnemonic('C'); 

    buttonPanel.add(cancelButton, "width 100!"); 
    return buttonPanel; 
} 

내 코드, 난 왜 이해가 안 돼요. 또한 모든 열의 구성 요소가 패널 상단에서 시작하는 이유는 무엇입니까?

+0

행의 구성 요소는 기본적으로 수직 가운데 맞춤이 있습니다. 레이아웃에 "상단"행 제약 조건을 추가하여 해당 부분을 수정할 수 있습니다. –

+0

나는이 논문의 레이아웃을 가장 위에 올려 놓았다 : getLivraison() getChoixElement() getProfile() 나는 같은 결과를 얻는다. – redfox26

+0

주 레이아웃에서 행 제약 조건으로 사용합니다 :'this.setLayout (new MigLayout ("wrap 3, debug"));'. –

답변

3

는 "상단 정렬 문제"이보십시오 :

// set global layout 
this.setLayout(new MigLayout("wrap 3, debug", null, "[top]")); 

및 "는 texfield 크기 문제"에 대한

:

this.add(getSearchPanel(), "span 3, wrap, grow"); 

당신이 내부 JPanel의없이 같은 결과를 가지고 싶다면, 당신은 할 수있다 :

final JLabel lblEmission = new JLabel("Show"); 
final JTextField txtEmission = new JTextField(10); 
final JTextField txtEM = new JTextField(5); 

this.add(lblEmission, "width 2%, span 3, split 3"); 
this.add(txtEmission, "right,width 60%, growx"); 
this.add(txtEM, "width 38%, growx"); 

그러나 이것은 내가 좋아하는 해결책이 아니다. 내부 패널을 사용하면 코드가 훨씬 간단하고 재사용 할 수 있습니다. 모델과의 상호 작용을 위해 구성 요소와 컨트롤러에 대한 사용자 상호 작용을위한 일부 리스너를 추가 할 때이 코드는 지나치게 복잡해질 것이라고 생각합니다. 이 경우 SearchPanelsingle responsability의 재사용 가능한 최상위 클래스에 추출 할 수 있습니다. 간단한 내부 패널이 없으면이 클래스를 추출하는 것이 훨씬 어려울 것입니다.

내가 왜 gui를 디자인 할 때, 먼저 BorderLayout을 사용하고 (더 복잡한 패널의 경우) MigLayout을 사용하는 것을 선호합니다.

+0

의 구성 요소 제약에 대한 장을 읽고 패널없이 할 수있는 방법이 있습니까? 평소에 – redfox26

+0

, 나는 간단한 해결책을 선호합니다. 중첩 된 패널을 사용하는 것이 더 쉽습니다. 나는 성능에서 큰 차이를 찾지 못했다. 나는 몇 시간 동안 miglayout을 사용했으며, 코드를 이해하는 것은 아주 간단하지가 않습니다. – redfox26

+0

물론, 여러 개의 간단한 패널을 가지고있는 것이 복잡한 패널 하나보다 성능이 낮다고 생각하지 않습니다. – gontard