How to add a read-only DialogComponentString

#1

Want to add an input,but the input value selected from the other UI.
I searched the API DOC,did not find method to set input component read-only,It’s possible to set input component read only?

another question:
How to set dialog UI component align(left or right)?
image

thanks

0 Likes

#2

Hi @lou,
You can add a read only compont as a label:

DialogComponentLabel label = new DialogComponentLabel("read only value");

// update the text
label.setText("new text");

However, this does not have a settings model, so you need to store the selected value somewhere else.
In your case it might be a good idea to use a list selection component like: DialogComponentStringSelection, it provides a dropdown list where a user selects an option.

In the DefaultNodeSettingsPane you can only chose horizontal or vertical dialog component placement, if you want to layout the dialog yourself you need to fall back to the NodeDialogPane, create a JPanel and customize its layout with e.g. a GridBagLayout.

best,
Gabriel

1 Like

#3

You can get to the underlying swing component too, in order to change the layout detail, e.g., with your code above:

JLabel jLabel=(JLabel) label.getComponentPanel().getComponent(0);
jLabel.setHorizontalAlignment(SwingConstants.TRAILING);

See also https://stackoverflow.com/questions/12589494/align-text-in-jlabel-to-the-right/12589611 and the JavaDoc for JLabel.setHorizontalAlignment()

Steve

2 Likes

#4

Nice hack Steve :nerd_face: :+1:

1 Like

closed #5

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

0 Likes