Overriding updateUI() ?
If I extend a JPanel and override updateUI() I get a null pointer exception?
Exception in thread"AWT-EventQueue-0" java.lang.NullPointerException
at ExtendedPanel.updateUI(Example.java:17)
at javax.swing.JPanel.<init>(JPanel.java:64)
at javax.swing.JPanel.<init>(JPanel.java:87)
at javax.swing.JPanel.<init>(JPanel.java:95)
at ExtendedPanel.<init>(Example.java:10)
at Example$1.run(Example.java:37)
at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
class ExtendedPanelextends JPanel
{
protected JLabel l;
public ExtendedPanel()
{
super();
this.l =new JLabel("Whatever");
this.add(this.l);
}
publicvoid updateUI()
{
this.l.setText("Updated");
super.updateUI();
}
}
Am I doing something wrong? :)
[1865 byte] By [
d11wtqa] at [2007-11-26 17:48:45]

# 6
Can I just double check I understood you? :)
class ExtendedPanel extends JPanel
{
protected JLabel l;
public ExtendedPanel()
{
super();
this.l = new JLabel("Whatever");
this.add(this.l);
}
public void paintComponent(Graphics g)
{
this.l.setText("Updated");
super.paintComponent(g);
}
}
This works as I want (obviously that code is purely for demonstration!) but have a gone a round-about way of doing it?
# 7
I don't really understand what you are doing.
The updateUI() method is invoked when a component is created or when a LAF change is made, so basically it should only ever be invoked once in a normal application.
The paintComponent() method is invoked whenever the Swing PaintManager determines that a component needs to be repainted, (ie. if you minimize then restore the frame), so it will be invoked multiple times in the life of the application.
I have no idea why you are trying to set the value of a label in either of those methods.
# 8
LOL... I'm not. It's just me being an idiot and giving a **** example.
See this calendar: http://www.w3style.co.uk/~d11wtq/calendar_demo.png
When you change the month in the JComboBox the grid needs updating. Currently I can fire all that myself. However, I've given the ability for the developer using the date picker to manually change the values in the Calendar object (java.util.Calendar). In which case, the table does not know it needs repainting. There are a few things that need to be done before it will repaint successfully (although I'm looking at improving the code to avoid these "few things") so I wanted to run a few methods before calling the super class' usual painting operations.
I think I may be able to avoid having to do all this anyway by refactoring the code which sets the values in the table :)