Changing Swing Component L&F

Hey

I am programming a game that takes place in the Middle Age, and to protect the player's suspension of disbelief, I'd like the few Swing components I use to look like they are pieces of wood.

I use a JScrollPane to scroll on the game's 2D viewport. I was thinking of getting the Graphics of the JScrollBars and repaint them, but it is not performance efficient.

Does anybody know how I could put my own pictures instead of the default tabs?

Thanks, Guillaume

[495 byte] By [gulm.org] at [2007-9-27 21:35:40]
# 1
I've never used this, but many people have recommended it: http://www.l2fprod.com/hth,m
wywiwyg at 2007-7-7 3:32:30 > top of Java-index,Other Topics,Java Game Development...
# 2
I didn't think computers were around in the middle-ages :)back then, they had more important things to worry about than L&F :P
Abuse at 2007-7-7 3:32:30 > top of Java-index,Other Topics,Java Game Development...
# 3

This is a sample of a self painted JScrollBar

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import javax.swing.plaf.*;

import javax.swing.plaf.basic.*;

class TinySp extends JScrollBar

{

public TinySp()

{

super.setUI(new myCustomScrollBarUI());

setPreferredSize(new Dimension(9,1));

setOpaque(false);

}

}

class myCustomScrollBarUI extends BasicScrollBarUI

{

public void configureScrollBarColors()

{

super.configureScrollBarColors();

}

public Dimension getMaximumThumbSize()

{

return(new Dimension(3,10));

}

protected void paintTrack(Graphics g, JComponent c, Rectangle trec)

{

g.setColor(Color.lightGray);

g.fillRect(trec.width/2,trec.y,1,trec.height);

}

protected void paintThumb(Graphics g, JComponent c, Rectangle trec)

{

g.setColor(Color.blue);

g.fillRect(3,trec.y,3,trec.height);

}

protected JButton createDecreaseButton(int orientation)

{

AbstractButton a1 = new myButton(1);

return((JButton)a1);

}

protected JButton createIncreaseButton(int orientation)

{

AbstractButton a2 = new myButton(0);

return((JButton)a2);

}

class myButton extends JButton

{

int d = 0;

public myButton(int i)

{

super();

d = i;

setOpaque(false);

setPreferredSize(new Dimension(9,9));

setBorderPainted(false);

}

public void paintComponent(Graphics g)

{

super.paintComponent(g);

Graphics2D g2 = (Graphics2D)g;

g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);

g2.setColor(Color.black);

if (d == 1)

{

g2.drawLine(4,1,1,6);

g2.drawLine(4,1,7,6);

g2.setColor(Color.lightGray);

g2.fillRect(4,7,1,5);

}

else

{

g2.drawLine(4,getHeight()-2,1,getHeight()-7);

g2.drawLine(4,getHeight()-2,7,getHeight()-7);

g2.setColor(Color.lightGray);

g2.fillRect(4,getHeight()-12,1,5);

}

g2.dispose();

}

}

}

Noah

noah.w at 2007-7-7 3:32:30 > top of Java-index,Other Topics,Java Game Development...
# 4

Right now, I'm leaning toward the skinned components, because I don't need to write code to change the UI aspect, I just have to change the java options and draw my PNG files. The problem is that it seems to eat up quite some memory, maybe more than the hard-coded UI. Another problem I am encountering with the skinned UI is that the top part of the screen is like the top part of a window, so if you want you can drag the window around - and that's not a cool feature when you are in fullscreen with a lower resolution :( otherwise it looks pretty great so far.

gulm.org at 2007-7-7 3:32:30 > top of Java-index,Other Topics,Java Game Development...