According to the JavaSoft Swing tutorial, 

"When you invoke the setText method on a component, for example, the
component should automatically repaint itself and, if appropriate,
resize itself. If it doesn't, it's a bug."

I would think that would apply to "setTitle" also, but perhaps not.

The tutorial also says of paintBorder:

"paintBorder -- Tells the component's border (if any) to paint. Do not
invoke or override this method."

(This is in the "Working with Graphics" section.)

If you absolutely have to avoid painting the JPanel, you
could try calling repaint(int,int,int,int), which defines a clipping
area for the repaint operation.   Not sure how you'd get the width
and height of the Border, since it doesn't inherit from JComponent.
Maybe getBorderInsets?

--Kurt 

--- In [EMAIL PROTECTED], Jaspreet Singh <[EMAIL PROTECTED]> wrote:
> Hi
> 	I am facing a problem that after changing the title of a titled
> border on a swing panel i am not being able to call the border's
> paintBorder(...) function correctly. the border is on the panel and
> panel.repaint() works perfectly fine but since i am just changing
the title
> of the border i don't want to repaint the whole panel. the problem
is that
> the graphics object being passed is null. i don't even know if i'm
calling
> the function correctly ! i am getting a NullPointerException. 
> 
> i am calling the function as:
> 
> myBorder.paintBorder(panel, panel.getGraphics(),  0, 0,
panel.getWidth(),
> panel.getHeight());	// myBorder is attached to panel
> 
> and the stack trace is:
> 
> Exception occurred during event dispatching: 
> java.lang.NullPointerException 	
> at java.awt.Rectangle.setBounds(Rectangle.java:251) 	
> at javax.swing.border.TitledBorder.paintBorder(T
itledBorder.java:329) 	
> at myui.MyPanel$1.valueChanged(MyPanel.java:50) 	
> at
>
javax.swing.DefaultListSelectionModel.fireValueCha
nged(DefaultListSelectionM
> odel.java:170) 	
> at
>
javax.swing.DefaultListSelectionModel.fireValueCha
nged(DefaultListSelectionM
> odel.java:140) 	
> at
>
javax.swing.DefaultListSelectionModel.setValueIsAd
justing(DefaultListSelecti
> onModel.java:507) 	
> at
>
javax.swing.plaf.basic.BasicTableUI$MouseInputHand
ler.setValueIsAdjusting(Ba
> sicTableUI.java:443) 	
> at
>
javax.swing.plaf.basic.BasicTableUI$MouseInputHand
ler.mouseReleased(BasicTab
> leUI.java:486) 
> at
java.awt.AWTEventMulticaster.mouseReleased(AWTEven
tMulticaster.java:231)
> 
> at java.awt.Component.processMouseEvent(Component.java:3717) 	
> at java.awt.Component.processEvent(Component.java:3546) 	
> at java.awt.Container.processEvent(Container.java:1164) 	
> at java.awt.Component.dispatchEventImpl(Component.java:2595) 	
> at java.awt.Container.dispatchEventImpl(Container.java:1213) 	
> at java.awt.Component.dispatchEvent(Component.java:2499) 	
> at
java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:2451)
> 
> at java.awt.LightweightDispatcher.processMouseEv
ent(Container.java:2216)
> 
> at java.awt.LightweightDispatcher.dispatchEvent(
Container.java:2125) 	
> at java.awt.Container.dispatchEventImpl(Container.java:1200) 	
> at java.awt.Window.dispatchEventImpl(Window.java:912) 	
> at java.awt.Component.dispatchEvent(Component.java:2499) 	
> at java.awt.EventQueue.dispatchEvent(EventQueue.java:319) 	
> at
java.awt.EventDispatchThread.pumpOneEvent(EventDis
patchThread.java:103)
> 
> at java.awt.EventDispatchThread.pumpEvents(Event
DispatchThread.java:93)
> 
> at java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
> 
> is there any way i can call this function successfully? or will i
have to
> use panel.repaint()?
> 
> thanks in advance,
> jassi

Reply via email to