Stylish Buttons in Java Fx

Hi,
This is Rakesh . I'm trying to create stylish buttons and menus in JavaFx
and for this purpose i'm trying to study about the role of gradient and
other such effects in styling the UI . I have surfed for various buttons in google
and trying to replicate the CSS buttons and cool Menus in JavaFx .
How ever i have found buttons with Text that look deep inside and for such buttons i'm not able to find any CSS
or any other information on how to create them .
For Example in the button [http://sites.google.com/site/javafxpoint/DeepTextbtn.gif|http://sites.google.com/site/javafxpoint/DeepTextbtn.gif]
i see that the text appears to be some what deep .
And in the button [http://sites.google.com/site/javafxpoint/notSoDeepbtn.gif|http://sites.google.com/site/javafxpoint/notSoDeepbtn.gif] ,
i see that the text does not appear so Deep .
We can download both those buttons to our desktop and try to enlarge them
and find that the color in the top half of the button is some what lighter when compared to the bottom half
and that can be achieved using Gradient .
But now my issue is that i'm not able to find out why the Text in the button1 seems to be very deep
and the test in the button2 seems to be normal . Is there any JavaFx effects or properties
that i can make use of to create Deep Text buttons using JavaFx .
Thanks
Edited by: vrakesh.techie on Oct 21, 2009 5:43 AM
Edited by: vrakesh.techie on Oct 21, 2009 5:44 AM
Edited by: vrakesh.techie on Oct 21, 2009 5:45 AM

Hi PhiLho,
I have tried your suggestion and it has worked for me .
I'll upload the demo soon .
But i think i need to play more with it so as to achieve perfection in it .
In my current sample i have placed the black shadow text on click of the button so as to make
the test look deep and then when its clicked again i have set the opacity of the black text to 0
so that the text does not look deep .
By clicking it again and again , we can feel that the text goes deep and comes up but i did not know how
to increase or decrease the depth of the text in a countable fashion .
( currently it's going deep or staying up based on whether i set the opacity of the black text to 0 or 1 ) .
I tried replacing the offSet of posX ,i.e posX + 1 with posX + 2 and posX + 0.5 and other options but they made it more clumsy .
I think i will have to play with the font weight properties so as to increase the depth of the text in a
measurable fashion .
Code used by me for testing :
===============================================================================================================
* simpleBtn.fx
* Created on Oct 22, 2009, 6:57:07 PM
package fancyButton;
import javafx.scene.paint.Color;
import javafx.scene.paint.LinearGradient;
import javafx.scene.paint.Stop;
import javafx.scene.shape.Rectangle;
import javafx.scene.Scene;
import javafx.scene.text.Font;
import javafx.scene.text.FontWeight;
import javafx.scene.text.Text;
import javafx.stage.Stage;
import javafx.scene.Group;
import javafx.scene.input.MouseEvent;
* @author rvagvala
// place your code here
var rect = Rectangle {
width: 150
height: 50
arcWidth: 20
arcHeight: 20
stroke: Color.BLACK
strokeWidth: 1
fill: LinearGradient {
startX: 0.0
startY: 0.0
endX: 0.0
endY: 1.0
proportional: true
stops: [
Stop {
offset: 0.0
color: Color.LIGHTBLUE
Stop {
offset: 1.0
color: Color.BLACK
var text1 : Text;
text1 = Text {
content: "Button"
fill: Color.WHITE//Color.RED
font: Font.font("Arial", FontWeight.BOLD, 14)
x: bind rect.x + rect.width/2 - 20
y: bind rect.y + rect.height/2
var text2 : Text;
var opac = 0;
text2 = Text {
content: "Button"
fill: Color.BLACK
font: Font.font("Arial", FontWeight.BOLD, 14)
x: bind rect.x + rect.width/2 - 20 + 1
y: bind rect.y + rect.height/2 - 1
opacity : bind opac
Stage {
title: "Stylish Buttons Demo"
width: 800
height: 600
scene: Scene {
fill: Color.BLACK
content : Group {
translateX: 50
translateY: 50
content: [
rect,
text2,
text1
onMouseClicked: function(e:MouseEvent){
if(opac==0) then opac = 1 else opac = 0;
====================================================================================================================
Thanks for your help .
bye
Edited by: vrakesh.techie on Oct 22, 2009 7:07 AM
Edited by: vrakesh.techie on Oct 22, 2009 7:08 AM

Similar Messages

  • Question on using Java Buttons,Vista Buttons in Java

    Hi All,
    In the internet i have seen some softwares like vista buttons4.0..etc..etc which creates stylished buttons with different text style and colors .But if i want to use the same created button inside my java application.How is it possible??
    regards,
    Viswanadh

    To Mr. Viswanadh: cross-posting can frustrate anyone who tries to help you only to find out later that the same answer was given hours ago in a cross-posted thread. No one likes wasting their time, especially a volunteer. The polite thing to do would be to not do this, but if you feel that you absolutely must, to at least provide links in both cross-posts to each other.

  • How can we prevent back button  using java script

    how can we prevent back button using java script

    Would be quicker for you to google for javaScript
    javascript:window.history.forward(-1);

  • Transparent Buttons in Java Swing?

    Hi!
    I want to create transparent Buttons using java swing for my desktop application. Can any one tell me how to do it?

    I can help, but it depends on what you mean by "transparent".
    Do you mean TOTALLY transparent, or slightly transparent, or merely translucent? Do you want the text on the button to be in any way transparent? You really need to be more specific.
    Basically, though, the concept is pretty simple. All swing components have several methods that can be overridden by somebody who knows what they are doing, in order to customize their appearances.
    Some of these are: paint(), paintComponent(), ComponentUI.paint(), etc.
    You need to determine the right place to put the new code. Then you extend the class, and change the transparency of the graphics object passed into the method in question, and then pass control to the super implementation of that method.
    There are some traps you need to make sure you avoid, though:
    1. If you want transparent components, you MUST have the opaque property of the component set to false. Otherwise, the components beneath your transparent button will never update.
    2. When you start messing with a graphics object to create transparency, you need to make sure that you revert your changes to the graphics object when you are finished, because all painting uses the same graphics object -> so if you set your button transparent, and then forget to remove the transparency, all objects drawn after the button will also be drawn transparent.
    A word of caution:
    This sort of manipulation is not hard, but you NEED to understand the painting model for SWING. There are a few articles hosted by sun that can help you in this respect.
    Good Luck!
    - Adam

  • Is it possible to create round shape button in java

    i have following questions, if possible plz. help me.
    1) is it possible to create round shape i.e circular shapes button using java program.
    2) is it possible to access the floppy and format it using java program. (if it is not possible to format it then plz. tell me how to access the floppy using java program).
    if possible plz. send me code of that programs on following address..
    [email protected]
    waiting for reply.
    prasad.
    (faculty of ssi)

    i have following questions, if possible plz. help me.
    1) is it possible to create round shape i.e circular
    shapes button using java program.
    Yes - GUI Components paint themselves through the invocation of their paint(Graphics) method. Create a subclass of JButton and override the method to paint a circle.
    public void paint(Graphics g) {
      //work out where you want to put the circle, x_pos, y_pos etc
      g.drawArc(x_pos, y_pos, width, height, 0, 360);
    }or some such. Note that since Java 1.2, the object that gets passed in to this method is actually a Graphics2D Object (subclass of Graphics). This provides extra methods.

  • How i will see print Preview of an excel by clicking a button in java

    hi,
    I have created an excel file from java. Now i want to see the print preview of this file by clicking a button in java? Is it possible in java? I have used JExcelApi for this. Is there anybody can help me?
    This is my code:
    package image_handle;
        import jxl.Workbook;
        import jxl.write.*;
        import java.io.*;
        import javax.print.*;
        import javax.print.attribute.*;
    import javax.print.attribute.standard.*;
        public class Excel {
          public Excel(String name) {
           try{
            Workbook wb= Workbook.getWorkbook(new File("report.xls"));
           WritableWorkbook copy=Workbook.createWorkbook(new File("Workbook.xls"),wb);
          WritableSheet sheet = copy.getSheet(0);
          Label label = new Label(0,1,"Bina");
          sheet.addCell(label);
          Label label1 = new Label(1,1,"187");
          sheet.addCell(label1);
          WritableImage image = new WritableImage(2,3,2,4,new File(name));
          sheet.addImage(image);
          copy.write();
          sheet.p
           copy.close();
          catch(Exception ex){
            ex.printStackTrace();
    }I need solution urgently. PLease help me.
    With regards
    Bina

    Multi-Post
    http://forum.java.sun.com/thread.jspa?threadID=731384&tstart=-1

  • Multifunction buttons in JAVA

    Hi I am new to Java. I need to make a GUI that will contain triangular shaped buttons. The trianglular button is supposed to be divided into three parts starting from the vertex down to the base of the triangle. The button controls the speed of a motor. Clicking it on the top part should give a 100% speed command to the motor.Clicking it somewhere in the middle should run the motor at 60% speed and clicking it at the bottom part should make the motor run at 30% speed. I was wondering if there is such button in Java that allows us to call three different function if we click it in three different places...

    Nope, you'll need to build one.

  • How to add control buttons using Java thorugh serial port?

    Hi everyone,
    I'm new to this forum.
    I have some questions on Java and serial port.
    I want to write a Java program to control my robot, through serial port. For example, when I click "Forward", the robot will go forward, and so on.
    Now I already have the buttons, so next I would like to ask how to interface the buttons with the serial port.
    I already have all the javax.comm things installed.
    below is the code for my buttons:
    import java.awt.*;
    public class ControlButtons extends java.applet.Applet
         GridLayout myLayout = new GridLayout(3, 3);
         Button button1 = new Button(" ");
         Button buttonForward = new Button("Forward");
         Button button2 = new Button(" ");
         Button buttonLeft = new Button("Left");
         Button buttonStop = new Button("Stop");
         Button buttonRight = new Button("Right");
         Button button3 = new Button(" ");
         Button buttonReverse = new Button("Reverse");
         Button button4 = new Button(" ");
         public void init()
              setLayout(myLayout);
              add(button1);
              button1.setVisible(false);
              add(buttonForward);
              add(button2);
              button2.setVisible(false);
              add(buttonLeft);
              add(buttonStop);
              add(buttonRight);
              add(button3);
              button3.setVisible(false);
              add(buttonReverse);
              add(button4);
              button4.setVisible(false);
    }Now I would like to ask for direction on how to add in the code to make it work with serial port.
    Thanks

    The plan is, I have a robot device connected to the serial port.We don't know anything about that device. We don't know how to control it. We don't know what you have to write to the device to make it do anything. Only you know what.
    For example, when I click "Forward", the robot will go forward, and so on.So what do you have to send to make it do that? and same for the other buttons.
    Next, you need to work out from the javax.comm API how to open the serial port and send data to it. This is a standard exercise in learning a new API. You must be able to do this. Again and again.
    But the program is useless. The button can be clicked, but didn't do anything.Because (a) they have no ActionListeners and (b) there is no code to send anything to the serial port.
    You have to write all that. So you also have to look up ActionListener in the Java API and how to attach it to a button. You can do that. We all do that kind of thing every day.
    So next I would like to ask how to interface the buttons with the serial port.You've been asking nothing else since you started, but you've also only done enough investigation of your own to create the buttons. That's only the start.
    The problem is what method and command should I use to make those buttons actually functioning.See above. You've been told part of it several times. The rest only you can answer, because it's your robot.

  • Clicking a htmlb:button via Java Script

    Hi all!
    I would like to 'click' a htmlb:button via Java Script.
    Example with a html-button:
    <htmlb:button id="b1" onClientClick="javascript:document.form_id['b2'].click()" text="Call Button 2"/>
    <input id="b2" type="button" onclick="alert('2')">
    Does anybody have an idea how it works with a htmlb:button?
    Thanks!
    Stefan
    Message was edited by: Stefan Kittsteiner

    Hi Stefan,
    Use this
    <script>
    function submit()
      return htmlbSL(this,2,'b2:b2Click');
    </script>
    <htmlb:button id="b1" onClientClick="javascript:submit()" text="Call Button 2" />
    <htmlb:button id="b2" onClientClick="alert('I am clicked')" text="Button 2" />
    b2Click is server event for button 'b2'.
    You can also use <bsp:htmlbEvent> for more details see weblog  <a href="/people/brian.mckellar/blog/2004/07/18/bsp-in-depth-using-the-htmlb-event-system In-Depth: Using the HTMLB Event System</a>
    Regards,
    Narinder Hartala

  • Problem with one of my buttons in java swing

    Gary,
    I am trying to create a button that will link to my .txt file located on my desktop then when I go to display button and press it there are errors coming up that I dont get. The display button should display the results of the previous search inside in a textArea I was wondering if you could help me
    Rgds
    Tony
    Here is the code
    //creates a button that can be used to display the results in the text area
    display_button = new JButton("Display results on text area");
    display_button.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent event_performed)
    try
    URL url = null;
    String line;
    InputStream in = url.openStream();
    BufferedReader dis = new BufferedReader(new InputStreamReader(in));
    buffer = new StringBuffer();
    while((line = dis.readLine()) != null)
    buffer.append(line + "\n");
    in.close();
    catch(IOException file_error)
    textArea.append("IO Exception = " + file_error);
    // Load the file into the TextArea.
    textArea.append(buffer.toString());
    } //End of display button actionPerformed
    }); //End of display_button actionListener
    The resulting errors are:
         at tony_buckley_project.Applet2.readFile(Applet2.java:330)
         at tony_buckley_project.Applet2.start(Applet2.java:356)
         at tony_buckley_project.Applet2$3.actionPerformed(Applet2.java:250)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1764)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:1817)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:419)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:257)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:245)
         at java.awt.Component.processMouseEvent(Component.java:5134)
         at java.awt.Component.processEvent(Component.java:4931)
         at java.awt.Container.processEvent(Container.java:1566)
         at java.awt.Component.dispatchEventImpl(Component.java:3639)
         at java.awt.Container.dispatchEventImpl(Container.java:1623)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3450)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3165)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3095)
         at java.awt.Container.dispatchEventImpl(Container.java:1609)
         at java.awt.Window.dispatchEventImpl(Window.java:1590)
         at java.awt.Component.dispatchEvent(Component.java:3480)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:450)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:197)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:144)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)

    One problem that i can see from your code is that you are writing
    url = null;
    and then
    InputStream in = url.openStream();
    should give u an exception right there...

  • SAVE AS BUTTON WITH JAVA SCRIPT FOR MOUSE UP EVENT

    Please any one help with complete code for "SAVE AS" button to auto save the acrobat form in a user specified path
    with unique name or incremental name.Please post only full script for MOUSE UP event.

    Thanks George but i need an example.my actual need is
    i have created a SAVE INVOICE button.i have set the action"Mouse up" to run a Java script.
    Now i need a scriprt for the same.
    If i press that SAVE INVOICE button.the fie should save on "C:\Users\MUNNA\Desktop" automatically
    with unique name and the name should not remain same for next Save.because it overwrites the previous
    file so please post an example pdf with same.

  • How to send a mail by ckicking the button using java

    hi,
    how to send a mail by clicking the button (like payroll silp in that contain one button if we click that it autometically go through the mail as a attachment) pls frd to me my gmail is [email protected]

    Hi,
    It seems we are doing the homework for you; to make you start with something; look at the sample code below and try to understand it first then put the right values
    to send an email with an attachement.
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.util.Date;
    import java.util.Properties;
    import javax.activation.DataHandler;
    import javax.activation.FileDataSource;
    import javax.mail.Message;
    import javax.mail.MessagingException;
    import javax.mail.Multipart;
    import javax.mail.Session;
    import javax.mail.Transport;
    import javax.mail.internet.InternetAddress;
    import javax.mail.internet.MimeBodyPart;
    import javax.mail.internet.MimeMessage;
    import javax.mail.internet.MimeMultipart;
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.JButton;
    import javax.swing.JComponent;
    import javax.swing.JFrame;
    import javax.swing.JTextField;
    public class Main {
          * @param args
         public static void main(String[] args) {
              // Create the frame
              String title = "Frame Title";
              JFrame frame = new JFrame(title);
              // Create a component to add to the frame
              JComponent comp = new JTextField();
              Action action = new AbstractAction("Button Label") {
                   // This method is called when the button is pressed
                   public void actionPerformed(ActionEvent evt) {
                        System.out.println("sending email with attachment");
                        sendEmail();
              // Create the button
              JButton button = new JButton(action);
              // Add the component to the frame's content pane;
              // by default, the content pane has a border layout
              frame.getContentPane().add(comp, BorderLayout.SOUTH);
              frame.getContentPane().add(button, BorderLayout.NORTH);
              // Show the frame
              int width = 300;
              int height = 300;
              frame.setSize(width, height);
              frame.setVisible(true);
         protected static void sendEmail() {
              String from = "me@localhost";
              String to = "me@localhost";
              String subject = "Important Message";
              String bodyText = "This is a important message with attachment";
              String filename = "c:\\tmp\\message.pdf";
              Properties properties = new Properties();
              properties.put("mail.stmp.host", "localhost");
              properties.put("mail.smtp.port", "25");
              Session session = Session.getDefaultInstance(properties, null);
              try {
                   MimeMessage message = new MimeMessage(session);
                   message.setFrom(new InternetAddress(from));
                   message.setRecipient(Message.RecipientType.TO, new InternetAddress(
                             to));
                   message.setSubject(subject);
                   message.setSentDate(new Date());
                   // Set the email message text.
                   MimeBodyPart messagePart = new MimeBodyPart();
                   messagePart.setText(bodyText);
                   // Set the email attachment file
                   MimeBodyPart attachmentPart = new MimeBodyPart();
                   FileDataSource fileDataSource = new FileDataSource(filename) {
                        @Override
                        public String getContentType() {
                             return "application/octet-stream";
                   attachmentPart.setDataHandler(new DataHandler(fileDataSource));
                   attachmentPart.setFileName(filename);
                   Multipart multipart = new MimeMultipart();
                   multipart.addBodyPart(messagePart);
                   multipart.addBodyPart(attachmentPart);
                   message.setContent(multipart);
                   Transport.send(message);
              } catch (MessagingException e) {
                   e.printStackTrace();
    }The sample above is not ideal so you need to go through it and start to ask me some questions if you have
    Let me know if you miss something
    Regards,
    Alan Mehio
    London,UK

  • How to disable a button using Java Script in Apex

    Hi All,
    I was trying to disable a button when the value of a select list item in the same page is equal to zero. Following are the steps which I did.
    1) Created a new button template as <table class="t9StandardButton" id="#BUTTON_ID#" cellspacing="0" cellpadding="0" border="0" summary="">
    2) Changed the existing button template to the newly created button template.
    3) Added onchange="javascript:fdisplay(this);" to form element value of select list
    4) Added the following java script in the page header
    <script type="text/javascript">
    function fdisplay(some) {
    if (some.value==0){
    html_GetElement ('#BUTTON_ID#').disabled = true;
    else
    html_GetElement ('#BUTTON_ID#').disabled = false;
    </script>
    But the script doesn't work. Is there anything I am missing here. Please advice.
    Thanks,
    Vikas

    Vikas:
    In the 'Button Attributes' field of the button enter 'id='thisButton'.
    Modify the button template to include the substitution string #BUTTON_ATTRIBUTES# . This should be put in the anchor tag in the template defintion.
    Modify your Javascript to reference the above id as
    html_GetElement ('thisButton').disabled = true;
    ....Varad

  • Draggable buttons in Java Swing

    Hi,
    I want to develop an application in Java Swing. The application I am going to develop is an application for developing other applications. I want my application to include a button which also acts as a drag and drop UI element. For example, I want my application to include a button for adding a picture. There are 4 buttons of different pictures. If a user wants to add a picture he can either click on one of these buttons and that picture will be added somewhere on the screen or dragging this button and drop it and that picture will be added where he dropped that button.
    Could anyone please tell me…
    1. If I can develop an application which includes Drag and Drop UI element if I develop it in Java Swing
    2. If a button (or other UI element) can act as both a button and a drag and drop element if I develop my application in Java Swing
    3.
    Could you please tell me where I can find some screenshots of applications which has been developed in Java Swing? I am not familiar with this program and I am not that good at programming, so I would like to get some impression of how it might look like.
    Thanks in advanced

    1. the good thing about Swing is that it is very flexible and with clever programming you can do just about anything. The problem is that depending on your requirements, this could require a great deal of programming that can be very hard to implement such that it works properly on all popular platforms (windows, linux, mac).
    2. see 1.
    3. Swing applications are "skinnable", you can give them a great number of different appearances. The default is to give the application a system look and feel, so they look pretty much like any other application for that platform. This means that when you run your application on Windows, it will look like a Windows application, if you run it on a Mac it will look like a Mac application, etc.
    I am not familiar with this program and I am not that good at programmingThat is quite a problem, because Swing is not the easiest API around. It requires a solid knowledge of Java and Object Oriented Programming in general as the entire API is based heavily on OOP concepts. To get a better idea of Swing, read through the Swing tutorial here:
    http://java.sun.com/docs/books/tutorial/uiswing/

  • Help in Button in Java

    so,
    I have a two-dimensional array of Button, each one is located in a different location on the graphic screen.
    some of the raws are initialized, but some are "null".
    i hava a different one Button and i want to check whether the Button is located at the location of one of the array's cells - and this particular cell is "null" - so to initialize this cell with the data of the other Button, and then this button become to be "null" or setVisible(false)
    my problem is that i couldn't succeed to write the exact code that can fill this condition, because i couldn't think how to check whether this cell is the cell we're talking, or the one to the left, or the one to the right - because they're all close to each other, and i need to check if some cell is more (!!!) contains the one-Button than the others.
    i would like to get some help!
    please....
    thank you!!! :)

    Note: This thread was originally posted in the [Java Programming|http://forums.sun.com/forum.jspa?forumID=31] forum, but moved to this forum for closer topic alignment.

Maybe you are looking for

  • Method of getting values from parameter ID to a form

    Hi,    Is it possible to get the value of a parameter ID from a FORM? If so, can you please give me the code to do it. Thanks Lilan

  • Presentation server is not running

    Hi, When I am starting presentation server i am getting the below error . Windows could not start the BI presentation server on local machine. Then i verified the log file C:\OracleBIData\web\log\sawlog0 Invalid item \\?\C:\OracleBIData\web\catalog\s

  • XmlParser exception

    SimpleXmlParser smp=new SimpleXmlParser(ifsSession); This gives a warning that it is deprecated. Also gives a run time error : Exception in thread "main" java.lang.NoClassDefFoundError: oracle/xml/parser/v2/XMLParseException at ParserTest.main(Parser

  • OSX Mail : reply all - my email address is also in to/cc field

    When i receive an email, and i hit Reply All, my email address is also in the TO or CC field. There is nowhere an option to disable this behavior. I got this situation : TO : email addresses of friends and my email address FROM : my email address How

  • File not found result code = -43

    For some unknown reason , Everytime I record an audio track then  attempt to edit it  by clicking on the sample edit tab the window opens up I'll select Time & pitch , Already highlighting the area on the waveform that needs to fixed with Time/Pitch