#JButton Sizing Not Working
1 messages · Page 1 of 1 (latest)
<@&987246399047479336> please have a look, thanks.
While you are waiting for getting help, here are some tips to improve your experience:
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.
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);
}
}
Detected code, here are some useful tools:
Can you post what you are seeing?
I fixed it already, but thank you!
Then close Thread