Re: titled border problem

2002-03-01 Thread Kurt Baumgarten




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
  
  
  


Memory leak in JEditorPane setText()

2002-03-01 Thread Mike Welz


I've got a kiosk-type program that displays small(1K) HTML pages repeatedly
using the JEditorPane setText() method.  The problem I have is that HTML
pages that contain 'TABLE' tags with a 'width' attribute seem to cause a
memory leak that leads to the JVM running out of memory eventually.

This happens on WinNT and Win95 using either JDK 1.2.2 or 1.3_02.

I've attached a small program that demonstrates this problem. Displaying the
TABLE without the width attribute will work indefinitely.  Using the width
attribute, memory usage goes up and up.  

Does anyone have any ideas how to get around this or alternatives to the
JEditorPane for displaying HTML?

TIA,

Mike




File:  EPTest.java


import java.lang.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class EPTest extends JFrame
{
public JEditorPane  html_pane;

public EPTest() {
html_pane = new JEditorPane();
html_pane.setContentType(text/html);
html_pane.setEditable(false);
getContentPane().add(html_pane, BorderLayout.CENTER);
setSize(400,400);
}

private static void gc() {
try {
System.gc();
Thread.currentThread().sleep(100);
System.runFinalization();
Thread.currentThread().sleep(100);
System.gc();
Thread.currentThread().sleep(100);
System.runFinalization();
Thread.currentThread().sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String [] args) {
String str1 = new String(HTML +
BODYTABLE width='100%'
+   // causes leak
//  BODYTABLE +
// works fine
TRTD colspan='2'ONE
HEADER/TD/TR +

TRTD1/TDTDApple/TD/TR +

TRTD2/TDTDOrange/TD/TR +

TRTD3/TDTDPear/TD/TR +
/TABLE/BODY +
/HTML);
EPTest eptest = new EPTest();
eptest.setVisible(true);
int loop = 0;
while (true) {
loop++;
eptest.html_pane.setText(str1);
try {
Thread.sleep(1000);
}
catch (Exception e) {
e.printStackTrace();
}
if (loop % 10 == 0) {
System.out.println(Loop:  + loop);
gc();
Runtime rt = Runtime.getRuntime();
int used = (int)(rt.totalMemory() -
rt.freeMemory());
System.out.println(Memory:  + (used /
1000) + / + 

(rt.totalMemory() / 1000) + K);
}
}
}
}
___
Advanced-swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/advanced-swing