#How to get the default system button in swing?
31 messages · Page 1 of 1 (latest)
⌛ This post has been reserved for your question.
Hey @violet tapir! Please use
/closeor theClose Postbutton above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.
Your would use UIManager to change the look and feel of your application. More specifally, it would look like this:
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());```
You will need to catch like four different exceptions, but after that it should work
If you are on windows, the System buttons do not support coloring I believe
Get rid of the setBackground()
Is it possible?
I'll try
And can I get rid of the annoying square in the middle of the button?
yes
, do setFocusPainted(false);
Oh, another thing, Make sure you are setting the look and feel before you add the buttons, or any other swing component for that matter
OMG I'm feeling like an Idiot
Did that work?
YES
great
package com.eitan07.crackme.windows;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
public class MainWindow implements ActionListener {
JFrame frame;
JPanel panel;
JButton button;
JLabel lbl1;
JLabel lbl2;
public MainWindow() throws UnsupportedLookAndFeelException, ClassNotFoundException, InstantiationException, IllegalAccessException {
frame = new JFrame();
panel = new JPanel();
button = new JButton();
button.setText("CLICK ME!!");
button.setFocusPainted(false);
button.setEnabled(true);
button.addActionListener(this);
panel.add(button);
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
frame.add(panel);
frame.setTitle("CRACKME");
frame.setResizable(false);
frame.setSize(150, 300);
frame.setVisible(true);
}
@Override
public void actionPerformed(ActionEvent e) {
if (e.getSource() == button) {
System.exit(0);
}
}
}
``` This is what my code looked like
I added the component before changing the FAL
I see
I've done that before for sure
If your problem is fixed, you should do /close
Tada!
nicee
Sure man
Thanks a lot!!!
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.