2017-06-30 6 views
0

無知にごめんなさい、私は初心者です。 JFileChooserのサイズを変更しようとしていますので、画面解像度のサイズになります。私は次のコードを使用し、解像度を取得するには:リサイズJFileChooser

GraphicsDevice gd = GraphicsEnvironment 
     .getLocalGraphicsEnvironment().getDefaultScreenDevice(); 
int width = gd.getDisplayMode().getWidth(); 
int height = gd.getDisplayMode().getHeight(); 

を私が検索しましたが、私は効果的JFileChooserのサイズを変更する方法を見つけることができませんでした。私が見つけた解決策をいくつか試しましたが、うまくいきませんでした。

+0

'JFrameを検討してください。 MAXIMIZED_BOTH'; 'JFileChooser'を' GridLayout'を持つパネルに追加してください。 – trashgod

答えて

0

この(コメントに注意してください)してみてください。他のコンポーネントは、フレームに追加する必要がない場合は、フレーム(推奨されません)に直接ファイルチューを追加することができます

import java.awt.BorderLayout; 

import javax.swing.JFileChooser; 
import javax.swing.JFrame; 
import javax.swing.JPanel; 

public class FileChooserFrame extends JFrame { 

    public FileChooserFrame() {//construct a JFrame 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); //maximize to full screen 

     //constract japnel. apply a border layout manager to it 
     JPanel mainPanel = new JPanel(new BorderLayout()); 
     add(mainPanel); //add panel to frame 

     JFileChooser fc = new JFileChooser(); //construct file chooser 
     mainPanel.add(fc, BorderLayout.CENTER); //add it to panel 
     setVisible(true); 
    } 

    public static void main(String[] args) { 

     new FileChooserFrame(); 
    } 
} 


を:

public FileChooserFrame() {//construct a JFrame 
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
    setExtendedState(getExtendedState() | JFrame.MAXIMIZED_BOTH); //maximize to full screen 
    JFileChooser fc = new JFileChooser(); //construct file chooser 
    add(fc); //add file chooser to frame 
    setVisible(true); 
}