Can we get rid of the grey outline around a JProgressBar ?

I've tried doing

//

// Has no effect

//

UIManager.put("ProgressBar.background", Color.WHITE)

//

// Sets the background inside the progressbar, but not outside

//

myProgressBar.setBackground(Color.WHITE)

//

// Setting the border colour doesn't help either, since the outline isn't the actual border, as this line shows

//

myProgressBar.setBorderPainted(false);

Does anyone know how to do this?

[817 byte] By [KomodoDavea] at [2007-11-26 15:29:56]
# 1
try setting the progressBar.setBackground(null); first to see if that's the effect you are trying for. I'm trying to write another SSCCE that actually removed the "bevel" border that seems to be stuck on the component even after you set the background to null.-Js
JSnakea at 2007-7-8 21:46:26 > top of Java-index,Desktop,Core GUI APIs...
# 2

Got it. It's a combination of setBorder(null) and setBorderPainted(false)

Here's the example. The Progressbar is set at 50 percent. Notice there is absolutely no border.

import java.awt.Color;

import java.awt.Dimension;

import javax.swing.Box;

import javax.swing.BoxLayout;

import javax.swing.JFrame;

import javax.swing.JPanel;

import javax.swing.JProgressBar;

public class ProgressBarBorderExample extends JFrame

{

private JPanel panel;

private JProgressBar progressBar;

public ProgressBarBorderExample()

{

this.setSize(200,100);

this.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);

this.setContentPane(getPanel());

this.setVisible(true);

}

private JPanel getPanel()

{

if(panel == null)

{

panel = new JPanel();

panel.setBackground(Color.WHITE);

panel.setLayout(new BoxLayout(panel,BoxLayout.X_AXIS));

panel.add(Box.createHorizontalGlue());

panel.add(getProgressBar());

panel.add(Box.createHorizontalGlue());

}

return panel;

}

private JProgressBar getProgressBar()

{

if(progressBar == null)

{

progressBar = new JProgressBar();

progressBar.setPreferredSize(new Dimension(150,50));

progressBar.setMaximumSize(new Dimension(150,50));

progressBar.setMinimumSize(new Dimension(150,50));

progressBar.setValue(50);

progressBar.setBorder(null);

progressBar.setBorderPainted(false);

}

return progressBar;

}

public static void main(String args[])

{

new ProgressBarBorderExample();

}

}

JSnakea at 2007-7-8 21:46:26 > top of Java-index,Desktop,Core GUI APIs...
# 3

> I'm trying to write another SSCCE

No, that is the OP's responsibility to post a SSCCE showing exactly what they have tried. Even if it doesn't work it allows us to play with code and try to solve the problem without starting from scratch.

It does not make sense for everybody who reads this posting to create their own SSCCE. The OP refuses to do this even for the most simple of questions which is why he rarely gets any help.

The OP should be trying to minimize the time we spent answering his question so that we can continue to answer other questions. Even if we spend 5 minutes creating the SSCCE from scratch that is 5 minutes that could have been spent on another question.

camickra at 2007-7-8 21:46:26 > top of Java-index,Desktop,Core GUI APIs...
# 4

> Got it. It's a combination of setBorder(null) and

> setBorderPainted(false)

You're a complete legend JSnake, massive thanks. I wouldn't have thought of trying that; thank you for the comprehensive code example too, it automatically answers any questions I might have had about your methodology. Thank You :oD

> No, that is the OP's responsibility to post a SSCCE

> showing exactly what they have tried

'No'?! LOL, are you telling JSnake he isn't allowed to post an SSCCE? He can do what he wants; I already told him what I tried, now he's shown me what he's tried, which worked. Seems perfectly reasonable to me.

> The OP refuses to

> do this even for the most simple of questions

For exactly that reason camickr - not all of us who see a simple question demand an SSCCE to accompany it. Why don't you spam elsewhere, I'm fed up to the back teeth of your righteous attitude. If you don't want to help, that's your prerogative, but I'm sick and tired of hearing you whine about me not posting an SSCCE. I was glad to see a couple of posts earlier from apparently experienced coders who share the same sentiment. Go help the SSCCEr's if that's what does it for you, and stop wasting time for the both of us.

KomodoDavea at 2007-7-8 21:46:26 > top of Java-index,Desktop,Core GUI APIs...
# 5

You are free to post questions the way you want.

I am free to respond to questions the way I want.

I am just informing others on the forum of your attitude. They can decide for themselves how to reply.

I don't comment on all your questions. Only those where a SSCCE is appropriate.

> I'm fed up to the back teeth of your righteous attitude.

ditto!

> I was glad to see a couple of posts earlier from people who share the same sentiment.

By people asking questions, not people answering the questions. There is a big difference. People who donate their time to help people with their problems have more respect from me than those only only know how to ask questions and never bother to acutally help others.

camickra at 2007-7-8 21:46:26 > top of Java-index,Desktop,Core GUI APIs...
# 6
Note that these settings may or may not be respected by third-party LAFs.
kirillga at 2007-7-8 21:46:26 > top of Java-index,Desktop,Core GUI APIs...
# 7

kirillg: You are definetely correct. Please test on all look and feels that the program will be used on.

camickr & KomodoDave:

First off, let me say that I am in agreement with camickr on this one. While it only took me like 5 min or less to build that SSCCE, it did ASSUME that I knew what you were looking for and what outcome you truely expected. The problem with me continuing that practice is on bigger questions I might have just wasted 30 min of time on something that wasn't even what the OP wanted. So an SSCCE would definetely make it clearer of what the OP was trying to do... and what needed to be fixed in order to satisfy the OP's question.

I don't think in all cases its wrong to throw up some code for someone who hasn't posted a SSCCE, but on the other hand, it does do a disservice to the OP... whether they see it or not.Let me explain the reasons why I think the OP should (almost) always write a SSCCE:

1. It will teach you how to simplify a problem down to its bare essentials. If you cannot do this yourself, your project is over your head. Writting these SSCCEs will give you a much clearer picture of what you doing. It helps you think!

2. Saves time for the people who have the answers. It will give us more time trying to find a solution, than to whip up the rest of the code along with the answer.

3. From the people who answer you, you receive not only comments on your original question, but also comments on style, technique, and effeciency. Topics that might be completely outside the OP's questions, but SOOOOO useful in your coding toolbelt. I have learned much from people such as camickr re-arranging SSCCE's. Seriously .. GREAT learning tool.

This list could go on for another 100 I'm sure. I'm fairly new around here, but the fact is, SSCCE's make you a better coder, and isn't that why we're all here? Not just for quick answers to move on.... but to learn.. so that we may be the one to answer the question the next time? In fact, I've used SSCCEs my whole life to try to explain answers to programmers whom I've encountered, and I'm glad I'm in an environmen that embraces them. It just makes you a better coder to write them.

*pause*

In conclusion. SSCCE = GOOD.

-Js

Message was edited by:

JSnake

JSnakea at 2007-7-8 21:46:26 > top of Java-index,Desktop,Core GUI APIs...
# 8

> I don't think in all cases its wrong to throw up some code for someone who hasn't posted a SSCCE,

I didn't mean to imply that it was wrong to post your own SSCCE. I meant it was wrong that you had to create one on your own time.

I think its great when people respond with a SSCCE. It keeps the thread short and simple with no need for follow up questions like: "where to I add this line of code?".

camickra at 2007-7-8 21:46:26 > top of Java-index,Desktop,Core GUI APIs...
# 9

It also depends on the question you're asking, sometimes you simply cant isolate your code into a SSCCE. but usually for a swing forum you can. I agree with camickr, its very helpful. you have to put yourself in the shoes of the person answering the question. us programmers sometimes get soo involved into our projects, and generalize our questions. sometimes not typing everything we're thinking . i understand SSCCEs take time to develop, and time is money (for most of us), but it will save time in people trying to understand your problem, and chances are you'll get more replies.

just my thoughts

llpindda at 2007-7-8 21:46:26 > top of Java-index,Desktop,Core GUI APIs...