I am learning java GUI programming and I would like to create button. Problem is when button is created it is huge. How I can resize button?
JFrame frame = new JFrame("Ikkuna <3");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel teksti = new JLabel("assdad", SwingConstants.CENTER);
teksti.setFont(new Font("Eras Demi ITC", Font.PLAIN, 32));
teksti.setForeground(Color.BLUE);//tekstin väri
ImageIcon img = new ImageIcon("C:/Users/account/Documents/NetBeansProjects/eka/src/eka/Kuvat/Trollface.PNG"); //Tämä on kuvake(icon).
frame.setIconImage(img.getImage());
JButton nappula = new JButton("Start");
frame.getContentPane().add(nappula);
nappula.setPreferredSize(new Dimension(83, 291));
nappula.setLocation(500, 350);
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
teksti.setPreferredSize(new Dimension(300, 100));
frame.getContentPane().add(teksti, BorderLayout.PAGE_START);
frame.setLocationRelativeTo(null);
frame.pack();
frame.setVisible(true);
I also tried this:
nappula.setPreferredSize(new Dimension(83, 291));
You Can set the fonts to the button and change its size
Font f = new Font("Times New Roman",Font.BOLD,20);
nappula.setFont(f);
Set it of any size change 20 to any value...... Try it....
You're using default layout from the looks of it. Try using
nappula.setSize(new Dimension(x, y));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.