#How to get the default system button in swing?

31 messages · Page 1 of 1 (latest)

violet tapir
#

I want the buttons in my app to look like the windows default ones.
Can someone help?

lapis doveBOT
#

This post has been reserved for your question.

Hey @violet tapir! Please use /close or the Close Post button 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.

supple arrow
#

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

violet tapir
#

It looks like this now

#

I want them to look like those

supple arrow
#

If you are on windows, the System buttons do not support coloring I believe

#

Get rid of the setBackground()

violet tapir
#

I'll try

#

And can I get rid of the annoying square in the middle of the button?

supple arrow
#

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

violet tapir
#

OMG I'm feeling like an Idiot

supple arrow
#

Did that work?

violet tapir
#

YES

supple arrow
#

great

violet tapir
#
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

supple arrow
#

I see

#

I've done that before for sure

#

If your problem is fixed, you should do /close

violet tapir
supple arrow
#

nicee

violet tapir
#

Thanks a lot!!!

lapis doveBOT
# violet tapir 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.

violet tapir
#

Got bless you

#

?