@@ -230,24 +230,24 @@ public TitledBorder(Border border,
230230 * @param height the height of the painted border
231231 */
232232 @ Override
233- public void paintBorder (Component c , Graphics g , int x , int y , int width , int height ) {
233+ public void paintBorder (Component c , Graphics g0 , int x , int y , int width , int height ) {
234234
235- Border border = getBorder ();
235+ Border border = getBorder ();
236236
237237 if (getTitle () == null || getTitle ().equals ("" )) {
238238 if (border != null ) {
239- border .paintBorder (c , g , x , y , width , height );
239+ border .paintBorder (c , g0 , x , y , width , height );
240240 }
241241 return ;
242242 }
243243
244244 Rectangle grooveRect = new Rectangle (x + EDGE_SPACING , y + EDGE_SPACING ,
245245 width - (EDGE_SPACING * 2 ),
246246 height - (EDGE_SPACING * 2 ));
247- Font font = g .getFont ();
248- Color color = g .getColor ();
247+ Font font = g0 .getFont ();
248+ Color color = g0 .getColor ();
249249
250- g .setFont (getFont (c ));
250+ g0 .setFont (getFont (c ));
251251
252252 //JComponent jc = (JComponent)c;
253253 FontMetrics fm = getFont (c ).getFontMetrics ();
@@ -340,6 +340,8 @@ else if(justification==TRAILING) {
340340 // to show through the title.
341341 //
342342 if (border != null ) {
343+ Rectangle clip0 = g0 .getClipBounds ();
344+
343345 if (((titlePos == TOP || titlePos == DEFAULT_POSITION ) &&
344346 (grooveRect .y > textLoc .y - ascent )) ||
345347 (titlePos == BOTTOM &&
@@ -348,72 +350,71 @@ else if(justification==TRAILING) {
348350 Rectangle clipRect = new Rectangle ();
349351
350352 // save original clip
351- Rectangle saveClip = g .getClipBounds ();
353+ //Rectangle saveClip = g.getClipBounds();
354+
355+ //JSGraphics2D cg = (JSGraphics2D) (Object) g;
356+ //int pt = cg.mark();
352357
353- JSGraphics2D cg = (JSGraphics2D ) (Object ) g ;
354- int pt = cg .mark ();
355358 // paint strip left of text
356- clipRect .setBounds (saveClip );
359+ clipRect .setBounds (clip0 );
357360 if (computeIntersection (clipRect , x , y , textLoc .x -1 -x , height )) {
361+ Graphics g = g0 .create ();
358362 g .setClip (clipRect );
359363 border .paintBorder (c , g , grooveRect .x , grooveRect .y ,
360364 grooveRect .width , grooveRect .height );
361- cg .reset (pt );
362- cg .mark ();
365+ g .dispose ();
363366 }
364367
365368 // paint strip right of text
366- clipRect .setBounds (saveClip );
369+ clipRect .setBounds (clip0 );
367370 if (computeIntersection (clipRect , textLoc .x +stringWidth +1 , y ,
368371 x +width -(textLoc .x +stringWidth +1 ), height )) {
372+ Graphics g = g0 .create ();
369373 g .setClip (clipRect );
370374 border .paintBorder (c , g , grooveRect .x , grooveRect .y ,
371375 grooveRect .width , grooveRect .height );
372- cg .reset (pt );
373- cg .mark ();
376+ g .dispose ();
374377 }
375378
376379 if (titlePos == TOP || titlePos == DEFAULT_POSITION ) {
377380 // paint strip below text
378- clipRect .setBounds (saveClip );
381+ clipRect .setBounds (clip0 );
379382 if (computeIntersection (clipRect , textLoc .x -1 , textLoc .y +descent ,
380383 stringWidth +2 , y +height -textLoc .y -descent )) {
384+ Graphics g = g0 .create ();
381385 g .setClip (clipRect );
382386 border .paintBorder (c , g , grooveRect .x , grooveRect .y ,
383387 grooveRect .width , grooveRect .height );
384- cg .reset (pt );
385- cg .mark ();
388+ g .dispose ();
386389 }
387390
388391 } else { // titlePos == BOTTOM
389392 // paint strip above text
390- clipRect .setBounds (saveClip );
393+ clipRect .setBounds (clip0 );
391394 if (computeIntersection (clipRect , textLoc .x -1 , y ,
392395 stringWidth +2 , textLoc .y - ascent - y )) {
396+ Graphics g = g0 .create ();
393397 g .setClip (clipRect );
394398 border .paintBorder (c , g , grooveRect .x , grooveRect .y ,
395399 grooveRect .width , grooveRect .height );
396- cg .reset (pt );
397- cg .mark ();
400+ g .dispose ();
398401 }
399402 }
400403
401404 // restore clip
402- g .setClip (saveClip );
403- cg .reset (pt );
405+ // g.setClip(saveClip);
404406
405407 } else {
406- border .paintBorder (c , g , grooveRect .x , grooveRect .y ,
408+ border .paintBorder (c , g0 , grooveRect .x , grooveRect .y ,
407409 grooveRect .width , grooveRect .height );
408410 }
409411 }
410412
411- g .setColor (getTitleColor ());
413+ g0 .setColor (getTitleColor ());
412414 //SwingUtilities2.drawString(jc, g, getTitle(), textLoc.x, textLoc.y);
413- g .drawString (getTitle (), textLoc .x , textLoc .y );
414-
415- g .setFont (font );
416- g .setColor (color );
415+ g0 .drawString (getTitle (), textLoc .x , textLoc .y );
416+ g0 .setFont (font );
417+ g0 .setColor (color );
417418 }
418419
419420 /**
0 commit comments