I'm trying to make H3 label, at this point I use built-in Vaadin theme - ValoTheme.This is how i create new label:
Label label = new Label();
label.setCaption("myLabel");
label.setStyleName(ValoTheme.LABEL_H3);
But for some reason, label keeps unstyled.
The question is - how i could stylish Label without using CSS?
Thanks
P.S UI class has been annotated with #Theme(ValoTheme.THEME_NAME)
Update: Making primary button with ValoTheme styling as described above, everything works perfectly.
It took for a while to investigate and found solution that fits me best. The issue has been related to 'label.setCaption(caption);' method, which set components caption, but it denied object customizations.
Thanks to #André Schild for suggestion. So i tested these two small solutions and they worked fine:
Label label = new Label(caption);
label.setStyleName(ValoTheme.LABEL_H3);
and
Label label = new Label(caption);
label.addStyleName(ValoTheme.LABEL_H3);
I hope it helps someone
Related
I am using the Swing GUI editor on the IntelliJ IDEA IDE. In the properties navigator of the JScrollPane there is a property called "border" and, inside of it, a sub-property called "title". There I can set a title to the pane, but I cannot find how to change this title dynamically.
I have tried all the reasonable possibilities that would work with most common swing components, like getting the border (as this title is apparently a property of the pane border) and finding some setText() or setTitle() method somewhere, but I could find nothing...
As I suspected, and as read in the question comments, the whole thing was going around the border property:
String borderTitle = "My fancy title";
Border etchedBorder = BorderFactory.createEtchedBorder();
Border etchedTitledBorder = BorderFactory.createTitledBorder(etchedBorder, borderTitle);
myScrollPane.setBorder(etchedTitledBorder);
Note I used the createEtchedBorder(), but any other available border method creator can be used.
There are probably better ways to achieve this, because in that way you need to set a new border every time you need to change the title instead of just changing the value of its title parameter, but this is doing the trick pretty well.
I hope this can be useful.
I created a label with a number shown in it and I now want to make this number responsive to the GUI.
How can I do that? Here is my number with its current font-size.
Label label = new Label();
label.setText("12");
label.setFont(Font.font("Comic Sans MS", 35));
Thanks for your help :)
If you want change values or params of this label you must use one of avelible javaFx controls: https://docs.oracle.com/javafx/2/ui_controls/jfxpub-ui_controls.htm
For each control you have onActionListners functions where you can make changes.
Hope this help.
Anchorpane,HBOX etc. are responsive in nature.Put the label inside a HBOX.
Hope this help.
I've created a checkbox skin for libgdx Scene2d but the problem that there is no space between my checkbox and the text label , here is my code for the checkbox :
final CheckBox vSyncCheckBox = new CheckBox("vSync", skin);
vSyncCheckBox.setChecked(vSync());
vSyncCheckBox.getCells().get(0).size(30, 30);
and in the table layout i tried to use spaceRight(10); but nothing happens :
table.add(vSyncCheckBox).top().expandY().spaceRight(10);
here is the image on what the checkbox looks like for the moment:
Like you can see the checkbox and Vsync are stack together any help on how to provide some space between them ?
This is how you set space between the check box and the text label.
final CheckBox vSyncCheckBox = new CheckBox("vSync", skin);
vSyncCheckBox.getLabelCell().padLeft(10);
This is how I solved my similar problem:
table.add(yourButton).padLeft(Distance).OTHER_STUFF;
Next time please refer to the Wiki table page to solve any problems of or relating table layout
If you have any problems in understanding the concept turn on debugging
table.setDebug(true);
If your check box and your label is one single item, you can just simply put some space " vSync" in your declaration of the object instead of "vSync".
Could you please post the whole code of that table? It might be not working because of other settings made to the table.
Also, it can be helpful to activate debug mode by using
table.setDebug(true); // turn on all debug lines (table, cell, and widget)
Source: https://github.com/libgdx/libgdx/wiki/Table#debugging
I am designing a Jframe using netbeans. I do have few questions.
Can we create a label for a field in a desired location(For eg.,we have a field named height, I need to display a label below it indicating height is in cm) conditionally?
Can we disable a field based on a condition?(by disable I mean it shouldn't be displayed in my frame)
Can someone suggest me whether we can achieve them through some examples.
Tried this, after some helpful suggestions
private void englishRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
JLabel userlabel;
if (englishRadioButton.isSelected())
{
userlabel = new JLabel("Inches");
userlabel.setBounds(311, 59, 64, 36);
//userlabel.setLocation(307,55);
//userlabel.setSize(70,40);
userlabel.setForeground(Color.green);
userlabel.setText("Inches");
userlabel.setVisible(true);
System.out.println(englishRadioButton.getBounds());
inchesTextField.setVisible(true);
}
}
The textfield is visible only when I click the English radio button,at the same time I need to get a label but it's not displayed with the above code. Can I know where I am going wrong?
Please see the attached screenshots
When English button is clicked, I need a label beneath the second textfield as inches, I am disabling the text field when Metric is displayed. I am able to achieve the later one but not the former one
Thanks!!
Yes, relative placement of components is easily achieved with use of layout managers.
Yes, all components have a setEnabled(...) and a setVisible(...) method either of which can be called at any time during a program's run. The former helps you activate/inactivate components and the latter helps make them visible/invisible. If you want to swap complete "views", use a CardLayout.
Regarding:
Can someone suggest me whether we can achieve them through some examples.
Please, you first as I strongly believe that the onus of effort here should be yours, the questioner's, since you're the one asking the questions, and the one with the most to learn by coding as much as possible. Let's see your attempts and we can help you with them. Otherwise the best examples are to be found at the Swing Tutorials.
For links, please look here: Swing Tag Info.
Edit
You ask:
I tried the above posted code,conditionally disabling the text field works well but getting a label doesn't work. Can you please suggest on that?
I don't see you adding your JLabel to any component. If you are going to create a component on an event, you must add it to a component whose ancestor hierarchy eventually reaches a visible top-level component such as a JFrame. Then after adding a component to a container (say a JFrame), you must call revalidate() on the container to have its layout managers re-layout its components, and then repaint() to repaint any "dirty" pixels.
I again will re-iterate that you're far better off not using null layout and absolute positioning, but rather using layout managers and relative positioning. If you want a label with and without visible text, it's often best to add an empty JLabel to the GUI on GUI creation, and just set its text when needed, as long as the label is located somewhere that allows its text to shrink and expand.
Also, as to your current problem, you might wish to show a picture of what you're trying to achieve, and what you're getting. Or if you can't post a picture here yet, post a link to an image or images you've created, and then we'll post it for you.
I have made a frame in which i have put two jTextfield boxes where the user can see the path of the loaded file. Problem is that if the path is too long , the textfield expands to accomodate the full path which again leads to display problems. I would like to keep the textfield's length constant and instead , display the full path of file as a tooltip instead.
How can this be done?
Code for layout manager of jinternal Frame:
javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
I never use an IDE so I don't know how the GroupLayout works.
But when using the other layout managers I always use:
JTextField textField = new JTextField(10); // or whatever size your want
This will give the text field a preferred size and the layout manager can use that information when laying out the component.
Code the GUI by hand instead. You will avoid problems like this and it will be much easier to make changes to your code.
you need to choose a layout manager to manage the proportions of your JComponents.
Try to put your textfiels on a JPanel so you can select a layout useful for you
Later you can use JTextField. setToolTip("full path") to set a tool tip
I solved my problem:
Anybody having the same problem can set the Property Columns using Netbeans. The default is 0, so the textfield cannot accomodate the full text. Use some value like 3 to achieve it.