Skip to main content
Gholamreza Rezaei
New Participant
May 16, 2021
Answered

change justify editText with click

  • May 16, 2021
  • 1 reply
  • 610 views

I want to change the justify of the editText, but it does not work.

my code is:

 

var win = (this instanceof Panel) ? this : new Window("palette", "myScript", undefined, {resizeable:false});
var group=win.add('group');
group.orientation="column";
var edt = group.add('edittext {preferredSize: [220, 100], properties: {multiline: true},justify: "right"}');
var btn = group.add("button",undefined,"change justify");
btn.onClick=function()
{
edt.justify="left";
}
win.show();

 

This topic has been closed for replies.
Correct answer Paul Tuersley

According to the javascript tools guide "Justification only works if the value is set on creation, using a resource specification or creation parameters."

https://extendscript.docsforadobe.dev/user-interface-tools/control-objects.html?highlight=justify#justify

 

So it's not surprising it can't be changed later. But when I test your code I'm not even getting right justification unless I set it to multiline:false, so those two options may not work together. You didn't say if you encountered that issue, just that it 'does not work'.

 

If it was just a case of not being able to switch justification then I'd think you could fairly easily create a group with orientation 'stack' which would let you put multiple EditText in the same location, one for each justification, then switch visibility between them when you press the button. Then you'd just need something that filled in the text contents of the invisible one to that of the visible one when you make the switch.

 

But if like me you're not even getting right justification when multiline:true then that might be a dealbreaker anyway.

1 reply

Paul TuersleyCorrect answer
Inspiring
May 16, 2021

According to the javascript tools guide "Justification only works if the value is set on creation, using a resource specification or creation parameters."

https://extendscript.docsforadobe.dev/user-interface-tools/control-objects.html?highlight=justify#justify

 

So it's not surprising it can't be changed later. But when I test your code I'm not even getting right justification unless I set it to multiline:false, so those two options may not work together. You didn't say if you encountered that issue, just that it 'does not work'.

 

If it was just a case of not being able to switch justification then I'd think you could fairly easily create a group with orientation 'stack' which would let you put multiple EditText in the same location, one for each justification, then switch visibility between them when you press the button. Then you'd just need something that filled in the text contents of the invisible one to that of the visible one when you make the switch.

 

But if like me you're not even getting right justification when multiline:true then that might be a dealbreaker anyway.

Gholamreza Rezaei
New Participant
May 16, 2021

This is the best solution. Thank you for your help

 

If it was just a case of not being able to switch justification then I'd think you could fairly easily create a group with orientation 'stack' which would let you put multiple EditText in the same location, one for each justification, then switch visibility between them when you press the button. Then you'd just need something that filled in the text contents of the invisible one to that of the visible one when you make the switch.