Closed mokun closed 3 years ago
Depends on what you mean under "high quality". Currently WebStatusBar
is similar to JToolBar
, just has a different styling out-of-the-box for convenience. I was thinking about potentially adding some other features to it, but they are all quite specific and depend on the type of app you are developing - nothing really worth adding into standard WebStatusBar
API.
Okay, guess I didn't understand how to work out this issue yet.
How do I make the components in the WebStatusBar
having fixed width ?
For instance, if there are 3 sets of coordinate labels such as x = 50, y = 60
inside the status bar, when the value of x and y change over time (from 2 digits to 3 digits, etc., the shift in width in one component would somehow cause the center component to shift or to jiggle.
Appreciate any help in avoiding this undesirable effect !
I just found out that I need to be careful with the FlowLayout manager when using the JPanel/WebPanel.
When I'll use no layout manager for the middle label and use FlowLayout.LEFT
instead of FlowLayout.RIGHT
for the end label, the text within these labels are no longer shifting.
WebStyledLabel l2 = new WebStyledLabel(StyleId.styledlabelShadow);
WebStyledLabel l3 = new WebStyledLabel(StyleId.styledlabelShadow);
WebPanel w2 = new WebPanel();
WebPanel w3 = new WebPanel(new FlowLayout(FlowLayout.RIGHT));
statusBar.addToMiddle(w2);
statusBar.addToEnd(w3);
How do I make the components in the WebStatusBar having fixed width ?
For instance, if there are 3 sets of coordinate labels such as x = 50, y = 60 inside the status bar, when the value of x and y change over time (from 2 digits to 3 digits, etc., the shift in width in one component would somehow cause the center component to shift or to jiggle.
This is, generally speaking, is unrelated to WebToolBar
and more about how you utilize layouts.
WebToolBar
is simply a Container
- just like JPanel
- but with a custom decoration. It uses custom WebLaF StatusBarLayout
by default which acts in almost the same way as ToolBarLayout
does, mainly because it's the most convenient layout for a status bar or a tool bar. But you can of course replace the layout if you want to.
Now for your question - if you want labels to not "jiggle" around as their content (text) is changed - you simply need to provide them with fixed preferred size. You do want to be careful though, because it has to be large enough to fit all possible text variations. Also it might be hard to provide a correct preferred height, so I recommend using method available in WebLabel
:
final WebLabel label = new WebLabel ( "Sample" );
label.setPreferredWidth ( 200 );
This will set label width to fixed 200px, but will allow it to adjust it's height according to the label Font
, so you don't have to do this manually.
I might add some extra methods in the future to provide preferred width based on the character count instead of pixels, like the JTextField
allows you to do. Although it will be based on maximum possible character width in Font
, so it still won't be perfect. But it will guarantee that if you set it to 10 characters in width - it will always fit any text that contains up to 10 characters.
I just found out that I need to be careful with the FlowLayout manager when using the JPanel/WebPanel.
When I'll use no layout manager for the middle label and use FlowLayout.LEFT instead of FlowLayout.RIGHT for the end label, the text within these labels are no longer shifting.
Text shifting around isn't a bug in the first place - each component simply recalculates it's preferred width on every settings change (like text change in label) and then the underlying layout uses that width to position the component. In case of something like FlowLayout
- components are positioned one after another, so for instance if first component in the line changes it's preferred size (and you haven't set a fixed preferred size) - it will force other components in the line move to accommodate it's size change.
I'll close this issue since the original question should now be answered.
Hi @mgarin ,
Will weblaf by any chance include a high quality
Status Bar
implementation in future ?