0

I want to change the color of JInternalFrame Title bar. For this I had tried with some forum suggestions but it doesn't work. In my application Click on create menu item then it shows an internal frame. I want to change the color of that title bar.

Here is my code:

public class CreateDocs extends javax.swing.JFrame {
int i=0;
JTextPane textPane;
public CreateDocs() {
    initComponents();
}
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

    tabbedPane = new javax.swing.JTabbedPane();
    menuBar = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    create = new javax.swing.JMenuItem();

    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

    jMenu1.setText("File");

    create.setText("Create");
    create.addActionListener(new java.awt.event.ActionListener() {
        public void actionPerformed(java.awt.event.ActionEvent evt) {
            createActionPerformed(evt);
        }
    });
    jMenu1.add(create);

    menuBar.add(jMenu1);

    setJMenuBar(menuBar);

    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 410, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tabbedPane, javax.swing.GroupLayout.PREFERRED_SIZE, 410, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE)))
    );
    layout.setVerticalGroup(
        layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
        .addGap(0, 279, Short.MAX_VALUE)
        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(tabbedPane, javax.swing.GroupLayout.DEFAULT_SIZE, 279, Short.MAX_VALUE))
    );

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

private void createActionPerformed(java.awt.event.ActionEvent evt) {
   final JInternalFrame internalFrame = new JInternalFrame("");
   i++;
   UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(new Color(248,250,175)));
   UIManager.put("InternalFrame.inactiveTitleBackground", new ColorUIResource(new Color(248,250,175)));
   javax.swing.plaf.basic.BasicInternalFrameUI ui = 
   new javax.swing.plaf.basic.BasicInternalFrameUI(internalFrame); 
   internalFrame.setUI(ui);
    internalFrame.setName("Document"+i);
    internalFrame.setClosable(true);
    internalFrame.setAutoscrolls(true);
    textPane=new JTextPane();
    textPane.setFont(new java.awt.Font("Miriam Fixed", 0, 14));
    internalFrame.add(textPane);
    tabbedPane.add(internalFrame);
}

public static void main(String args[]) {
    /* 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
     */
    try {
        for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
            if ("Nimbus".equals(info.getName())) {
                javax.swing.UIManager.setLookAndFeel(info.getClassName());
                break;
            }
        }
    } catch (ClassNotFoundException ex) {
        java.util.logging.Logger.getLogger(CreateDocs.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (InstantiationException ex) {
        java.util.logging.Logger.getLogger(CreateDocs.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        java.util.logging.Logger.getLogger(CreateDocs.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    } catch (javax.swing.UnsupportedLookAndFeelException ex) {
        java.util.logging.Logger.getLogger(CreateDocs.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
    }
    //</editor-fold>

    /* Create and display the form */
    java.awt.EventQueue.invokeLater(new Runnable() {
        public void run() {
            new CreateDocs().setVisible(true);
        }
    });
}
// Variables declaration - do not modify
private javax.swing.JMenuItem create;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar menuBar;
private javax.swing.JTabbedPane tabbedPane;
// End of variables declaration

}

1 Answers1

0

Try using this one line:

internalFrame.getRootPane().setWindowDecorationStyle(5);

Use any number between 1 to 8.

bhavna garg
  • 270
  • 2
  • 19