# Java graphical component looks

3 replies to this topic

### #1oskargustafsson

New Member

• Members
• 1 posts

Posted 10 August 2006 - 04:31 PM

Is there any way to alter the looks of specific java components? Say I want to remove the borders around a JTextField, for example.

I've searched the internet for answers with no result, but I'm sure you can help me. Thanks!

### #2I_Jones

New Member

• Members
• 4 posts

Posted 29 August 2006 - 11:04 PM

maybe just draw a box around the border of the textfield matching the BG colors, if your BG is multicolored well then i dont know, im a noob
no img code allowed huh?

### #3WildChild

New Member

• Members
• 3 posts

Posted 30 August 2006 - 07:56 AM

Yes there are ways to alter the default look for a Swing component. For your specific example look up setBorder method in JComponent (JtextField inherits from JComponent).

Use the documentation!

WildChild

### #4dega512

Valued Member

• Members
• 108 posts

Posted 30 August 2006 - 10:07 PM

Yes, look into the javax.swing.plaf.synth package.

Another option is to create a custom class that inherits the component and you do the custom painting in the paintComponent method, like this:

import java.awt.*;

import javax.swing.*;

public class MyComponent extends JComponent // replace with the component you wish to alter

{

// ... constructor etc..

protected void paintComponent(Graphics g)

{

super.paintComponent(g);  // make the component paint itself

// do all of your custom painting here...

}

}

- dega

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users