I would like to know if it's possible to remove red areas(on JProgressBar) on the following image.
These are blue lines on the top and left side of the progress bar which I would like to remove. I have managed to remove it with paint() method, painting progress bar manually. But probably there is more correct way of doing it.
Thanks,
Serhiy.
Not tested but i think progressBar.setBorderPainted(false) should do the trick.
Subclassing JProgressBarand overriding paint()is fine and perfectly correct if you want to modify the bar's behaviour. I'm not sure where your blue lines are coming from though; do you have a shadow effect set somewhere?
Related
Recently, I'm using Synthetica as default JLAF, but progress bar doesn't fill, I try the following customize sentences but, nothing changes:
Synthetica.progressBar.x.animation.type with a different value of 0.
Synthetica.progressBar.respectMinimumBarImageSize with the recommended value of false.
Is there a solution?, is it a simple bug? or Is there some customize sentence that I've not seen?
I must clarify that, in other JLAF like nimbus, progress bar fills perfectly.
Thanks in advance!
At the end, the best way to solve the problem was deleting the sentence Synthetica.progressBar.x.animation.type and keeping the other as the following:
UIManager.put("Synthetica.progressBar.respectMinimumBarImageSize",Boolean.FALSE);
I am going through a legacy application which is using Swing and i am struggling to figure out how the screens are changing when a user clicks a button. One of the reasons i cant figure this out is because this is the first time i am using Swing. I have read a book and got the basics but still struggling.
Basically, the screen i am looking at has a JSplitPane which has a number of shortcut buttons on the left and an empty pane on the right. When i click on the button, the right side pane is populated with a different screen depending on the button pressed.
Going through the code, i was expecting somewhere that there will be something that calls a setVisible() method depending on which button is pressed.
The actionPerformed method for each of the shortcut buttons looks something like this:
void shortCutBtn_actionPerformed(ActionEvent e) {
propertyChangeListeners.firePropertyChange("selectedShortCut", previousShortCutSel, currentShortCutSel);
mainPanel.updateUI();
}
I have gone through most of the code and came to a conclusion that the above code is what is causing the frame switching but i dont understand how that is happening.
Each screen is identified by a numeric constant. In the above code example, previousShortCutSel and previousShortCutSel refer to a numeric value that represents individual screens screen.
I have tried to look for documentation of how updateUI() works but i am lost. How does the above cause the content of the right panel of the JSplitPanel to be updated with a new screen?
This is not an appropriate use of updateUI(), which "Resets the UI property to a value from the current look and feel." As the example itself may be unreliable, consider studying another. GoogleOlympiad, for example, sets a label's icon using a (cached) image.
ImageIcon image = getImage(index);
imageLabel.setIcon(image);
(source: drjohnbmatthews at sites.google.com)
As per comments by ziggy (glad it helped)
Have a look at the PropertyChangeListeners that appear to be added in the code. In particular the propertyChange(PropertyChangeEvent e) method is where the code which changes the content will be present.
+1 to trashgod nice example/advice as always
I implemented an indeterminate java progress bar in my program but for some reason the progress bar is grey instead of blue. Any ideas why this is happening?
This is how the progress bar looks; it is supposed to have moving blue lines shown below instead of the stationary grey ones as shown in the picture.
Maybe the JProgressBar is disabled. When working with a GUI Editor, search for the option enabled and make sure it is set to true.
You can do it manually as well by calling:
progressbar.setEnabled(true);
I will assume that you are talking about a awt/swing application. The progress bar color, along with every other GUI element, is regulated by the Look & Feel of the application. Swing/awt have standardized look and feels, but also some that are heavily platform-dependent. For more precise information, please provide a screenshot of your progress bar and also of the one that you think your bar should look like.
For information how to set the look & feel, look here:
http://docs.oracle.com/cd/E17409_01/javase/tutorial/uiswing/lookandfeel/plaf.html
EDIT:
Can you provide the code of your app where you define the progress bar? I assume it is a JProgressBar? Also, what OS do you use?
EDIT EDIT:
The progress bar you created can have its look and feel changed.
http://www.java2s.com/Tutorial/Java/0240__Swing/CustomizingJProgressBarLookandFeel.htm
Experiment with the mentioned properties like that:
UIManager.put("ProgressBar.selectionBackground", Color.blue);
Until you achieve a result that is suitable to you. Hope that helps.
I am having a set of panelbar Items which need to have a image as label and this image will change when onexpand and shrunck of the panel .
please help me in resolving this issue
I don't see any such options from here, But you can always play with raw HTML and set image there.
First, define two CSS classes: one for the normal state (I call it panelBarClosed), the second one for the opened state (panelBarOpened), and set the image as the background:
.panelBarClosed {
background: url('/path/to/images/closed.png');
}
.panelBarOpened {
background: url('/path/to/images/opened.png');
}
Now, on your <rich:panelBarItem>, set the first class:
<rich:panelBarItem headerClass="panelBarClosed" headerClassActive="panelBarOpened">
...
</rich:panelBarItem>
I am not sure if this is enough or not (I am not able to test it right now).
If this still is not working, this component provides two other attributes that can be useful in your case: onenter and onleave. The first event is fired when you "enter" the panel bar item (i.e. you open it), the second one when you leave it. So the idea is to change the CSS class of the component on this events:
<rich:panelBarItem ...
onenter="jQuery(this).removeClass('panelBarClosed').addClass('panelBarOpened');"
onleave="jQuery(this).removeClass('panelBarOpened').addClass('panelBarClosed');">
...
</rich:panelBarItem>
(again, I didn't test it, so maybe this solution should be corrected a little)
Here's a very specific coding question:
I've recently been asked to maintain some old-ish Java Swing GUI code at work and ran into this problem:
I've attached my own subclass of InputVerifier called MyFilenameVerifier to a JTextField (but it may as well be any JComponent for these purposes). I've overridden the verify() method such that it calls super.verify(input) (where input is the JComponent parameter to verify()). If super.verify(input) comes back false, I do:
input.setBorder(BorderFactory.createLineBorder(Color.RED));
This is a convention used throughout the UI of this application that started long before me, so I don't have a lot of choice as far as using other ways to get the users attention (wish I did). This is just the way it works.
Problem is, once the user goes back and types something valid into the text field, I need a way to set it back to default border (instead of just saying set it to Color.GRAY or whatever, which is a different color from its original border). I need a way to say, "remove the extra decoration and go back to normal" or just set the border to its default, in other words.
Couldn't you just call input.getBorder() and cache it somewhere before setting the border to red?
Or without caching anything, you could tell the JComponent to update its UI back to the look and feel's defaults via component.updateUI. That should make the component reset its colors, borders, fonts, etc to match the original settings.
input.getBorder()
Wouldn't it be awesome if no one ever saw this and I got away free without the ass-beating I deserve for asking this question?
Not sure how your system is build, but I think you can store the original border before changing it. So you can change it back later
// assuming the Border was not null before
if (!super.verify(input)) {
original = input.getBorder();
input.setBorder(...);
} else {
if (original != null) {
input.setBorder(original);
original = null; // not needed
}
}
You need to preserve the existing border when you change it.
One way to do this is to use the methods putClientProperty() and getClientProperty(), which you'll find documented in the API.
Another possibility, if there are only a few input widgets you need this for is to subclass, e.g. JTextField, add setBorderOverride() and modify getBorder() to return "overriddingBorder" if it is not null.
Then you just use setBorderOverride(redBorder) to make it red and setBorderOverride(null) to clear it.
This of course depends on the painting to use getBorder(), which it may or may not do, and which may be implementation specific.
Incidentally, you only need a single static reference to the border-- it's the selfsame border instance used by all JTextFields.