#JButton Sizing Not Working

1 messages · Page 1 of 1 (latest)

peak juniper
#

I looked everywhere for help but I feel a bit stupid right now because I can't implement what I see online into my code. The button is taking up the entire frame and I don't know what to do since I'm just a beginner, would appreciate some help please!

Will post the code in the thread

heady salmonBOT
#

<@&987246399047479336> please have a look, thanks.

heady salmonBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

peak juniper
#
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Color;
//import java.awt.Dimension;
import javax.swing.JOptionPane;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.BorderFactory;

public class MyFrame extends LoginSim{
    JButton button;
    MyFrame(){
        button = new JButton();
     
       String name = JOptionPane.showInputDialog("Enter your username please!");
     JOptionPane.showMessageDialog(null, "Welcome " + name + "!");
     
     int age = Integer.parseInt(JOptionPane.showInputDialog("Enter your age please in numbers! (Ex: 2, not two.)"));
     JOptionPane.showMessageDialog(null, "You are " + age + " years old.");
   
     JFrame frame = new JFrame(); //creates frame, needs import
     frame.setTitle("Welcome"); //sets title
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //exit out of application
     frame.setResizable(true); //frame resizing true or false
     frame.setSize(800,600); //set x dimension, and y dimension of frame
     
     frame.setVisible(true); //make frame visible
     
     frame.getContentPane().setBackground(new Color(245, 225, 225)); //change frame bg color, by rgb
     //(250, 172, 172) or (245, 225, 225) possible colors
     //button.setFont(new Font("Comic Sans"Font.BOLD,25));
   
    //button.setBounds(20,20,10,10); //(x, y, width, height)
     //button.setPreferredSize(new Dimension(50, 50));
     button.setBounds(20,20,10,10);
     button.addActionListener(e -> System.out.println("poo."));
     button.setText("Bruh");
     button.setFocusable(false);
     button.setForeground(new Color(0, 0, 0));
     button.setBackground(new Color(230, 223, 223));
     button.setHorizontalTextPosition(JButton.CENTER);
     button.setVerticalTextPosition(JButton.BOTTOM);
     button.setIconTextGap(-15);
     button.setBorder(BorderFactory.createEtchedBorder());
     button.setEnabled(true);
     
     
     frame.add(button);
     
        }
     
}
heady salmonBOT
ionic heart
#

Can you post what you are seeing?

peak juniper
brisk plume