2017-07-08 9 views
0

私は、境界線がテキスト領域の内側ではなくテキスト領域の周りにあるようにしたいと思います。 enter image description here境界線の位置を正確に指定する方法を教えてください。

/** 
    This frame shows a data set and its statistics. 
*/ 
public class FileGUI extends JFrame 
{ 

    private static JPanel panel; 
    private JTextArea display; 
    private JButton open; 
    private JButton save; 
    private JButton clear; 


    //declare data fields here (GUI Components and other data fields) 


    public FileGUI() 
    {  

     //Initialize data fields and construct GUI 

     open = new JButton("Open file"); 
     save = new JButton("Save to File"); 
     clear = new JButton("Clear Display"); 

     display = new JTextArea(30,30); 
     Border border = BorderFactory.createTitledBorder("File Summary"); 
     display.setBorder(border); 



     panel = new JPanel(); 
     panel.add(open); 
     panel.add(save); 
     panel.add(clear); 
     panel.add(display); 
    } 

    //supporting methods here. 


    public static void main(String[] args) 
    {  
     JFrame frame = new FileGUI(); 
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     frame.setSize(400, 600); 
     frame.setVisible(true); 
     frame.add(panel); 
    } 
} 

答えて

0

あなたは国境があなたのテキストフィールドを囲むしたい場合は、別のコンポーネント(例えばJPanelの)にそれをラップし、そのコンポーネントに境界線を設定する必要があります。枠線は、割り当てられたコンポーネントの範囲内で常にレンダリングされます。

ところで、メインスレッドからスイングコンポーネントを作成して初期化しています。これは良い方法ではありません。スイングはシングルスレッドのGUIであり、イベントディスパッチスレッドですべてのやりとりが発生する必要があります。私はこの推奨をお勧めします。concurrency in swing lesson

関連する問題