Hello, I am trying to use a button click event to change the size of a chart. I am trying to figure out what I am doing wrong.
window = system.gui.getParentWindow(event)
chart = window.getRootContainer().getComponent('chart')
if chart is None:
print 'chart was not found'
else:
#button text
buttonText = event.source.text
if buttonText == 'Increase Chart Size':
print 'chart is small. making it large'
#large
newX = 8
newY = 8
newWidth = 1106
newHeight = 568
event.source.text = 'Decrease Chart Size'
else:
print 'chart is large. making it small'
#small
newX = 548
newY = 105
newWidth = 566
newHeight = 471
event.source.text = 'Increase Chart Size'
chart.setSize(newWidth, newHeight)
chart.setLocation(newX, newY)
chart.repaint()
print 'done'
You are trying to directly use Swing methods without taking into account what Swing does with Look & Feel implementations.
TL/DR: Use system.gui.transform()
.
1 Like
I have a chart in vision that I am trying to make larger by using a button click. When the button is clicked I want to change the charts size and position. It does work, but when the button is clicked again, I want the chart to return to its original size and position. This is where the problem lies. I cannot get the chart to return to is original position every time. The original position of the chart is on the right side but if vision is full screen then instead of the chart returning to the right side, it is in the middle. I have placed the script that I am using in the button click below. Please let me know what I can do to get the chart to return to its original position.
window = system.gui.getParentWindow(event)
chart = window.getRootContainer().getComponent('chart')
buttonText = event.source.text
if buttonText == 'Increase Chart Size':
#large
x = 8
y = 8
width = 1106
height = 568
event.source.text = 'Decrease Chart Size'
else:
#small
x = 548
y = 105
width = 566
height = 471
event.source.text = 'Increase Chart Size'
system.gui.transform(component=chart, newWidth=width, newHeight=height, newX = x, newY = y)
@Burger_King this topic is closely related enough to the original I just merged the thread.
Try specifying the "coord space" argument in your system.gui.transform
call - you want to use the coordinate system from the designer with your hardcoded positions.
Thanks a lot. This worked for me.
system.gui.transform(component=chart, newWidth=width, newHeight=height, newX = x, newY = y, coordspace=1)
1 Like