<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
	<channel>
		<title><![CDATA[JavaRanch: Latest posts for the topic "JavaFX Button: You'd think this would be simple...."]]></title>
		<link>http://www.coderanch.com/forums/t/98/Java-FX/JavaFX-Button-You-d-think</link>
		<description><![CDATA[Latest messages posted in the topic "JavaFX Button: You'd think this would be simple...."]]></description>
		<generator>JForum - http://www.jforum.net</generator>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[I'm porting an iphone game over to <a href="http://www.javaranch.com" class="faq" title="A Friendly Place for Java Greenhorns" target="_new">java</a> for desktop distribution.  I'm in the process of investigating different techs to create it and one of those is JavaFX.  I want the app to look as similar to the iphone version as possible and I'm trying to apply an image to all my menu buttons.  My first attempt was to have a custom group that I would end up adding a mouse listener to that looks something like this...<br /> <br /> <pre>
def newGame = Group {
    content: [
    	ImageView {
    	    image: buttonImage
    	    x: 10
    	    y: 10
    	
    	},
    	Text {
    	    x: 80
    	    y: 30
    	    fill: Color.WHITE
    	    content: &quot;New Game&quot;
    	    
    	}    	
    ]
}
</pre><br /> <br /> This is overly verbose for a button.  So I started looking at the Button control.  I added an image to it however you can still see the Button underneath because of insets/margins and I can't seem to find out how to remove them.  I started looking into "skinning" but that seemed way overly complex for what I am trying to do.  I also started looking into creating a custom node or extending Button but again, can't figure out how to apply an image to it.  Anyone know a simple way to apply an Image to a Button control and not have any button margins/insets?]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2008206</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2008206</link>
				<pubDate><![CDATA[Tue, Jun 23 2009 23:11:45 MDT]]></pubDate>
				<author><![CDATA[Gregg Bolinger]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA["Wild Wild West" guess here.<br /> <br /> in the book threads/discussions last week, it was mentioned that javafx had a wrapper class for swing components.<br /> <br /> perhaps getting the button to behave itself as a swing component, then using the wrapper class might work.<br /> <br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2008233</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2008233</link>
				<pubDate><![CDATA[Wed, Jun 24 2009 00:00:59 MDT]]></pubDate>
				<author><![CDATA[Michael Dunn]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[First, you might want to look at the javafx.scene.control.Button class, however if you want to make the same view that you saw on the iPhone, something like this might work for you. You could also replace Text in the example with javafx.scene.control.Label. Label will confine the text to a maximum width to stay within the overall bounds of the button.<br /> <br /> <pre>import javafx.scene.CustomNode;
import javafx.scene.Node;
import javafx.scene.layout.Stack;
import javafx.scene.image.ImageView;
import javafx.scene.layout.Resizable;
import javafx.scene.image.Image;
import javafx.scene.text.Text;
import javafx.scene.paint.Color;
import javafx.geometry.HPos;
import javafx.geometry.VPos;
import javafx.stage.Stage;
import javafx.scene.Scene;

class MyButton extends CustomNode, Resizable {

    public var image:Image;

    public override function getPrefWidth(w: Number) : Number {
        100.0; // or replace with something more meaningful
    }
    public override function getPrefHeight(h: Number) : Number {
        50.0; // or replace with something more meaningful
    }

    public override function create(): Node {
        return Stack {
            nodeHPos: HPos.CENTER // this is default anyway
            nodeVPos: VPos.CENTER // this is default anyway
            content: [
                ImageView {
                    fitWidth: bind width
                    fitHeight: bind height
                    preserveRatio: true
                    image: bind image
                }
                Text {
                    fill: Color.WHITE
                    content: &quot;New Game&quot;
                }


            ]
        };
    }
}

function run() {
    var myImage = Image { url: &quot;{__DIR__}BakuretsuTenshi.jpg&quot; }
   Stage {
        title : &quot;MyApp&quot;
        scene: Scene {
            width: 200
            height: 200
            content: [
                MyButton {
                    image: myImage
                    width: 100
                    height: 100
                    onMouseClicked: function(e) {
                        println(&quot;clicked&quot;);
                    }

                }

            ]
        }
    }
}</pre><br /> <br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2008750</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2008750</link>
				<pubDate><![CDATA[Wed, Jun 24 2009 10:03:42 MDT]]></pubDate>
				<author><![CDATA[Jim Clarke]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[Jim, did you read my post?  I looked at the Button control.  I just can't figure out how to give it an image and remove the margins.  Thanks for the code example, but my example code is no worse and gives me the result I want.  I just assumed there was an easier (less code) way of doing this.]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2008792</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2008792</link>
				<pubDate><![CDATA[Wed, Jun 24 2009 11:00:15 MDT]]></pubDate>
				<author><![CDATA[Gregg Bolinger]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[The Button control has a skin based on what is called the Caspian theme. To remove the boundaries you could write your own skin, but that would probably be more work that what you are already doing.]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2011322</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2011322</link>
				<pubDate><![CDATA[Sun, Jun 28 2009 19:01:07 MDT]]></pubDate>
				<author><![CDATA[Jim Clarke]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[<blockquote class="uncited">
			<div>   Jim, did you read my post? I looked at the Button control. I just can't figure out how to give it an image and remove the margins. Thanks for the code example, but my example code is no worse and gives me the result I want. I just assumed there was an easier (less code) way of doing this. </div>
		</blockquote><br /> <br /> Can make use of "graphic" property of Button Control. <br /> <pre>  
Button{
  graphic: ImageView{
      image:Image{
         url:&quot;&lt;link to image&gt;&quot;
      }
  } 
}
</pre><br /> <br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2016649</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2016649</link>
				<pubDate><![CDATA[Mon, Jul 6 2009 22:01:21 MDT]]></pubDate>
				<author><![CDATA[mohammed sanaullah]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[<blockquote>
			<div>
				<cite>mohammed sanaullah wrote:</cite><blockquote class="uncited">
			<div>   Jim, did you read my post? I looked at the Button control. I just can't figure out how to give it an image and remove the margins. Thanks for the code example, but my example code is no worse and gives me the result I want. I just assumed there was an easier (less code) way of doing this. </div>
		</blockquote><br /> <br /> Can make use of "graphic" property of Button Control. <br /> <pre>  
Button{
  graphic: ImageView{
      image:Image{
         url:&quot;&lt;link to image&gt;&quot;
      }
  } 
}
</pre><br /> <br /> </div>
		</blockquote><br /> <br /> <blockquote>
			<div>
				<cite>Gregg Bolinger wrote:</cite>I added an image to it however you can still see the Button underneath because of insets/margins and I can't seem to find out how to remove them</div>
		</blockquote><br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2016650</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2016650</link>
				<pubDate><![CDATA[Mon, Jul 6 2009 22:13:12 MDT]]></pubDate>
				<author><![CDATA[Gregg Bolinger]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[<blockquote>
			<div>
				<cite>Gregg Bolinger wrote:</cite><blockquote>
			<div>
				<cite>mohammed sanaullah wrote:</cite><blockquote class="uncited">
			<div>   Jim, did you read my post? I looked at the Button control. I just can't figure out how to give it an image and remove the margins. Thanks for the code example, but my example code is no worse and gives me the result I want. I just assumed there was an easier (less code) way of doing this. </div>
		</blockquote><br /> <br /> Can make use of "graphic" property of Button Control. <br /> <pre>  
Button{
  graphic: ImageView{
      image:Image{
         url:&quot;&lt;link to image&gt;&quot;
      }
  } 
}
</pre><br /> <br /> </div>
		</blockquote><br /> <br /> <blockquote>
			<div>
				<cite>Gregg Bolinger wrote:</cite>I added an image to it however you can still see the Button underneath because of insets/margins and I can't seem to find out how to remove them</div>
		</blockquote><br /> </div>
		</blockquote><br /> <br /> Any one got a solution for this? ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2016653</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2016653</link>
				<pubDate><![CDATA[Mon, Jul 6 2009 22:19:09 MDT]]></pubDate>
				<author><![CDATA[mohammed sanaullah]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[That was my point, you can use Graphic, but the underlying border will still be shown.<br /> <br /> The 2 options are: use CustomNode as I had shown, or  use Button but write your own Skin.<br /> <br /> Each Control has a <blockquote class="uncited">
			<div>skin</div>
		</blockquote> variable and a Skin implements<blockquote class="uncited">
			<div> javafx.scene.control.Skin</div>
		</blockquote>. Each skin<br /> in turn has a <blockquote class="uncited">
			<div>behavior</div>
		</blockquote> variable, <blockquote class="uncited">
			<div>javafx.scene.control.Behavior</div>
		</blockquote>.<br /> <br /> So you could write you own skin.<br /> Then, create the Button as:<br /> <br /> <pre>Button {
   skin: MyButtonSkin{}
   graphic: ImageView{..}
}</pre><br /> <br /> Both options would be about the same amount of work, but the skin option<br /> is a better design option.<br /> <br /> ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2017389</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2017389</link>
				<pubDate><![CDATA[Tue, Jul 7 2009 14:56:24 MDT]]></pubDate>
				<author><![CDATA[Jim Clarke]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[Thanks Jim.]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2017390</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2017390</link>
				<pubDate><![CDATA[Tue, Jul 7 2009 14:57:17 MDT]]></pubDate>
				<author><![CDATA[Gregg Bolinger]]></author>
			</item>
			<item>
				<title>JavaFX Button: You'd think this would be simple....</title>
				<description><![CDATA[Thanks a lot. That was resourceful. ]]></description>
				<guid isPermaLink="true">http://www.coderanch.com/forums/posts/preList/451040/2017844</guid>
				<link>http://www.coderanch.com/forums/posts/preList/451040/2017844</link>
				<pubDate><![CDATA[Wed, Jul 8 2009 04:27:01 MDT]]></pubDate>
				<author><![CDATA[mohammed sanaullah]]></author>
			</item>
	</channel>
</rss>
