Strange behavior with System.out.println

I was working with the following code:
1. public class DemoChar {
2. public static void main(String args[]) {
3.
4. char buf[] = new char[50];
5. buf[0] = 'a';
6. buf[1] = 'b';
7. buf[2] = 'c';
8. buf[3] = 'd';
9. buf[4] = 'e';
10. System.out.println( buf);
11. }
12. }
if you print "buf", it really works; however if you change line 10 by :
System.out.println("--->" + buf );
The method "println()" doesn't write "--->abcde". The functionality doesn't the same. It will appear "----> [C@3e25a5"
Could you help me?
I don't understand that behavior. I am using "java version 1.6.0_07"

buf's an array and thus is an object. object's don't inherently know how to represent themselves as Strings, so you have to do other things to make sure that they print out ok. To get a char array to print well, you could use the String method valueOf(...):
public class DemoChar
  public static void main(String args[])
    char buf[] = {'a', 'b', 'c', 'd', 'e'};
    System.out.println(buf);  // this seems to call implicitly String.valueOf(buf)
    System.out.println("--->" + buf);  // this however seems to call buf.toString() with different results
    System.out.println("--->" + String.valueOf(buf));
}Also, when posting your code, please use code tags so that your code will retain its formatting and be readable. To do this, you can will need to paste already formatted code into the forum, highlight this code, and then press the "code" button at the top of the forum Message editor prior to posting the message. You may want to click on the Preview tab to make sure that your code is formatted correctly. Another way is to place the tag [code] at the top of your block of code and the tag [/code] at the bottom, like so:
[code]
  // your code block goes here.
  // note the differences between the tag at the top vs the bottom.
[/code]or
{code}
  // your code block goes here.
  // note here that the tags are the same.
{code}Edited by: Encephalopathic on Aug 21, 2008 9:40 AM

Similar Messages

  • Can't run java apps with System.out.println on any builder.

    Hello,
    I'm currently using Vista RC2, which is the immediate problem.
    Classes with System.out.println won't launch the console window. As I'm a student and practicing on these steps, I do have quite a problem on my hands. I click on run, build succesfull, nothing happens.
    I have tried Netbeans and Jcreator, and gave up on trying different builds, as I reckon I'll have to find some other way to counter this; any way to get println messages working in vista?

    It is run as a desktop app, and other runs with commands such as JOptionPane do function, only the println windows don't appear at all. So I think JRE is installed and working.
    I did notice there was one command for input where I'd be able to enter it at the bottom of Netbeans.
    Like just now I clicked build and run for the following code
    import java.util.*;
    public class FirstProgram
        public static void main(String[] args)
            System.out.println("Hello out there.");
            System.out.println("I will add two numbers for you.");
            System.out.println("Enter two whole numbers on a line:");
            int n1, n2;
            Scanner keyboard = new Scanner(System.in);
            n1=keyboard.nextInt();
            n2=keyboard.nextInt();
            System.out.println("The sum of those two numbers is");
            System.out.println(n1+n2)
    }Resulting in a brief flash of "input" in the output window (which is below the coding window) and it dissapears. But this also occurs when I don't include system scanner code.
    Using commands in cmd
    java -jar "C:\Users\Alegis\Netb\MyApp\dist\MyApp.jar"
    Does not yield desired results either. Nothing happens.

  • Problems with System.out.println()

    I tried writing a simple 'Hello world'-program:
    public class Test{
         public static void main(String[] args){
              System.out.println("Hello World!");
         }//main()
    }//Test
    But the text wouldn't appear in the DOS-window. The only text that showed up was the standard 'Press any key to close the window'. The program compiled without any problems, but didn't work when I tried to run it.
    Does anyone have any idea what's wrong?

    Are u sure , the main() class part is donecorrectly.
    Becuse program will compile but not run without a
    main() class.what do you mean by main() class???First of all main() is a method, not a class. The main() method the JRE recognizes and runs is the:
    public static void main(String[] params)
    If you don�t have exaclty those modifiers and receive an array of Strings parameter it will send you an runtime exception.
    Your code compiles and runs fine, the problem isn�t really System.out.print() it is something with your configuration.
    I have to rename the class to TestF. Here is the running:
    C:\cJava>javac TestF.java
    C:\cJava>java TestF
    Hello World!

  • Strange behavior with System Preferences involving Guest Account

    I work for a company that primarily uses macs and I have recently been asked to enable the Guest Account on all of them (as well as a general staff login). In doing this, I have come across at least one computer (they all run 10.5.5 or 10.5.6) where it seems impossible to enable the Guest Account. Here is what happens:
    1. I open System Preferences, go to the Accounts pane, authenticate, and click on the Guest Account.
    2. I check the option to "Allow guests to log into this computer" and a little busy sign shows for a second.
    3. I click on another account in the list on the left.
    4. When I click back to the Guest Account, the checkbox is unchecked. Also, the Guest Account does not appear in the fast user switch menu.
    After tinkering around a little bit, I found that there was a "Guest" home folder in the Users folder. I thought that this was strange because I thought that this folder is created when you actually log into the guest account (I checked on another computer and found that this was indeed the case). I then deleted this "Guest" home folder and emptied the trash.
    I again went through the same steps I did above (with a Finder window on the Users folder displayed) and found that when I check the box to enable the Guest Account, a "Guest" home folder appears in the Users folder. I deleted and repeated this process a number of times, all with the same result. I then began looking around for other occurrences of this problem.
    At some point, I came across this discussion, which seemed to pose a possible solution: http://discussions.apple.com/thread.jspa?messageID=9176908#9176908
    As suggested in that thread, I tried creating a standard user with a home folder by the name of "Guest" or "guest". I filled in all the fields but when I clicked on "Create Account", it seems to work and then goes back to the Accounts preference pane except that the account I just created +*is not there!*+ I then tried this while the "Guest" home folder existed in the Users folder and it brings up a window asking whether I want to use the current "Guest" home folder as the home folder for the new account. Even if I click OK, +*the account still does not appear.*+
    Does anyone know what is going on here? The next thing I'll try is an archive and reinstall, but a quicker fix would be nice, since the former involves running all the updates again (we don't have current versions of the Leopard install disks).
    I would be very grateful if anyone has an answer.
    -Nik

    As it turns out, the Guest folder behavior is actually normal, but I still have not figured out why the guest account still doesn't work. My next step will be to try a disk repair. I've repaired the permissions, but that didn't seem to help as far as I know. I'll also try reinstalling the combo updater to 10.5.6 (as suggested by a co-worker) and see if that does anything. Last resort is the archive and reinstall.

  • System.out.println not showing up in the console

    Hi,
    I've some System.out.println statements in a static block in a Stateless
    Session Bean. I could not see these outputs in the Weblogic console. I'm
    using Weblogic 5.1 Any one faced this problem before? any help is
    appreciated.
    Thanks & Regards,
    Nithi.

    Take a look in the weblogic log files they might be redirecting std out.
    "Ryan LeCompte" <[email protected]> wrote:
    >
    Hello Nithi,
    I'm all out of ideas, unfortunately! However, check out the following
    links for
    some possible insight into the problem:
    http://groups.google.com/groups?q=System.out.println+5.1+WebLogic&start=60&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3d3df18e%40newsgroups.bea.com&rnum=69
    http://groups.google.com/groups?q=System.out.println+5.1+WebLogic&start=70&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3977417b%40newsgroups.bea.com&rnum=71
    http://groups.google.com/groups?q=System.out.println+5.1+WebLogic&start=200&hl=en&lr=&ie=UTF-8&oe=UTF-8&selm=3bc20346%241%40newsgroups.bea.com&rnum=209
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669
    "Nithi Rajan" <[email protected]> wrote:
    Hi Ryan,
    Thanks for your reply and sorry for the long silence. I was on vocation.
    Thre problem still remains.I'm very sure that the EJB
    is deployed by WebLogic as I'm able to call some methods.
    and I'm also calling EJB methods from Servlet. But my
    System.out.println statments work fine in the Servlet and
    not inside EJB (or anyother classes used by EJB).
    Any one has faced similar problems? BTW am using WebLogic 5.1
    Thanks in advance,
    Regards,
    Nithi.
    "Ryan LeCompte" <[email protected]> wrote in message
    news:[email protected]...
    Hello Nithi,
    I find it strange that your System.out.println statements are beingexecuted from
    within your servlets, but not in your stateless session bean. Are
    you
    positive
    that your EJB is being located and deployed by WebLogic? The statementsin
    your
    static { } block should be executed as soon as the WebLogic class
    loader
    finds
    the class and loads it into the JVM. I would suggest examining theconsole
    and
    try to determine if your EJB is in fact being deployed. Are you invokingmethods
    on the EJB inside of your servlets? Are you using any logging frameworkfrom within
    the EJBs which would redirect output to a file?
    Best regards,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669
    "Nithi Rajan" <[email protected]> wrote:
    Hi Ryan,
    Thanks for your reply. The setting in the weblogic.properties is
    as
    follows.
    weblogic.system.enableConsole=true
    So, that tells me that I should see all the System.out.printlns right?
    (Pleasecorrect me if I'm wrong). I can see all the System.out.println
    from
    my
    servletand not from the Session Bean (even if the System.out.println
    is
    outside
    static block).
    Please let me know your thoughts.
    Thanks & Regards,
    Nithi.
    "Ryan LeCompte" <[email protected]> wrote in message
    news:[email protected]...
    Hello Nithi,
    Are you sure that you don't have WebLogic configured to redirect
    all
    messages
    to a file instead of the console? Are you able to see yourSystem.out.println
    statements when placed within other methods of your stateless sessionbean? Please
    be a bit more specific.
    Thank you,
    Ryan LeCompte
    [email protected]
    http://www.louisiana.edu/~rml7669
    "Nithi Rajan" <[email protected]> wrote:
    Hi,
    I've some System.out.println statements in a static block in a
    Stateless
    Session Bean. I could not see these outputs in the Weblogic console.
    I'm
    using Weblogic 5.1 Any one faced this problem before? any helpis
    appreciated.
    Thanks & Regards,
    Nithi.

  • Linux System.out.println()

    I am porting some JSP's from Windows to SUSE Linux. These JSP's call functions that are embedded in JAVA classes, which in turn output error messages with System.out.println() to the console. It appears that in Linux, the bash Konsole doesn't print these errors, so they are invisible.
    I suppose that if I wrote JSP's in the future, errors could be printed in the browser, but I would really like to be able to see my errors in bash or which ever shell. Any help would be appreciated.

    If you ever intend to use more than one webserver, I would suggest you look towards something like JMS. Messages can be sent to the queue from which you can pick them up and deal with them as necessary in your own time, be that real-time or delayed.
    If you think you will never need more than one, why not write a little log file reader? Remember though that the catalina.out file will grow and grow unless you stop Tomcat, rename the old file and restart Tomcat.

  • How can I show a System.out.println(""); into a JSP?

    Is a simple doubt that would help me a lot to reach other thing that I wished reach with a JSP.
    Thank you!!!

    Hi!!!
    Thank you to answer me......my question�is because�my problem is a little more complicated��let me tell you�.
    My problem is that I wish to do some queries to a table of a Municipalities DB, I have read about that....and according with the exemples....my JSP...should be running and executing very well....but I haven�t had success with that...:(
    My JSP file is:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    stmt.execute("select * from cat_municipio");
    ResultSet rs = stmt.getResultSet();
    while (rs.next()) {
    System.out.println(rs.getInt("cve_municipio") + " - " + rs.getInt("cve_sepomex") + " - " + rs.getString("desc_municipio"));
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    My result obtained is the following:
    Municipalities List
    Please call Mary with any updates ASAP!
    Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    I don�t obtain nothing.....is like DB table were without information......but in reality the DB table has information.....and I can obtain it with the following JSP:
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    // Fetch all records from the database in a TableDataSet
    DataSet dSet = new TableDataSet(conn, "cat_municipio").fetchRecords();
    TableElement tE = new TableElement(dSet);
    tE.setBorder(1);
    out.print(tE);
    } catch (SQLException sqle) {
    out.print("Sorry, the database is not available.");
    out.print("Exception: " + sqle);
    } catch (Exception e) {
    out.print("Exception occured: " + e);
    } finally {
    if(conn != null)
    try {
    conn.close();
    } catch(SQLException sqle) {}
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>
    and with this JSP I obtain all the following information:
    Municipalities List
    CVE_MUNICIPIO CVE_SEPOMEX DESC_MUNICIPIO
    1 1 ACAJETE
    2 2 ACATENO
    3 3 ACATLAN
    4 4 ACATZINGO
    5 5 ACTEOPAN
    Now...I need that the first JSP work very well, because...with that way...I can do queries and obtain the needed results for showing them in the Browser......
    So, I already find out�.that�any string that I send to the browser with System.out.println(); isn�t showed�.so it is the reason of my question�..how I can see my results of a query using a loop (like a for, while) resolving it....I think my problem would be resolved.
    So...I hope you understand me, and you could help me please...thanks.....
    Mary
    P.D. I also attempted with the following JSP...but the result is the same....I don�t obtain none result...
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <!-- Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.-->
    <head>
    <title>Query of Municipalities</title>
    </head>
    <body bgcolor=#FFFFFF>
    <font face="Helvetica">
    <h1>
    <font color=#DB1260>
    Municipalities List
    </font>
    </h1>
    <%@ page import="
    weblogic.db.jdbc.*,
    weblogic.html.*,
    java.sql.*
    " %>
    <p>
    <%
    Connection conn = null;
    try {
    Class.forName("weblogic.jdbc.pool.Driver").newInstance();
    conn = DriverManager.getConnection("jdbc:weblogic:pool:DESAPool");
    catch (Exception e) {
    e.printStackTrace();
    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("select CVE_MUNICIPIO, CVE_SEPOMEX, DESC_MUNICIPIO from cat_municipio");
    while (rs.next()) {
    System.out.println(rs.getInt(1) + " - " + rs.getInt(2) + " - " + rs.getString(3));
    rs.close();
    stmt.close();
    conn.close();
    %>
    <p>Please call Mary with any updates ASAP!
    <p>
    <font size=-1>Copyright (c) 1999-2000 by BEA Systems, Inc. All Rights Reserved.
    </font>
    </font>
    </body>
    </html>

  • Override System.out.println()

    Guys,
    I know that "System" is a final class and I can't override it.
    But "PrintStream" is not a final class and it contains "println(Object)"
    method in it. So, I can override it, right?
    My basic requirement is, when I have a program with
    System.out.println("sreedhar");
    say, it should display me something like
    Oct 11, 2007 4:05:05 PM INFO: sreedhar.
    ie. I want to override S.o.p to Logger.info (where Logger is from log4j; or for that matter from commons-logging or JDK logging).
    Can this be done by changing System.java, dropping System.class in tools.jar?

    System has this method. With its help, you can use your own (prepending, timestamping etc.) PrintStream object:
    public static void setOut(PrintStream out)
    //    Reassigns the "standard" output stream.Kaj was faster.
    Edited by: BIJ001 on Oct 12, 2007 8:43 AM

  • System.out.println() Print to JFrame

    I just wrote a rather large java application and now want to develop a GUI for it. I have never developed GUI and am trying to use the API's for help. Can anyone point me in the right direction: I am trying to take everything that is printed out with System.out.println() and print it inside a JFrame. Any help would be magnificent.
    -Alex

    Add a JTextArea to your frame, create a TextAreaOutputStream with it, and use System.setOut(...) to set System.ouot
    * Created on Mar 13, 2005 by @author Tom Jacobs
    package tjacobs;
    import java.io.IOException;
    import java.io.OutputStream;
    import javax.swing.JTextArea;
    import javax.swing.text.JTextComponent;
    * TextAreaOutputStream creates an outputstream that will output to the
    * given textarea. Useful in setting System.out
    public class TextAreaOutputStream extends OutputStream {
         public static final int DEFAULT_BUFFER_SIZE = 1;
         JTextArea mText;
         byte mBuf[];
         int mLocation;
         public TextAreaOutputStream(JTextArea component) {
              this(component, DEFAULT_BUFFER_SIZE);
         public TextAreaOutputStream(JTextArea component, int bufferSize) {
              mText = component;
              if (bufferSize < 1) bufferSize = 1;
              mBuf = new byte[bufferSize];
              mLocation = 0;
         @Override
         public void write(int arg0) throws IOException {
              //System.err.println("arg = "  + (char) arg0);
              mBuf[mLocation++] = (byte)arg0;
              if (mLocation == mBuf.length) {
                   flush();
         public void flush() {
              mText.append(new String(mBuf, 0, mLocation));
              mLocation = 0;
              try {
                   Thread.sleep(1);
              catch (Exception ex) {}
    }

  • Difference between System.out.println(..)and PrintWriter.println(..)

    Hello every one
    With System.out.println(..) we can print to Console.
    But System.out internally creates PrintWriter object.So why cant we use
    PrintWriter.println(..) directly to write to console.
    Is there aany disadvvantage with PrintWriter.println(..).
    If so can anyone please tell me what is that and
    what is the advantage we r going to get with System.out.println(..) method of writing to console.

    kirn291 wrote:
    With System.out.println(..) we can print to Console.If you want to be very precise, then you have to say that System.out.println() writes to the default output stream. This is usually shown at the console, but can equally well go into a file (if you've redirected it) or nowhere (when running without a console).
    But System.out internally creates PrintWriter object.Not exactly. It refers to a PrintStream object.
    So why cant we use
    PrintWriter.println(..) directly to write to console.Because if you create a PrintWriter it is just another PrintWriter that writes to whatever you specified at the constructor. It is not the same thing as the one PrintStream that is used in System.out.
    what is the advantage we r going to get with System.out.println(..) method of writing to console.The advantage is that it's the only way to do it. Could you post an example of how you'd think of a different way to write to the console?

  • How use system.out.println with a Java Swing Applet?

    Hi guys,
    I was just wondering what can I use to view output on the Java console with a Java Swing Applet?
    At the moment I'm using a JTextArea within the Applet for debugging but I want output to appear in the browser java console but system.out.println doesn't work.
    I'm viewing the Swing Applet on Netscape 4.7 browser.
    Any ideas?

    System.out.println()s work fine! I'm guessing that your problem is that you are looking at the wrong console window!
    You're using the Java Plug-in, right? On Windows, go to your Control Panel and double click "Java Plug-in". You should find a checkbox option to "Show Java Console" - make sure this is checked. Next time you fire up you JApplet, you should see a Java Console window popup.
    Hope this helps!

  • Strange behavior with Collections

    Hello!
    I have a - from my point of view - strange behavior with a List (same also applies to Vector, LinkedList, and others):
    List<String> myList = new myList<String>;
    myList.add("One");
    while (true) {
    try {
    System.out.println(myList.size());
    throw new Exception();
    } catch (Exception e) {
    e.printStackTrace();
    }And the result is 1, 2, 2, 2, ...although I added only one element. The two elements in the List point to the same object.
    What could case this issue?
    Regards,

    len00x wrote:
    List<String> myList = new myList<String>;This doesn't even look like it will compile for at least one reason, easily two.

  • Strange behavior with Bindings??

    Hello to all JavaFX 2 Binding experts,
    I have a strange behavior with Bindings in JavaFX 2.2 (Java 1.7 update 21). Please have a look at the following source code:
    package test;
    import javafx.application.Application;
    import javafx.beans.binding.BooleanBinding;
    import javafx.beans.property.SimpleBooleanProperty;
    import javafx.beans.value.ChangeListener;
    import javafx.beans.value.ObservableValue;
    import javafx.fxml.FXML;
    import javafx.fxml.FXMLLoader;
    import javafx.scene.Parent;
    import javafx.scene.Scene;
    import javafx.scene.control.Label;
    import javafx.scene.control.RadioButton;
    import javafx.stage.Stage;
    public class BindingVsProperty extends Application
        @FXML
        private RadioButton opt11;
        @FXML
        private RadioButton opt12;
        @FXML
        private RadioButton opt21;
        @FXML
        private RadioButton opt22;
        @FXML
        private Label lbl11And21;
      @Override
        public void start(Stage arg0) throws Exception
            FXMLLoader l_loader = new FXMLLoader();
            l_loader.setLocation(BindingVsProperty.class.getResource("BindingVsproperty.fxml"));
            l_loader.setController(this);
            l_loader.load();
            Scene l_scene = new Scene((Parent)l_loader.getRoot());
            arg0.setScene(l_scene);
            useBinding1();
            //useBinding2();
            //useBinding3();
            arg0.show();
        private void useBinding1() // NOT WORKING - ChangeListener.changed(..) is not called
            BooleanBinding l_andOpt11Opt21 = opt11.selectedProperty().and(opt21.selectedProperty());
            l_andOpt11Opt21.addListener(new ChangeListener<Boolean>()
                @Override
                public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2)
                    System.out.println("Opt 1.1 AND Opt 2.1 changed to: " + arg2);
        private void useBinding2() // OK - ChangeListener.changed(..) is called
            BooleanBinding l_andOpt11Opt21 = opt11.selectedProperty().and(opt21.selectedProperty());
            lbl11And21.visibleProperty().bind(l_andOpt11Opt21);
            l_andOpt11Opt21.addListener(new ChangeListener<Boolean>()
                @Override
                public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2)
                    System.out.println("Opt 1.1 AND Opt 2.1 changed to: " + arg2);
        private void useBinding3() // NOT WORKING - ChangeListener.changed(..) is not called
            BooleanBinding l_andOpt11Opt21 = opt11.selectedProperty().and(opt21.selectedProperty());
            new SimpleBooleanProperty(false).bind(l_andOpt11Opt21);
            l_andOpt11Opt21.addListener(new ChangeListener<Boolean>()
                @Override
                public void changed(ObservableValue<? extends Boolean> arg0, Boolean arg1, Boolean arg2)
                    System.out.println("Opt 1.1 AND Opt 2.1 changed to: " + arg2);
        public static void main(String[] args)
            launch(args);
    <?xml version="1.0" encoding="UTF-8"?>
    <?import java.lang.*?>
    <?import java.util.*?>
    <?import javafx.scene.control.*?>
    <?import javafx.scene.layout.*?>
    <?import javafx.scene.paint.*?>
    <BorderPane id="BorderPane" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefWidth="371.0" xmlns:fx="http://javafx.com/fxml">
      <center>
        <AnchorPane prefHeight="200.0" prefWidth="200.0">
          <children>
            <Label id="lblAnd" fx:id="lbl11And21" layoutX="82.0" layoutY="121.0" text="Group1 Opt1 AND Group2 Opt1 is true" textFill="#41cc00" visible="false" />
            <RadioButton fx:id="opt21" layoutX="216.0" layoutY="24.0" mnemonicParsing="false" text="Group 2 - Opt 1">
              <toggleGroup>
                <ToggleGroup fx:id="group2" />
              </toggleGroup>
            </RadioButton>
            <RadioButton fx:id="opt22" layoutX="216.0" layoutY="67.0" mnemonicParsing="false" text="Group 2 - Opt 2" toggleGroup="$group2" />
            <RadioButton fx:id="opt11" layoutX="29.0" layoutY="24.0" mnemonicParsing="false" text="Group 1 - Opt 1">
              <toggleGroup>
                <ToggleGroup fx:id="group1" />
              </toggleGroup>
            </RadioButton>
            <RadioButton fx:id="opt12" layoutX="29.0" layoutY="67.0" mnemonicParsing="false" text="Group 1- Opt 2" toggleGroup="$group1" />
          </children>
        </AnchorPane>
      </center>
    </BorderPane>
    What I need for my application is the use case in useBinding1(), i.e., a BooleanBinding where several listeners are attached to. The problem is that I never get a callback in the ChangeListener if one of the RadioButton.selectedProperty() is changed.
    Now I tried what happens if I use the same BooleanBinding for another binding to a property plus the listener, now the listener gets callbacks as expected! (see useBinding2() )
    Than I thought may be Bindings must be bound in order to trigger listeners and tried useBinding3() where I bind the BooleanBinding to a new BooleanProperty, in this case the listener doesn't get callback anymore...
    And now I'm very frustrated and hope that anyone out there can help me to understand this strange behavior.
    Thanks a lot!
    WhiteAntelope

    All these work just fine for me: the listeners are all called as expected. Note that the listener is only invoked when the value of the binding actually changes, which doesn't happen every time a radio button is pressed. (For example, if both buttons are unselected, the binding is false. If one button is selected, the binding remains false and the listener is not invoked. When the second button is selected, the binding becomes true, and the listener is invoked.)

  • Strange Behavior with Rectangle in BorderPane

    I'm creating a Rectangle, filling it with a gradient, and setting it as the top component of a BorderPane. Then, when the BorderPane expands I also want the Rectangle to expand. And when the BorderPane shrinks I want the rectangle to shrink. The code looks like:
    BorderPane mainLayout = new BorderPane();
            VBox.setVgrow(mainLayout, Priority.ALWAYS);
            getChildren().add(mainLayout);
            Text title = new Text("New Entry");
            title.setFont(Font.font(title.getFont().getName(), title.getFont().getSize() * 1.6));
            HBox titlePanel = new HBox();
            titlePanel.setAlignment(Pos.CENTER);
            //titlePanel.getChildren().add(title);   
            // TODO: How to make this rectangle grow to always fill the form title?
            Stop[] stops = new Stop[] { new Stop(0, Color.STEELBLUE), new Stop(1, Color.WHITE)};
            LinearGradient gradient = new LinearGradient(0, 0, 1, 0, true, CycleMethod.NO_CYCLE, stops);
            final Rectangle r = new Rectangle() {
                @Override
                public boolean isResizable() {
                    return true;
            setFillHeight(true);
            mainLayout.widthProperty().addListener(
                    new ChangeListener<Number>() {
                        @Override
                        public void changed(
                                ObservableValue<? extends Number> observable, Number oldValue, Number newValue) {
                            System.out.println("Setting width to " + newValue);
                            // r.setWidth(newValue.intValue());
            r.widthProperty().bind(widthProperty());
            r.setHeight(100);
            r.setFill(gradient);
            titlePanel.getChildren().add(r);
            mainLayout.setTop(titlePanel);----
    Strangely enough this code works if the BorderPane is expanded to a greater size than it was previously. In this case the ChangeListener will be invoked and widthProperty will But if the BorderPane shrinks then nothing shrinks and the ChangeListener is never called. Is this a bug? Why would the BorderPane be able to expand but to never shrink?
    Any help appreciated, thanks.
    Edited by: ocean on Aug 27, 2011 9:22 AM
    Edited by: ocean on Aug 27, 2011 9:22 AM

    Not sure why, but I managed to fix this issue. The BorderPane in the code snippet above was itself embedded inside a HBox that was itself being embedded inside the center of another BorderPane. I removed the titlepanel from the embedded BorderPane and put it in the top-level BorderPane. There I was able to get the Rectangle to expand and contract as the window was received. This seems to be another "nesting thing" with JavaFX and it's not the first such issue I've run into, particularly with respect to resize behavior. I wish the documentation could be updated so that it's clear how the different nodes, particularly layouts, behave with respect to resizing. Thanks.

  • Strange behavior with assert / catching an AssertionError

    Hello all,
    probably catching an AssertionError doesn't make sence, but the following program produces a strange output and I would like to understand why:
    // run this programm with "-ea"-switch
    // java -ea AssertionTest
    public class AssertionTest {
       * @param args
      public static void main(String[] args) {
        int i = 6;
        for(int ii = 0; ii < 5; ii++) {
          System.out.println("------------------- iteration " + ii + " ----------------");
          try {
            assert (i > 7) : "Honk!";
          catch(Throwable t) {
            System.out.println(" ---before Stacktrace ---");
            t.printStackTrace();
            System.out.println("--- after Stacktrace ---");
    //    assert(i > 7): "Honk!";
    }I would expect the following output:
    ------------------- iteration 0 ----------------
    ---before Stacktrace ---
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    --- after Stacktrace ---
    ------------------- iteration 1 ----------------
    ---before Stacktrace ---
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    --- after Stacktrace ---
    ------------------- iteration 2 ----------------
    ---before Stacktrace ---
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    --- after Stacktrace ---
    ------------------- iteration 3 ----------------
    ---before Stacktrace ---
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    --- after Stacktrace ---
    ------------------- iteration 4 ----------------
    ---before Stacktrace ---
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    --- after Stacktrace ---But most of the time it outputs something wired like this:
    ------------------- iteration 0 ----------------
    ---before Stacktrace ---
    --- after Stacktrace ---
    ------------------- iteration 1 ----------------
    ---before Stacktrace ---
    --- after Stacktrace ---
    ------------------- iteration 2 ----------------
    ---before Stacktrace ---
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    --- after Stacktrace ---
    ------------------- iteration 3 ----------------
    ---before Stacktrace ---
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    --- after Stacktrace ---
    ------------------- iteration 4 ----------------
    ---before Stacktrace ---
    java.lang.AssertionError: Honk!
         at AssertionTest.main(AssertionTest.java:20)
    --- after Stacktrace ---When I slow things down by debugging the program and run it step-by-step, the expected result appears.
    Anybody with an explanation for this?
    Thanks a lot in advance!
    Best regards
    Stephan

    System.out.println goes to stdout. Exception.printStackTrace probably goes to stderr. There are two separate streams sending output to your console, and they may be flushed at different rates.
    You could try flushing System.out after every println and flushing System.err after ever printStackTrace, or you could just println to System.err.
    EDIT: Yup, just checked the docs for printStackTrace. It goes to stderr.
    Edited by: jverd on Apr 18, 2008 3:28 PM

Maybe you are looking for

  • Layout Issue for Operation

    HI All, I am facing an issue of Operation  Layout differ in both Client. Suppose  i i have two client 200 and 201 in that  I am getting an activity type and unloading Point in one client and another client earliest start date and  end date soboth lay

  • How to make a copy of a table in oracle?.

    I have a table. I would like to make an exact copy of the table (except for different name of the table) ..basically like a backup. Thanks!

  • Newbie AE6.5 Pro keyboard shortcut question

    Hi - What is the key shortcut for turning the text tool off? Cmd_+T turns it on, I put in my text, and then want to get to the Selection tool or preview the audio. I wind up with a lot of extra "v's" and ".'s" on my screens. TIA some expert input on

  • How can I use JSF 1.2 components in NetBeans 5.5.1 with VWP

    I need to use requiredMessage and converterMessage, but they are available in JSF 1.2. How can I create a Visual Web Application Project which uses JSF 1.2? Thanks

  • A small clarification in Scripts

    See observe the follwing text which i wrote in a window. 1.&v_var1&   &v_var2& i have 3spaces between them. 2.&v_var1&      &v_var2& Now there 6spaces between them. The output varies from 1 to 3 interms of providing space at time of printing ( Not pr