How to set Java LookAndFeel to default WindowsLookAndFeel

How to set Java LookAndFeel to default WindowsLookAndFeel

How to set Java LookAndFeel to default WindowsLookAndFeel
My previous post-JOptionPane showMessageDialog I used UIManager to set swing components to default Windows LookAndFeel.

Today am going into details to explain how UIManager works


How to setLookAndFeel in java

Open your IDE and run below code.

[
import javax.swing.JFrame;
import javax.swing.JTextField;

import javax.swing.JTextArea;
import javax.swing.JButton;
import java.awt.Dimension;
import javax.swing.UIManager;

import java.awt.FlowLayout;

public class SetJavaLookAndFeel extends JFrame {
    public JButton button;
    public JTextField name,email;
    public JTextArea area;


    public SetJavaLookAndFeel()
    {
        super("Setting Java LookAndFeel");
        this.setPreferredSize(new Dimension(600,200));
        this.setLocationRelativeTo(null);
        this.setLayout(new FlowLayout(FlowLayout.RIGHT));
        try        {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
        }

        catch(Exception e)
        {
            e.printStackTrace();
        }


        name=new JTextField("Enter your name");
        name.setToolTipText("Your firstname or secondname");

        email=new JTextField("Enter your email");
        email.setToolTipText("Your email");
        area=new JTextArea("Enter your message");
        area.setToolTipText("Message to send ");

        button=new JButton("Send");


        add(name);
        add(email);
        add(area);
        add(button);
        pack();
        setVisible(true);

    }


    public static void main(String args[])
    {
        new SetJavaLookAndFeel();
    }

}
]
Result of above Code:

Java LookAndFeel Code Explanation:

This program has graphical User interface that allows user to interact with the program when feeding program with inputs.

Some of the swing components used in this program are

  • JTextField
  • JTextArea
  • JButton
To add  ActionListener to JButton read here.

These are but a few swing components that are used to get user input.To Make the look like other programs that are running on windows we use UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel").

Other new methods in this program are.

  • new Dimension(int i,int j)-this method takes two int variables.Used to create a dimension like rectangle or square
  • setPreferredSize()-Its used to set the size of JFrame Window
  • add(swing component eg button)-this method is used to add swing components to JFrame window.
  •  setLocationRelativeTo()-positions JFrame window at the center of the screen.
  • setLayout()-used to set default JFrame window.
  • pack()-used when using layout managers and you want all the fit JFrame window.Incase you have setSize of JFrame Window not need of using pack() method.
  • setVisible(boolean)-makes JFrame Window visible to the screeen.


COMMENTS

Name

android android Apps android emulators antivirus blogger bluestack Break Statement in Java constructors download downloader drivers emulators java java control statements java do-while loop java for loop java infinitive do-while loop java system methods java tutorials Java While Loop java.awt java.swing javalookandfeel javascript JButton JCheckBox JColorChooser JComboBox JDialog JFileChooser JFrame JLayeredPane JList JMenuBar joomla JOptionPane JPanel JPasswordField JPopupMenu JProgressBar JRadioButton JScrollBar JSlider JSpinner JTabbedPane JTable JTextArea JTextField JToolBar mysql php plugins Polymorphism setToolTiptext skype for windows software swing class themes Visual Studio Code WeChat whatsapp wordpress
false
ltr
item
Java Codes: How to set Java LookAndFeel to default WindowsLookAndFeel
How to set Java LookAndFeel to default WindowsLookAndFeel
How to set Java LookAndFeel to default WindowsLookAndFeel
https://2.bp.blogspot.com/-NPhdWfV-SkM/WJyB-G5w6yI/AAAAAAAAG2A/rickh7tJRY8k9BNi4_8C6W5O0lQvC9K0ACLcB/s200/how-to-set-java-windows-lookandfeel-min.PNG
https://2.bp.blogspot.com/-NPhdWfV-SkM/WJyB-G5w6yI/AAAAAAAAG2A/rickh7tJRY8k9BNi4_8C6W5O0lQvC9K0ACLcB/s72-c/how-to-set-java-windows-lookandfeel-min.PNG
Java Codes
http://www.download-all.net/2017/02/how-to-set-java-lookandfeel-to-default.html
http://www.download-all.net/
http://www.download-all.net/
http://www.download-all.net/2017/02/how-to-set-java-lookandfeel-to-default.html
true
7826648292785071009
UTF-8
Not found any posts VIEW ALL Readmore Reply Cancel reply Delete By Home PAGES POSTS View All RECOMMENDED FOR YOU LABEL ARCHIVE SEARCH ALL POSTS Not found any post match with your request Back Home Sunday Monday Tuesday Wednesday Thursday Friday Saturday Sun Mon Tue Wed Thu Fri Sat January February March April May June July August September October November December Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec just now 1 minute ago $$1$$ minutes ago 1 hour ago $$1$$ hours ago Yesterday $$1$$ days ago $$1$$ weeks ago more than 5 weeks ago Followers Follow THIS CONTENT IS PREMIUM Please share to unlock Copy All Code Select All Code All codes were copied to your clipboard Can not copy the codes / texts, please press [CTRL]+[C] (or CMD+C with Mac) to copy