Results 1 to 9 of 9
  1. #1
    linux1man's Avatar
    linux1man is offline Member
    Join Date
    Nov 2008
    Posts
    39
    Rep Power
    0

    Question [SOLVED] Changing the look of butons in program

    Hi everybody!

    I made a simple number generator (just to mess around with Swing) but when I run the program it does not look like my system theme it looks bluish. I know that this is the default, but is there any way to change it from netbeans (in the graphical window were you drag & drop buttons, etc...) or in the code itself?

    PS
    I am running Linux Ubuntu 8.04
    i have uploaded the screen shot of my current program
    But if you know the way to do it on Windows, it's fine too.
    Attached Thumbnails Attached Thumbnails [SOLVED] Changing the look of butons in program-screenshot.jpg  
    -- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
    -- 2.66 Ghz Pentium Geforce NVidia 440 64mb

  2. #2
    linux1man's Avatar
    linux1man is offline Member
    Join Date
    Nov 2008
    Posts
    39
    Rep Power
    0

    Default

    BTW this is my code:
    Java Code:
    import java.util.Random; 
    
    public class Generator extends javax.swing.JFrame {
        
        /** Creates new form Generator */
        public Generator() {
            initComponents();
        }
        
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            jPanel1 = new javax.swing.JPanel();
            jTextField1 = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            jButton3 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setResizable(false);
    
            jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Lottery Generator"));
    
            jButton1.setText("Generate!");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton1ActionPerformed(evt);
                }
            });
    
            jButton3.setText("Clear");
            jButton3.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton3ActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel1Layout.createSequentialGroup()
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addGap(99, 99, 99)
                            .addComponent(jButton1)
                            .addGap(18, 18, 18)
                            .addComponent(jButton3, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel1Layout.createSequentialGroup()
                            .addContainerGap()
                            .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 345, Short.MAX_VALUE)))
                    .addContainerGap())
            );
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                    .addGap(40, 40, 40)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 38, Short.MAX_VALUE)
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton1)
                        .addComponent(jButton3))
                    .addContainerGap())
            );
    
            jButton2.setText("Exit");
            jButton2.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButton2ActionPerformed(evt);
                }
            });
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButton2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jButton2)
                    .addContainerGap())
            );
    
            pack();
        }// </editor-fold>                        
    
        private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            System.exit(0);
        }                                        
    
        private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            String ans = "";
            int numbers[] = new int[5];
            int power;
            Random rand = new Random();
            for(int i = 0; i < 5; i++)         
            {
                numbers[i] = (rand.nextInt(58)+1);
                ans += (numbers[i] + "-");
            }
            power = (rand.nextInt(38)+1);
            ans += power;         
            jTextField1.setText(ans);
        }                                        
    
        private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {                                         
            jTextField1.setText("");
        }                                        
        
        /**
         * @param args the command line arguments
         */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new Generator().setVisible(true);
                }
            });
        }
        
        // Variables declaration - do not modify                     
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JButton jButton3;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration                   
        
    }
    -- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
    -- 2.66 Ghz Pentium Geforce NVidia 440 64mb

  3. #3
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

    Default

    try
    Java Code:
    try
    		{
    			UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    		}
    		catch (Exception evt)
    		{
    			evt.printStackTrace();
    		}

  4. #4
    linux1man's Avatar
    linux1man is offline Member
    Join Date
    Nov 2008
    Posts
    39
    Rep Power
    0

    Default

    Can you tell me exactly where would you paste this
    -- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
    -- 2.66 Ghz Pentium Geforce NVidia 440 64mb

  5. #5
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,453
    Rep Power
    20

    Default

    Before constructing any Swing components. Typically, at the top of the main(...) method before the SwingUtilities.invokeLater call to launch the GUI on the EDT.

    db

  6. #6
    linux1man's Avatar
    linux1man is offline Member
    Join Date
    Nov 2008
    Posts
    39
    Rep Power
    0

    Default

    it says it can not find symbol variable UAManager
    Java Code:
    public static void main(String args[]) 
        {
            try
                {
                        UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                }
                catch (Exception evt)
                {
                        evt.printStackTrace();
                }
            java.awt.EventQueue.invokeLater(new Runnable() 
            {
                public void run() 
                {
                    new ConverterGUI().setVisible(true);
                }
            });
        }
    :confused:
    -- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
    -- 2.66 Ghz Pentium Geforce NVidia 440 64mb

  7. #7
    mtyoung is offline Senior Member
    Join Date
    Dec 2008
    Location
    Hong Kong
    Posts
    473
    Rep Power
    6

  8. #8
    linux1man's Avatar
    linux1man is offline Member
    Join Date
    Nov 2008
    Posts
    39
    Rep Power
    0

    Default

    Nope, thanks!!!
    -- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
    -- 2.66 Ghz Pentium Geforce NVidia 440 64mb

  9. #9
    linux1man's Avatar
    linux1man is offline Member
    Join Date
    Nov 2008
    Posts
    39
    Rep Power
    0

    Default

    It works!!!!!!!!!!! Thanks for the help!!
    -- Ubuntu 8.04 (Linux) O.P.S. 512mb RAM
    -- 2.66 Ghz Pentium Geforce NVidia 440 64mb

Similar Threads

  1. its not changing bgcolor
    By javanoobita in forum Java Applets
    Replies: 1
    Last Post: 02-21-2009, 03:29 PM
  2. Changing the Jframe
    By Nemo1959 in forum New To Java
    Replies: 13
    Last Post: 09-19-2008, 04:58 PM
  3. Changing Active Window
    By jmHoekst in forum New To Java
    Replies: 1
    Last Post: 06-14-2008, 01:21 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •