swing - Java Graphics and Bordering Problems in JScrollPane -


i have found customscrollbaruiexample, , trying change own (with attribution, of course, legal). have run problem.

what trying achieve put border around not jscrollpane itself, moveable block if understand meen.

i have put modified source code below, , have highlighted problem.

package com.finn.chess;  import java.awt.*; import java.awt.image.bufferedimage; import javax.swing.*; import javax.swing.plaf.metal.metalscrollbarui;  /** @see https://stackoverflow.com/a/12270067/230513 */ public class customscrollbaruiexample {  public static void main(string[] args) {     jscrollpane before = makeexamplepane();     jscrollpane after = makeexamplepane();     after.setverticalscrollbarpolicy(jscrollpane.vertical_scrollbar_always);     jscrollbar sb = after.getverticalscrollbar();     sb.setui(new myscrollbarui());     jframe f = new jframe();     f.setdefaultcloseoperation(jframe.exit_on_close);     f.setlayout(new gridlayout(0,1));     f.add(before);     f.add(after);     f.pack();     f.setsize(320, 240);     f.setvisible(true); }  private static jscrollpane makeexamplepane() {     jtextarea text = new jtextarea(16, 16);     text.append("lorem ipsum dolor sit amet…");     jscrollpane scroll = new jscrollpane(text);     return scroll; }  static class myscrollbarui extends metalscrollbarui {      private image imagethumb, imagetrack;     private jbutton b = new jbutton() {          @override         public dimension getpreferredsize() {             return new dimension(0, 0);         }      };      myscrollbarui() {         imagethumb = fauximage.create(32, 32, color.blue.brighter());         imagetrack = fauximage.create(32, 32, color.black);     }      @override     protected void paintthumb(graphics g, jcomponent c, rectangle r) {         g.setcolor(color.blue);         ((graphics2d) g).drawimage(imagethumb,             r.x, r.y, r.width, r.height, null);     }      @override     protected void painttrack(graphics g, jcomponent c, rectangle r) {         ((graphics2d) g).drawimage(imagetrack,             r.x, r.y, r.width, r.height, null);     }      @override     protected jbutton createdecreasebutton(int orientation) {         return b;     }      @override     protected jbutton createincreasebutton(int orientation) {         return b;     } }  private static class fauximage {      static public image create(int w, int h, color c) {         bufferedimage bi = new bufferedimage(             w, h, bufferedimage.type_int_argb);         graphics2d g2d = bi.creategraphics();         g2d.setpaint(c);         g2d.fillrect(0, 0, w, h);          // problem, border         g2d.setpaint(color.white);         g2d.drawrect(0, 0, w-1, h-1);          g2d.dispose();         return bi;     } } } 

just @ end, can see setup border put around it. in big sizes, appears this:

scroll bar

i don't want massive block of white down bottom; want simple, 1 pixel high border. how achieve this? posting brand new thread because other 1 2 years old, , can't add comment.

add border in paintthumb(), after image has been scaled drawimage(). starting original , using color.red emphasis, result seen below:

image

@override protected void paintthumb(graphics g, jcomponent c, rectangle r) {     g.setcolor(color.blue);     graphics2d g2d = (graphics2d) g;     g2d.drawimage(imagethumb, r.x, r.y, r.width, r.height, null);     g2d.setpaint(color.red);     g2d.drawrect(r.x, r.y, r.width - 1, r.height); } 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -