Advertisement
MoonlightOwl

ScrollBar UI by Totoro

Mar 5th, 2015
316
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.50 KB | None | 0 0
  1. package net.launcher.components;
  2.  
  3. import net.launcher.theme.LoginTheme;
  4.  
  5. import javax.swing.*;
  6. import javax.swing.plaf.basic.BasicScrollBarUI;
  7. import java.awt.*;
  8.  
  9.  
  10. /**
  11.  * Created by Totoro on 3/3/2015.
  12.  * New UI for news browser scrollbar
  13.  */
  14.  
  15. public class ScrollBarUI extends BasicScrollBarUI {
  16.     @Override
  17.     protected void installDefaults()
  18.     {
  19.         super.installDefaults();
  20.         LookAndFeel.installProperty(scrollbar, "opaque", Boolean.FALSE);
  21.         thumbColor = LoginTheme.scrollBarColor;
  22.         thumbHighlightColor = thumbColor.brighter();
  23.         thumbDarkShadowColor = thumbColor.darker();
  24.     }
  25.  
  26.     @Override
  27.     protected void installComponents(){
  28.         switch (scrollbar.getOrientation()) {
  29.             case JScrollBar.VERTICAL:
  30.                 incrButton = createIncreaseButton(SOUTH);
  31.                 decrButton = createDecreaseButton(NORTH);
  32.                 break;
  33.  
  34.             case JScrollBar.HORIZONTAL:
  35.                 if (scrollbar.getComponentOrientation().isLeftToRight()) {
  36.                     incrButton = createIncreaseButton(EAST);
  37.                     decrButton = createDecreaseButton(WEST);
  38.                 } else {
  39.                     incrButton = createIncreaseButton(WEST);
  40.                     decrButton = createDecreaseButton(EAST);
  41.                 }
  42.                 break;
  43.         }
  44.         /*scrollbar.add(incrButton);
  45.         /scrollbar.add(decrButton);*/
  46.  
  47.         // Force the children's enabled state to be updated.
  48.         scrollbar.setEnabled(scrollbar.isEnabled());
  49.     }
  50.  
  51.     @Override
  52.     protected void paintTrack(Graphics g, JComponent c, Rectangle trackBounds) {
  53.         // pass =)
  54.     }
  55.  
  56.     @Override
  57.     protected void paintThumb(Graphics g, JComponent c, Rectangle thumbBounds) {
  58.         if(isThumbRollover()){ g.setColor(thumbHighlightColor); }
  59.         else{ g.setColor(thumbColor); }
  60.         g.fillRoundRect(thumbBounds.x + 4, thumbBounds.y, thumbBounds.width-6, thumbBounds.height, 4, 4);
  61.         g.setColor(thumbHighlightColor);
  62.         g.drawRoundRect(thumbBounds.x + 4, thumbBounds.y, thumbBounds.width - 6, thumbBounds.height, 4, 4);
  63.         g.setColor(thumbDarkShadowColor);
  64.         int height = thumbBounds.y + thumbBounds.height/2;
  65.         g.drawLine(thumbBounds.x + 5, height-4, thumbBounds.x+thumbBounds.width-3, height-4);
  66.         g.drawLine(thumbBounds.x + 5, height, thumbBounds.x+thumbBounds.width-3, height);
  67.         g.drawLine(thumbBounds.x + 5, height+4, thumbBounds.x+thumbBounds.width-3, height+4);
  68.     }
  69. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement