2017-08-26 7 views
1

ボタンサイズがJLabelbackgroundBoxLayoutamico.setPreferredSize(new Dimension(320, 240));で増加しない理由はわかりませんが、問題は何ですか?ボタンサイズが変更されない

public class JavaApplication30 extends JFrame 
{ 
    private final JButton amico; 
    private final JButton bello; 
    private final JButton compagno; 

    public JavaApplication30(File imageFile) 
    { 
     JLabel background = new JLabel(new ImageIcon(imageFile.getAbsolutePath())); 
     add(background); 
     background.setLayout(new BoxLayout(background, BoxLayout.Y_AXIS)); 
     amico=new JButton("Amico"); 
     amico.setPreferredSize(new Dimension(320, 240)); 
     bello=new JButton("Bello"); 
     compagno=new JButton("Compagno"); 
     background.add(Box.createRigidArea(new Dimension(0,100))); 
     background.add(amico); 
     background.add(Box.createRigidArea(new Dimension(0,30))); 
     background.add(bello); 
     background.add(Box.createRigidArea(new Dimension(0,30))); 
     background.add(compagno); 

     setTitle("Prova"); 
     pack(); 
     setLocationRelativeTo(null); 
     setDefaultCloseOperation(EXIT_ON_CLOSE); 
    } 

    public static void main(String[] args) throws IOException 
    { 
     SwingUtilities.invokeLater(new Runnable() 
     { 
      @Override 
      public void run() 
      { 
       String filepath = "C:\\Users\\user\\Documents\\NetBeansProjects\\JavaApplication29\\src\\eila.jpg"; 
       File imageFile = new File(filepath); 
       JavaApplication30 frame = new JavaApplication30(imageFile); 
       frame.setVisible(true); 
      } 
     }); 
    } 
} 
+1

* amico.setPreferredSize(新しい次元(320,240));「問題は何ですか?何らかのエラーが発生しますか? – nullpointer

+0

@nullpointerエラーなし、BUILD SUCCESSFUL – carelli99

答えて

0

は次やろうでした:それは役立つはず

amico = new JButton("Amico") { 
    { 
      setSize(new Dimension(320, 240)); 
      setMaximumSize(getSize()); 
    } 
}; 

あなた

コードをありがとうございます。がんばろう。

関連する問題