jframe adding own design jinternal frame error
Posted
by
Van Minh
on Stack Overflow
See other posts from Stack Overflow
or by Van Minh
Published on 2014-06-03T17:10:58Z
Indexed on
2014/06/04
3:25 UTC
Read the original article
Hit count: 234
I designed a title bar color on my JInternal frame. Then I took attempt to add it to my JFrame, but I cannot. Here is the code of my title bar:
public class MyIFtitleBar extends BasicInternalFrameTitlePane {
public MyIFtitleBar(JInternalFrame jif) {
super(jif);
}
protected void paintTitleBackground(Graphics g){
g.setColor(Color.pink);
g.fillRect(0, 0, getWidth(), getHeight());
}
}
Here is my JInternal frame. I tried running it in its psvm method, that worked!
public class FitnessProg_Frame extends javax.swing.JInternalFrame {
public FitnessProg_Frame() {
initComponents();
this.setUI(new BasicInternalFrameUI(this){
@Override
protected JComponent createNorthPane(JInternalFrame jif) {
return new MyIFtitleBar(jif);
}
});
}
@SuppressWarnings("unchecked")
private void initComponents() {
setBackground(new java.awt.Color(255, 255, 255));
setBorder(new javax.swing.border.MatteBorder(null));
setTitle("Fitness Progarm");
setPreferredSize(new java.awt.Dimension(507, 304));
pack();
}
}
But when I add it to my JFrame I get an error:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
Here is my JFrame code:
public class NewJFrame extends javax.swing.JFrame {
public NewJFrame() {
initComponents();
FitnessProg_Frame ff = new FitnessProg_Frame();
ff.setVisible(true);
mydes.add(ff); // this line made errors
}
@SuppressWarnings("unchecked")
private void initComponents() {
mydes = new javax.swing.JDesktopPane();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout mydesLayout = new javax.swing.GroupLayout(mydes);
mydes.setLayout(mydesLayout);
mydesLayout.setHorizontalGroup(
mydesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
mydesLayout.setVerticalGroup(
mydesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
getContentPane().add(mydes, java.awt.BorderLayout.CENTER);
pack();
}
public static void main(String args[]) {
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(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
private javax.swing.JDesktopPane mydes;
}
© Stack Overflow or respective owner