What is the difference between with and apply. From what I know the following code does the same thing:
swingElement.apply {
minWidth = ENABLED_COLUMN_WI
There're two differences:
apply accepts an instance as the receiver while with requires an instance to be passed as an argument. In both cases the instance will become this within a block.
apply returns the receiver and with returns a result of the last expression within its block.
I'm not sure there can be some strict rules on which function to choose. Usually you use apply when you need to do something with an object and return it. And when you need to perform some operations on an object and return some other object you can use either with or run. I prefer run because it's more readable in my opinion but it's a matter of taste.