2012-01-24 4 views
3

만든 대화 상자에 문제가 있습니다. 그것은 경계 제목과 입력 상자를 잘라내는 모든 것을 포장합니다. 나는 패널과 컴포넌트의 크기를 설정하려고했지만 아무 소용이 없다. 크기는 변하지 않습니다. 대화 상자의 크기를 수정할 수 있다면 도움이 될 것입니다.크기 조정 대화 상자

JTextField account = new JTextField(6); 
account.setDocument(new JTextFieldLimit(6)); 
account.setBorder(new TitledBorder("account")); 

String[] firstDigitList = {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; 
JComboBox firstDigitCombo = new JComboBox(firstDigitList); 
firstDigitCombo.setSelectedIndex(0); 
firstDigitCombo.setBorder(new TitledBorder("Leading Digit Change")); 

JPanel panel = new JPanel(); 
panel.add(account); 
panel.add(firstDigitCombo); 

int result = JOptionPane.showConfirmDialog(null, panel, "Please Enter Values", JOptionPane.OK_CANCEL_OPTION); 
+0

이 실제 코드 또는 당신은뿐만 아니라 일부의 LayoutManager 코드를하는거야? –

+0

JOptionPane을 사용하지 않는 것이 좋습니다.이 위젯은 예를 들어 몇 가지 자동 크기 조정을 수행합니다. 건네받은 캐릭터 라인 Netbeans gui 디자이너를 사용하여 좋은 결과를 얻었습니다. 귀하의 경우에는 JDialog 기반 GUI가 그 일을 할 것입니다. – boto

+0

실제 코드. 사용자가 파일을 선택하고 파일을 기반으로 jdialog가 표시됩니다. 패널에 몇 가지 다른 구성 요소가 추가되었지만 게시시 공간을 절약하기 위해 남겨 둡니다. – whitewolfpgh

답변

5

기본적인 문제는 TitledBorder가 전체 텍스트를 표시 할만큼 큰 것입니다 점에 구성 요소를 확장 할 것입니다. 대신 텍스트를 자릅니다.

해결 방법은 구성 요소가 텍스트를 표시 할만큼 충분히 큰지 확인하는 것입니다. 텍스트 필드의 크기를 확장하고 '단축'제목에 '전체 길이'레이블을 추가하여 여기에 표시했습니다.

Test Size Of Gui

import java.awt.*; 
import javax.swing.*; 
import javax.swing.border.*; 

class TestSizeOfGui { 

    public static void main(String[] args) { 
     SwingUtilities.invokeLater(new Runnable() { 
      public void run() { 
       JTextField account = new JTextField(10); 
       JPanel accountPanel = new JPanel(new GridLayout()); 
       accountPanel.add(account); 
       accountPanel.setBorder(new TitledBorder("Account")); 

       String[] firstDigitList = { 
        "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"}; 

       JLabel firstDigitListLabel = new JLabel("Leading Digit Change"); 
       JPanel firstDigitListPanel = new JPanel(new BorderLayout(4,2)); 
       firstDigitListPanel.add(firstDigitListLabel, BorderLayout.WEST); 
       JComboBox firstDigitCombo = new JComboBox(firstDigitList); 
       firstDigitListPanel.add(firstDigitCombo); 
       firstDigitCombo.setSelectedIndex(0); 
       firstDigitListPanel.setBorder(new TitledBorder("LDC")); 

       JPanel panel = new JPanel(); 
       panel.add(accountPanel); 
       panel.add(firstDigitListPanel); 

       int result = JOptionPane.showConfirmDialog(
        null, 
        panel, 
        "Please Enter Values", 
        JOptionPane.OK_CANCEL_OPTION); 

       } 
      }); 
    } 
} 
+0

점심 식사 후 앤드류 (Andrew)를 보자. – whitewolfpgh

+0

오늘 학습 항목이 +1이 되나요 ??? 기본적인 문제는 TitledBorder ??? 그래서 이상한 JPanel – mKorbel

+0

이것은 정확히 내가하고 싶은 것처럼 보입니다. JDialog를 조작하는 완전히 새로운 방법을 배웠습니다. 오 소년은 배우고 할 일이 훨씬 많습니다! 다시 한 번 감사드립니다! – whitewolfpgh

관련 문제