я провел большую часть своего времени, пытаясь имитировать дизайн на основе (как мне очень нравится), как показано на кнопку here:Rich JButton без использования изображений
Я борюсь с созданием границ Jbutton округлил, а также добавил тень к кнопкам. Я нашел способ делать округленные границы, но фон JButton, но он не остается в этом.
public class LoginView {
private Component mainPanel;
public static void main(String[] args){
JFrame frame = new JFrame("Sign In to eVenture Books");
frame.setSize(350, 200);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
frame.add(panel);
placeComponents(panel);
frame.setVisible(true);
}//End of Main()
private static class RoundedBorder implements Border {
private int radius;
RoundedBorder(int radius) {
this.radius = radius;
}
public Insets getBorderInsets(Component c) {
return new Insets(this.radius+1, this.radius+1, this.radius+1, this.radius+1);
}
public boolean isBorderOpaque() {
return true;
}
public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
g.drawRoundRect(x, y, width-1, height-1, radius, radius);
}
}//End of Class RoundedBorder
private static void placeComponents(JPanel panel) {
panel.setLayout(null);
JLabel userLabel = new JLabel("Username :");
userLabel.setBounds(10, 10, 80, 25);
panel.add(userLabel);
JTextField userText = new JTextField(20);
userText.setBounds(100, 10, 160, 25);
panel.add(userText);
JLabel passwordLabel = new JLabel("Password :");
passwordLabel.setBounds(10, 40, 80, 25);
panel.add(passwordLabel);
JPasswordField passwordText = new JPasswordField(20);
passwordText.setBounds(100, 40, 160, 25);
panel.add(passwordText);
JButton loginButton = new JButton("LOGIN");
loginButton.setBounds(10, 80, 80, 25);
loginButton.setBackground(new Color(0xF06292));
//loginButton.setBorder(new RoundedBorder(5));
loginButton.setMargin(new Insets(0, 0, 0, 0));
loginButton.setFont(new Font("Arial", Font.PLAIN, 15));
//loginButton.setForeground(new Color(0xFAFAFA));
//loginButton.setBorderPainted(false);
panel.add(loginButton);
JButton registerButton = new JButton("Register");
registerButton.setBounds(180, 80, 80, 25);
registerButton.setBackground(new Color(0xF06292));
registerButton.setBorder(new RoundedBorder(5));
panel.add(registerButton);
JButton quitButton = new JButton("Quit");
quitButton.setBounds(95, 80, 80, 25);
quitButton.setBackground(new Color(0x757575));
//quitButton.setBorder(BorderFactory.createSoftBevelBorder(BevelBorder.RAISED));
//quitButton.setBorder(new RoundedBorder(5));
// quitButton.setOpaque(false);
panel.add(quitButton);
JLabel titleLabel = new JLabel("Sign in to eVenture Books");
titleLabel.setBounds(10, 120, 200, 25);
titleLabel.setFont(new java.awt.Font("Freestyle Script", 1, 18));
titleLabel.setText("Sign In to eVenture Books");
panel.add(titleLabel);
}
}
Спасибо за ответ Я изучаю это! Я также слышал, что могу многого добиться с помощью JavaFX, но я не могу найти нигде больше информации о нем. –