954,554 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

can anyone tell me how to get the look and feel in my second form................

i've created a project .....in which on executing the h.java the second window3.java appears slowly as you can see that by running the below source code.............but the problem is that the second form i.e window3.java on displaying does'nt shows the noire look and feel environment as well as no noire border,minimize button, maximize button,closing button.............

can anyone tell me how to bring that all..............

Attachments project.zip (592.81KB)
Jessurider
Posting Whiz in Training
207 posts since Feb 2011
Reputation Points: 9
Solved Threads: 0
 

post the code for the initial frame creation, the setting of the look and feel (should be the same place, hopefully), as well as the code for the creation and display of the "second form".

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

first.java

package project;


import com.jtattoo.plaf.noire.NoireLookAndFeel;
import com.sun.awt.AWTUtilities;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Timer;


/**
 *
 * @author work
 */
public class first extends javax.swing.JFrame implements ActionListener {
    window3 window2 = new window3();
    int phase = 1; // demo runs a number of consecutive phases
    int count = 0, vm = 0;
    /** Creates new form h */
    public first() {
        initComponents();
    }

    public void actionPerformed(ActionEvent e) {
        
        //window2.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
        window2.getRootPane().putClientProperty(new NoireLookAndFeel(),Boolean.TRUE);
        if (vm < 50)
        {
            
            window2.setLocationRelativeTo(null);
        window2.setVisible(true);
            // called by timer 20 times per sec
            vm++;
            System.out.println("action:" + vm);
            // goes thru a number of phases, each a few seconds long
            switch (phase) {
                case 1:// fade in
                       if ((count += 2) < 100)
                       setAlpha(window2, 0.01f * count);
                       break;
                           }
        } else {
            window2.setOpacity(1);
        }
    }

    /** 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
    private void initComponents() {

        jButton1 = new javax.swing.JButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("window2"); // NOI18N

        jButton1.setText("click");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(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()
                .addGap(143, 143, 143)
                .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(152, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(146, 146, 146)
                .addComponent(jButton1)
                .addContainerGap(131, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                        

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// TODO add your handling code here:
}                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        System.out.println("MAIN:");
        new Timer(2, new first()).start();
    }
    // Variables declaration - do not modify                     
    private javax.swing.JButton jButton1;
    // End of variables declaration                   

    private void setAlpha(window3 window, float alpha) {
        // System.out.println("alpha:"+alpha);
        AWTUtilities.setWindowOpacity(window, alpha);

    }
    /*  void setShape(JFrame window, Shape shape) {
    // cover for temporary API expected to change for Java 7
    // should become window.setShape(Shape)
    AWTUtilities.setWindowShape(window, shape);
    }*/
}


window3.java

package project;

import com.jtattoo.plaf.noire.NoireLookAndFeel;
import javax.swing.JRootPane;
import javax.swing.UIManager;

/**package project;

 *
 * @author user
 */
public class window3 extends javax.swing.JFrame {

    /** Creates new form window3 */
    public window3() {
        this.setUndecorated(true);
        initComponents();
        //this.getRootPane().putClientProperty(new NoireLookAndFeel(), Boolean.TRUE);//setWindowDecorationStyle(JRootPane.FRAME);
      //  this.getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
    }

    /** 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.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new org.netbeans.lib.awtextra.AbsoluteLayout());

        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        getContentPane().add(jButton1, new org.netbeans.lib.awtextra.AbsoluteConstraints(160, 230, -1, -1));

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 18));
        jLabel1.setForeground(new java.awt.Color(255, 51, 0));
        jLabel1.setText("HI HOW ARE YOU");
        getContentPane().add(jLabel1, new org.netbeans.lib.awtextra.AbsoluteConstraints(120, 110, 217, 45));

        jLabel2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/project/gg.png"))); // NOI18N
        getContentPane().add(jLabel2, new org.netbeans.lib.awtextra.AbsoluteConstraints(0, -1, 460, 290));

        pack();
    }// </editor-fold>

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {                                         
// TODO add your handling code here:
}                                        

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {

        try {
            UIManager.setLookAndFeel(new NoireLookAndFeel());
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */

        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new window3().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    // End of variables declaration
}
Jessurider
Posting Whiz in Training
207 posts since Feb 2011
Reputation Points: 9
Solved Threads: 0
 

As far as not showing a border, etc, what does this

this.setUndecorated(true);

do?

Use JDialog (setting the parent in the constructor) rather than JFrame for the "additional" forms. Of course the "look and feel" of one frame is not automatically to a new frame, since it is a completely separate entity, and you haven't set it explicitly. JDialog (with a prent component) should take of that (and make it more correct, besides).

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

if

<strong>this.setUndecorated(true);</strong>


is removed it causes the following errors

Exception in thread "AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated
	at java.awt.Frame.setOpacity(Frame.java:960)
	at java.awt.Window$1.setOpacity(Window.java:3998)
	at com.sun.awt.AWTUtilities.setWindowOpacity(AWTUtilities.java:174)
	at project.h.setAlpha(h.java:117)
	at project.h.actionPerformed(h.java:51)
	at javax.swing.Timer.fireActionPerformed(Timer.java:312)
	at javax.swing.Timer$DoPostEvent.run(Timer.java:244)
	at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:251)
	at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:705)
	at java.awt.EventQueue.access$000(EventQueue.java:101)
	at java.awt.EventQueue$3.run(EventQueue.java:666)
	at java.awt.EventQueue$3.run(EventQueue.java:664)
	at java.security.AccessController.doPrivileged(Native Method)
	at java.security.ProtectionDomain$1.doIntersectionPrivilege(ProtectionDomain.java:76)
	at java.awt.EventQueue.dispatchEvent(EventQueue.java:675)
	at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:211)
	at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:128)
	at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:117)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:113)
	at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:105)
	at java.awt.EventDispatchThread.run(EventDispatchThread.java:90)
MAIN:
action:1
Jessurider
Posting Whiz in Training
207 posts since Feb 2011
Reputation Points: 9
Solved Threads: 0
 

Okay? And the rest of my previous post?

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

sir.........u mean that i should substitute jdialog instead of jframe..............

Jessurider
Posting Whiz in Training
207 posts since Feb 2011
Reputation Points: 9
Solved Threads: 0
 

Yes. That is what I said, isn't it? And check the constructors for JDialog (see the API docs, of course) so that you can properly define your constructors and properly set the "parent".

masijade
Industrious Poster
Moderator
4,253 posts since Feb 2006
Reputation Points: 1,471
Solved Threads: 494
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You