Problem with setVisible(true) ??

Hi All;
In my application, I am using JFrame and added some component. At last I called setVisible(true); method. But it cann't works.
Then I tried with show() method. but the result is same.
Then I tried with isDisplayable() method, but strange ,it is returning false.
Now my problem is why it is hanging on calling the setVisible() method. or why it is returning false for isDisplayable().
Can anybody guide me to solve the problem.
Thanks in advance.
-Sumeet G

You should pack() or validate() the frame before
calling setVisible(). Do pack if you use layout
managers, validate if you set components size
manually.

Similar Messages

  • I have a problem with setVisible(true) !!!!!!

    Hi!
    Could you tell me please, how can I use the method
    getSize() before call the method setVisible(true)??
    If I call the method getSize() before setVisible(true)
    then return getSize() only 0 !!!!!
    I must call getSize() before setVisible(true).
    Thank you for your help ;-))
    Code:
    import java.awt.*;
    class Test extends Frame
    Test()
    t.setSize(200, 100);
    Button b=new Button("test");
    t.add(b);
    System.out.println("Size: "+ b.getSize()); //It doesn't work!!!!
    t.setVisible(true); // ohne das haut's ihn raus !
    public static void main(String args[])
    (new Test());
    }

    If you want to get the Button size, then you should set the button size before you called getSize(), otherwise you will get the value of zero just like yours.
    Try the following code.
    import java.awt.*;
    class Test extends Frame
    Test()
    setSize(200, 100);
    Button b=new Button("test");
    b.setSize(70,25);
    add(b);
    System.out.println("Size: "+ b.getSize()); //It doesn't work!!!!
    setVisible(true); // ohne das haut's ihn raus !
    public static void main(String args[])
    new Test();
    In this way, you will get the button size!

  • Problem with return true and if statement

    I'm making a
    ship shooter
    game and I have a problem with the collision detection for the
    corners of the stage. When you hold down two of the arrows to move
    the ship into the corners of the screen, the ship will go past it.
    The function bellow is what I'm using to detect this collision. The
    reason I'm using a function is because it's used for the ship and
    for all the balls from the cannons (as shown in the last two lines
    of the attached code). This is the reason I need the return true,
    so the if statement can be evaluated to true and then unload the
    movieclip of the cannon ball. When I remove the return true, the
    collision works fine, but obviously my cannon balls all get stuck
    on the edges.
    Any ideas?

    Well the function is called every frame, for the ship and for
    every cannon ball that's on the screen. So it could be called about
    4 times or so per frame. The problem is that ship goes through the
    corners of the stage (btw, the green background is the stage area)
    when you go in a diagonal direction.
    Just curious...what's the unnecessary code you're talking
    about?

  • Problem with printing true colors

    Had PSE7 and colors printed true and beautiful. Upgraded to PSE10 and all of a sudden colors printed muddy and dull with purplish overcast. Took printer in for service but problem persisted. Upgraded to PSE11 and once again colors were printing true and beautiful for over a year. Printed a card about 5 days ago using PSE11 - beautiful. Printed a card yesterday using PSE11 and colors muddy and dull with purplish overtones. Installed  PSE13 and colors printing dull, muddy with purplish overcast..  I feel it is a problem somewhere in settings of PSE, but can't figure out where.  I don't think it is a problem with printer. Both printer and PSE set to Adobe RGB. Color control set to optimize for printer. Using PC with Windows 7, 64 bit. Printer is Epson stylus photo 1400.  Thanks for any help, Merrie

    See if this helps:
    http://helpx.adobe.com/photoshop-elements/kb/color-management-settings-best-print.html

  • Global problem with immediate="true"

    JSF specifies that immediate="true" in UICommands should skip the Validation and Update Model phases.
    The RI uses the Update Model phase to reset the local values of the input components after updating the model. That means that in the case of immediate="true", the local values are not reset, and thus saved by the state manager.
    The problem is that the next display of the page shows the previously entered values, instead of getting the values from the model, which is somewhat strange for a 'cancel' button.
    I think this is mainly a problem with the spec which clearly indicates that the clearing of the local values should be done in the update model phase.
    Is it possible to have a workaround for this ?

    the previous posts have been made long ago, but I'll give it a try:
    I think this behavior is still buggy or at least not logical.
    Example:
    I've got a dataTable which shows a list of entries, each row with an "edit" commandButton and a "new" commandButton below the list.
    If the user clicks an "edit" button, he is redirected to the "details" page where he can edit and save the values of this entry. This works as expected. But: On the "details" page, there's also a "cancel" button, which should navigate to the list again, without doing any validation or updating.
    If I set this "cancel" button to "immediate", navigation works, but then I'll always see the values of the canceled entry, regardless of which "edit" button I click in the list.
    If the "cancel" button is not immediate, validation fails when the user clicks "new" and then "cancel", because he gets an empty form, but some or all fields are required.
    There are two workarounds:
    1) Creating two different views, one for creating a new entry and one for editing.
    2) The "cancel" button is a simple html-button, with the "onlick='location.href=xxxyyy'" attribute.
    IMHO both workarounds are ugly. So, why is the view ignoring that there is a complete different entry object in the backing bean of the "details" input fields???
    BTW: I'm using JSF SUN RI 1.1.01 (same with 1.2 current snapshot).
    With MyFaces, everythings works but it has some other bugs, so I want to stick to the Sun RI.
    Thanks,
    Walter

  • Problem with immediate=true, maybe a Bug

    I'm using a dataTable for selecting an user. The selected userBean will be put to the session context with id "selectedUser". The next page allows to edit users values. This edit page contains a cancel button with immedtiate=true param to abort editing and go back to the list. The edit page contains some input fields like:
    <h:inputText id="firstName" value="#{selectedUser.firstName}" />
    <h:inputText id="lastName" value="#{selectedUser.lastName}" />
    These fields are showing correct values for the selected user. But after selecting another user from the list the edit page is showing the values of the previous selected user! By selecting the second user again and again after a while the edit page shows the correct values.
    Well, I've added a JSP expression to the edit page to show me if the selected user is the right one "Edit User (${selectedUser})". The value of this expression always shows the correct selected user.
    If I modify the command button from:
    <h:commandButton action="users" value="Cancel" immediate="true" />
    to:
    <h:commandButton type="reset" onclick="window.location.href='/faces/users'" value="Cancel" />
    the problem does not appear!!!
    For me it looks like a bug. Any ideas?
    Thx,
    Wolfgang

    Sorry for the imcomplete testcase, here it comes again:
    --- Users.java ---------------------------------------------
    package jsf.test;
    import java.util.ArrayList;
    import javax.faces.context.FacesContext;
    public class Users
    private ArrayList users;
    public Users()
    super();
    users = new ArrayList();
    users.add(new User("User_A", "firstName_A", "lastName_A"));
    users.add(new User("User_B", "firstName_B", "lastName_B"));
    users.add(new User("User_C", "firstName_C", "lastName_C"));
    public ArrayList getUsers()
    return users;
    public String edit()
    FacesContext context = FacesContext.getCurrentInstance();
    User user = (User)context.getExternalContext().getRequestMap().get("user");
    System.out.println("selectedUser: " + user);
    context.getExternalContext().getSessionMap().put("selectedUser", user);
    return "navToUser";
    --- User.java ---------------------------------------------
    package jsf.test;
    public class User
    private String loginName;
    private String firstName;
    private String lastName;
    public User()
    public User(String loginName, String firstName, String lastName)
    this.loginName = loginName;
    this.firstName = firstName;
    this.lastName = lastName;
    public String getLoginName()
    return loginName;
    public void setLoginName(String loginName)
    this.loginName = loginName;
    public String getFirstName()
    return firstName;
    public void setFirstName(String firstName)
    this.firstName = firstName;
    public String getLastName()
    return lastName;
    public void setLastName(String lastName)
    this.lastName = lastName;
    public String update()
    System.out.println("user update: " + this);
    return "navToUsers";
    public String toString()
    return firstName + " " + lastName;
    --- users.jsp ---------------------------------------------
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <html>
    <body>
    <f:view>
    <h:form id="selectUser">
    <b>Users</b><p>
    <h:dataTable id="users" value="#{users.users}" var="user">
    <h:column>
    <f:facet name="header">
    <h:outputText value="Login Name" />
    </f:facet>
    <h:commandLink action="#{users.edit}">
    <h:outputText value="#{user.loginName}"/>
    </h:commandLink>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="First Name" />
    </f:facet>
    <h:commandLink action="#{users.edit}">
    <h:outputText value="#{user.firstName}"/>
    </h:commandLink>
    </h:column>
    <h:column>
    <f:facet name="header">
    <h:outputText value="Last Name" />
    </f:facet>
    <h:commandLink action="#{users.edit}">
    <h:outputText value="#{user.lastName}"/>
    </h:commandLink>
    </h:column>
    </h:dataTable>
    </h:form>
    </f:view>
    </body>
    </html>
    --- user.jsp ---------------------------------------------
    <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
    <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
    <html>
    <body>
    <f:view>
    <h:form>
    <b>User</b><p>
    <h:panelGrid columns="2" cellpadding="5">
    <h:outputText value="Login Name" />
         <h:inputText id="lognName" value="#{selectedUser.loginName}"/>
    <h:outputText value="First Name" />
         <h:inputText id="firstName" value="#{selectedUser.firstName}"/>
    <h:outputText value="Last Name" />
         <h:inputText id="lastName" value="#{selectedUser.lastName}"/>
    <h:outputText value=" " />
    <h:panelGroup>
    <h:commandButton action="navToUsers" value="Cancel" immediate="true"/>
    <%-- <h:commandButton type="reset" onclick="window.location.href='/faces/users.jsp'" value="Cancel"/> --%>
    <h:outputText value=" " />
    <h:commandButton action="#{selectedUser.update}" value="OK"/>
    </h:panelGroup>
    </h:panelGrid>
    </h:form>
    </f:view>
    </body>
    </html>
    --- faces-config.xml ---------------------------------------------
    <managed-bean>
    <description>
    Bean for TEST users.
    </description>
    <managed-bean-name>users</managed-bean-name>
    <managed-bean-class>jsf.test.Users</managed-bean-class>
    <managed-bean-scope>session</managed-bean-scope>
    </managed-bean>
    <managed-bean>
    <description>
    Bean for TEST user.
    </description>
    <managed-bean-name>user</managed-bean-name>
    <managed-bean-class>jsf.test.User</managed-bean-class>
    <managed-bean-scope>request</managed-bean-scope>
    </managed-bean>
    <navigation-rule>
    <from-view-id>/users.jsp</from-view-id>
    <navigation-case>
    <from-outcome>navToUser</from-outcome>
    <to-view-id>/faces/user.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>
    <navigation-rule>
    <from-view-id>/user.jsp</from-view-id>
    <navigation-case>
    <from-outcome>navToUsers</from-outcome>
    <to-view-id>/faces/users.jsp</to-view-id>
    </navigation-case>
    </navigation-rule>

  • Problems with CFNoCache=TRUE

    I have a problem.
    When forms are submitted with action=post the following is appended to the url string &CFNoCache=TRUE.
    I am using cgi.scriptname?cgi.query string in the  form action and it seems that &CFNoCache=TRUE is being passed along invisibly in the query string.
    I have googled this and can't find anything that  helps.
    Anyone know what I can do as it seems to have the knock on effect of clearing sessions which is causiohg me grief.
    Thanks

    I have had similar problems with same error messages. I've concluded that this problem ocurred due to different versions between SQLLoader and Data Base server and the way OWB invokes SQLLDR during a direct path loading.
    You said you use OWB10 against a 9.2.0.4 database. If you see at OWB10 home you will see at "bin" folder an SQLLDR.EXE, and the version of this SQLLDR is 10.x.x. which does not correspond to de database version.
    If you review the folder "OWB10home\owb\log" you will see log files with the name of the runtime repository and a version number. Please check the one that corresponds to the time of sqlloader execution and you will see that OWB build up a command line using "OWB10home\bin\sqlldr.exe" and due version differences between SQLLoader and the database an error is raised. When you run sqlldr from the owb home through the command line, probably you are reaching the correct version of SQLLDR due to your machine path. Verify which version is used at the log file.
    I could not find where it can be changed the definition of the sqlldr command line, at configure of mappings?, changing paths?, etc. So, the only workaround that I have found was to use OWB 9.2 against a 9.2 database if I will use SQLLoader and uninstalled OWB10g.
    If anybody knows how to solve this problem when OWB 10g is used please let us know.
    Hoping this will help you.
    Emilio Montecinos

  • Problem with setVisible

    Hi
    I made a class like this.
    class MonthComboBox extends JComboBox
    public MonthComboBox()
    addItem(" ");
    addItem("Jan");
    addItem("Feb");
    addItem("Mar");
    addItem("Apr");
    addItem("May");
    addItem("Jun");
    addItem("Jul");
    addItem("Aug");
    addItem("Sep");
    addItem("Oct");
    addItem("Nov");
    addItem("Dec");
    Now when I tried to do <object>.setVisible(false) in an event handler
    the runtime environment started giving lots of exceptions. Can somebody tell me whats wrong and how to correct this?

    Here is a simple program to hide the combobox, hope it helps.
    If this does not help, then -as already suggested- you have to provide us a little bit more information about your code and exceptions. =)
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    class MonthComboBox extends JComboBox implements ActionListener
         public MonthComboBox()
              addItem(" ");
              addItem("Jan");
              addItem("Feb");
              addItem("Mar");
              addItem("Apr");
              addItem("May");
              addItem("Jun");
              addItem("Jul");
              addItem("Aug");
              addItem("Sep");
              addItem("Oct");
              addItem("Nov");
              addItem("Dec");
         public void actionPerformed(ActionEvent e)
         if(isVisible())
         setVisible(false);
    else
         setVisible(true);
         public static void main(String [] args)
              //Make JPanel for the combobox
              JPanel mainPanel = new JPanel();
              mainPanel.setLayout(new BorderLayout());
              final MonthComboBox combo = new MonthComboBox();
              mainPanel.add(combo,BorderLayout.WEST);
              //Button that hides the combobox
              JButton button = new JButton("Toggle ComboBox Visibility");
              //Add an actionlistener for the button
              //in this case the combobox itself listens to it's own actions
              button.addActionListener(combo);
         mainPanel.add(button,BorderLayout.EAST);
              //Create a frame to test the code
              JFrame frame = new JFrame("Testing");
              frame.getContentPane().add(mainPanel);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.pack();
              frame.setSize(300,70);
              frame.setVisible(true);
    Br,
    J

  • Problem with setTransient(true)  JSF tree method

    Hi all,
    I have created dynamic tree .
    I am parsing the Parent and Child nodes and constructing the tree.
    I am using my own method treeSlectionHandler() for event handling for which i am using MethodBinding class and getCookieSelectedNode() method.
    Here is the problem ,whenever I delete or add any node from/into database change did not reflected in the tree .
    So I am using setTransient(true) which is able to reflect the database changes.
    I have one JSP(tree page) with this tree and one button on this page .I am calling tree.setTransient(tree) inside button action.
    Now I will delete one node from database.
    So I will click the button then which will go to next page.
    Again I will navigate to Tree page through menu.
    If I click any node for the first time it will simply refresh the tree state as in the database (if 10 nodes in database it wil show 10)
    But click action will not work (no check image set)
    But for the very next click the click action works and check image is set.
    So plz suggest me is there any other method to refresh the tree state ?
    I[b] want both tree refresh and click action happen simultaneously.
    I will be thankful if any one suggests me the solution .

    Hello EJP !
    You downloaded the sample to see? I use a button made in the project and not the browser button.
    Note: Sorry if this with some english mistakes but I do not speak very well.

  • Problem with flush=true in the jsp:include tag

    Hello
    I have deployed a JSP based application , based on the apache struts framework. The web server is Sun One Webserver 6 Service Pack4, on a windows 2000 machine
    The same application was tried on SunONE application server 7, and it works without any problem. However in this case the following error , on the page
    javax:servlet.jspexception:Illegal to flush within a custom tag
    Does this mean flush="true" is not allowed within custom tags
    Or is there a workaround for this
    Any help is appreciated
    thanks
    - Aniruddha

    Hi,
    This is a known problem, ��flush before you include�� limitation in JSP 1.1.
    As a result, you have to state flush="true" every time you include a jsp using <jsp:include> tag if you are using JSP1.1.
    Fortunately, it is fixed in JSP1.2. The flush attribute controls flushing. If true, then, if the page output is buffered and the flush attribute is given a ��true�� value, then the buffer is flushed prior to the inclusion, otherwise the buffer is not flushed. The default value for the flush attribute is ��false��.
    Gary Wang
    Developer Technical Support
    SUN Microsystems
    http://www.sun.com/developers/support/

  • Problem with immediate="true" used with inputText

    Hi everybody,
    I have two component, A and B, of type inpuText. When A is updated, I want B to be updated according to the value provided in A.
    I have to use immediate=True + context.renderResponse because I'm using some converters and validators because I want to avoid error messages being displayed at that point.
    I'm using partialtrigger to tell B to refresh himself when A changes it's value.
    This doesn't work.
    If I'm using the same code, but with ouputText instead, everything works!
    the code looks like this:
    <af:inputText id="A" styleClass="normalInputText"
    label="A" simple="true"
    value="#{controller.formBean.A}"
    valueChangeListener="#{controller.updateB}"
    autoSubmit="true" immediate="false"/>
    <af:inputText id="netAmount" styleClass="normalInputText"
    label="B" simple="true"
    value="#{controller.formBean.B}"
    partialTriggers="A">
    public void updateGrossPriceDependentFields(ValueChangeEvent event)
    FacesContext context = FacesContext.getCurrentInstance();
    formBean.setA((Long)event.getNewValue());
    if(formBean.getA().intValue() == 0)
    formBean.setB(new Long(222));
    else
    formBean.setB(new Long(0));
    context.renderResponse();
    Any ideas?

    Hi ,
    Just Try with this instead of context.renderResponse();
    Context.addPartialTarget(ComponantNAME);
    So that it will get refreshed
    RHY
    Message was edited by:
    RHY

  • Problem with setVisible(false)

    I everybody!!
    I have a some panels in a JFrame, disposed ones underneath the others. But when I make one of the bottom invisble doing:
    jPanel.setVisible(false);
    the ones in the top becomes down!!
    Is there any way to avoid this?
    Thanks in advance

    If you have multiple panels sharing the same area in a JFrame then you should be using a [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]Card Layout.
    Or you need to remove the old panel before adding the new panel.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.

  • Problem with required="true"

    Hi,
    If I set required="true" for an inputText, then if I click the return button without filling in this inputText , I can't return because the field must be filled!!!!
    Does someone have an idee about resolving that?
    Thanks

    Set immediate="true" on your return button.
    Note: This will skip ALL component validation. Which is probably what you want anyways.
    CowKing

  • Problem With ButtonUI in an Auxiliary Look and Feel

    This is my first post to one of these forums, so I hope everything works correctly.
    I have been trying to get an axiliary look and feel installed to do some minor tweaking to the default UI. In particular, I need it to work with Windows and/or Metal as the default UI. For the most part I let the installed default look and feel handle things with my code making some colors lighter, darker, etc. I also play with focus issues by adding FocusListeners to some components. I expect my code to work reasonably well no matter what the default look and feel is. It works well with Motif, Metal, and Windows, the only default look and feels I've tested with. What I'm going to post is a stripped down version of what I have been working on. This example makes gross changes to the JButton background and foreground colors in order to illustrate what I've encountered.
    I have three source code files. The first, Problem.java, creates a JFrame and adds five buttons to it. One button installs MyAuxLookAndFeel as an auxiliary look and feel using MyAuxButtonUI for the look and feel of JButtons. The next button removes that look and feel. The next button does nothing except print a line to System.out. The next button installs MyAuxLookAndFeel as an auxiliary look and feel using MyModButtonUI for the look and feel of JButtons. The last button removes that look and feel.
    The problem is, when I install the first auxiliary look and feel, buttons are no longer tabable. Also, they cannot be invoked by pressing the space button when they're in focus. When I remove the first auxiliary look and feel everything reverts to behaving normally. When I add the "Mod" version, button tabability is fine. The only difference is I've added the following code:
    if ( c.isFocusable() ) {
       c.setFocusable(true);
    }That strikes me as an odd piece of code to profoundly change the program behavior. Anyway, after adding and removing the "Mod" look and feel, the tababilty is forever fixed. That is, if I subsequently re-install the first look and feel, tababilty works just fine.
    The problem with using the space bar to select a focused button is more problematic. My class is not supposed to mess with the default look and feel which may or may not use the space bar to press the button with focus. When the commented code in MyModButtonUI is uncommented, things behave correctly. Even the statement
    button.getInputMap().remove( spaceKeyStroke );doesn't mess things up after the auxiliary look and feel is removed. So far I've tested this with JRE 1.4.2_06 under Windows 2000, JRE 1.4.2_10 under Windows XP, and JRE 1.5.0_06 under Windows XP and the behavior is the same.
    All of this leads me to two questions.
    1. Is my approach fundamentally flawed? I've extended TextUI and ScrollBarUI with no problems. This is the only problem I've encountered with ButtonUI. My real workaround for the space bar issue is better than the one I've supplied in the example, but it certainly is not guaranteed to work for any arbitrary default look and feel.
    2. Assuming I have no fundamental problems with my approach, it's possible I've found a real bug. I searched the bug database and couldn't find anything like this. Of course, this is the first time I've tried seasrching the database for a bug so my I'm doing it badly. Has this already been reported as a bug? Is there any reason I shouldn't report it?
    What follows is the source code for my example. It's in three files because the two ButtonUI classes must be public in order to work. Thanks for insight you can provide.
    Bill
    File Problem.java:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class Problem extends JFrame {
       public boolean isAuxInstalled = false;
       public boolean isModInstalled = false;
       public LookAndFeel lookAndFeel = new MyAuxLookAndFeel();
       private static int ctr = 0;
       public static void main( String[] args ) {
          new Problem();
       public Problem() {
          this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          setSize(250, 150);
          setTitle("Button Test");
          JButton install = new JButton("Install");
          JButton remove = new JButton("Remove");
          JButton doNothing = new JButton("Do Nothing");
          JButton installMod = new JButton("Install Mod");
          JButton removeMod = new JButton("Remove Mod");
          this.getContentPane().setLayout(new FlowLayout());
          this.getContentPane().add(install);
          this.getContentPane().add(remove);
          this.getContentPane().add(doNothing);
          this.getContentPane().add(installMod);
          this.getContentPane().add(removeMod);
          install.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( !isAuxInstalled ) {
                   isAuxInstalled = true;
                   UIManager.addAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          remove.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( isAuxInstalled ) {
                   isAuxInstalled = false;
                   UIManager.removeAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          doNothing.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                System.out.println( "Do nothing " + (++ctr) );
          installMod.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( !isModInstalled ) {
                   isModInstalled = true;
                   UIManager.addAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          removeMod.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
                if ( isModInstalled ) {
                   isModInstalled = false;
                   UIManager.removeAuxiliaryLookAndFeel( lookAndFeel );
                   SwingUtilities.updateComponentTreeUI( Problem.this );
          setVisible(true);
       class MyAuxLookAndFeel extends LookAndFeel {
          public String getName() {
             return "Button Test";
          public String getID() {
             return "Not well known";
          public String getDescription() {
             return "Button Test Look and Feel";
          public boolean isSupportedLookAndFeel() {
             return true;
          public boolean isNativeLookAndFeel() {
             return false;
          public UIDefaults getDefaults() {
             UIDefaults table = new MyDefaults();
             Object[] uiDefaults = {
                "ButtonUI", (isModInstalled ? "MyModButtonUI" : "MyAuxButtonUI"),
             table.putDefaults(uiDefaults);
             return table;
       class MyDefaults extends UIDefaults {
          protected void getUIError(String msg) {
    //         System.err.println("(Not) An annoying error message!");
    }File MyAuxButtonUI.java:
    import javax.swing.*;
    import java.awt.*;
    import javax.swing.plaf.*;
    import javax.swing.plaf.multi.*;
    import javax.accessibility.*;
    public class MyAuxButtonUI extends ButtonUI {
       private Color background;
       private Color foreground;
       private ButtonUI ui = null;
       public static ComponentUI createUI( JComponent c ) {
          return new MyAuxButtonUI();
       public void installUI(JComponent c) {
          MultiButtonUI multiButtonUI = (MultiButtonUI) UIManager.getUI(c);
          this.ui = (ButtonUI) (multiButtonUI.getUIs()[0]);
          super.installUI( c );
          background = c.getBackground();
          foreground = c.getForeground();
          c.setBackground(Color.GREEN);
          c.setForeground(Color.RED);
       public void uninstallUI(JComponent c) {
          super.uninstallUI( c );
          c.setBackground(background);
          c.setForeground(foreground);
          this.ui = null;
       public void paint(Graphics g, JComponent c) {
          this.ui.paint( g, c );
       public void update(Graphics g, JComponent c) {
          this.ui.update( g, c );
       public Dimension getPreferredSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getPreferredSize( c );
          return this.ui.getPreferredSize( c );
       public Dimension getMinimumSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getMinimumSize( c );
          return this.ui.getMinimumSize( c );
       public Dimension getMaximumSize(JComponent c) {
          if ( this.ui == null ) {
             return super.getMaximumSize( c );
          return this.ui.getMaximumSize( c );
       public boolean contains(JComponent c, int x, int y) {
          if ( this.ui == null ) {
             return super.contains( c, x, y );
          return this.ui.contains( c, x, y );
       public int getAccessibleChildrenCount(JComponent c) {
          if ( this.ui == null ) {
             return super.getAccessibleChildrenCount( c );
          return this.ui.getAccessibleChildrenCount( c );
       public Accessible getAccessibleChild(JComponent c, int ii) {
          if ( this.ui == null ) {
             return super.getAccessibleChild( c, ii );
          return this.ui.getAccessibleChild( c, ii );
    }File MyModButtonUI.java:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.plaf.*;
    public class MyModButtonUI extends MyAuxButtonUI
       static KeyStroke spaceKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0 );
       public static ComponentUI createUI( JComponent c ) {
          return new MyModButtonUI();
       public void installUI(JComponent c) {
          super.installUI(c);
          c.setBackground(Color.CYAN);
          if ( c.isFocusable() ) {
             c.setFocusable(true);
    //      final JButton button = (JButton) c;
    //      button.getInputMap().put( spaceKeyStroke, "buttonexample.pressed" );
    //      button.getActionMap().put( "buttonexample.pressed", new AbstractAction() {
    //         public void actionPerformed(ActionEvent e) {
    //            button.doClick();
    //   public void uninstallUI(JComponent c) {
    //      super.uninstallUI(c);
    //      JButton button = (JButton) c;
    //      button.getInputMap().remove( spaceKeyStroke );
    //      button.getActionMap().remove( "buttonexample.pressed" );
    }

    here is the code used to change the current look and feel :
    try {
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.motif.MotifLookAndFeel");
             catch (InstantiationException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (ClassNotFoundException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (UnsupportedLookAndFeelException e)
                  System.out.println("Error occured  "+ e.toString());
             catch (IllegalAccessException e)
                  System.out.println("Error occured in .. " + e.toString());
             Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
             Fenetre fen = new Fenetre();
             fen.setSize(dim.width, dim.height);
             fen.setResizable(false);
                 fen.setLocation(0, 0);
                  fen.setVisible(true);

  • Problem with JFrame.setUndecorated(true)

    I am using a L&F that overrides the JFrame's default title bar, which requires that the following methods are called before showing my main gui.
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);after gui is shown, i have a process that pops up a new JFrame with a progress bar, with a splash screen feel (no title bar), but ever since i called the above methods, i cant get the title bar to go away.
    JFrame frame = new JFrame("go away");
    frame.setUndecorated(true);how can i have my cake and eat it too? (draw main gui with new title bar L&F, then show splash/progress without title bar)
    thanks,
    mark

    I don't play with the default LAF but have you tried something like:
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);
    JFrame frame = new JFrame(...)
    frame.setVisible(true);
    JFrame.setDefaultLookAndFeelDecorated(false);
    JDialog.setDefaultLookAndFeelDecorated(false);
    Show your splash screen here
    JFrame.setDefaultLookAndFeelDecorated(true);
    JDialog.setDefaultLookAndFeelDecorated(true);

Maybe you are looking for