Container a = getContentPane(); - Problem

Hello Guys,
As you can use this method successfuly on for JFrame. Is there any possibility to use it on a JPanel?
Basically, I have a class which extends JPanel. I am trying to use this method to design the components very efficiently using .setBounds().
However, I couldn't make it work.
Any Suggestions?
Thanks.

Well,
I have a class which extends JPanel with loads of components. I have extended it in order to control the frames faster. I have 3 different tabs, so basically I create the class and then pass it into Tab.
The reason why I said efficiently, it is really hard to design the components using borderlayout, flowlayout etc.. So I've decided to keep the layout null, and use setBounds instead. However, to use this I also be using getContentPane().
I have tried this -> Container contentPane = getContentPane(); in a class which extends JFrama, it worked fine as JFrame is part of Container. I need to use this in a class which extends JPanel only, to design the components as I want.
Thanks.

Similar Messages

  • Extending JPanel to contain a JRootPane - problems with scroll panes

    I am trying to write a JPanel subclass that contains a JRootPane, similar to the way that JFrame contains a JRootPane. The reason that I am doing this is that I would like to be able to intercept mouse events using the JGlassPane facility, but adding the glasspane to the JFrame is problematic since it then intercepts mouse events over all components in the JFrame, including the menu bar. It seems simpler to me to have the JRootPane owned by a JPanel, to give me better control over intercepting events. I've got an implementation working with the JFrame case, but have had to handle many small "gotchas", and at least one more exists. I'm hoping to simplify things by moving away from this way of doing things.
    I wrote a straightforward RootPanePanel class that extends JPanel and implements RootPaneContainer, delegating all of the add methods to the JRootPane's content pane. Here's the constructor for RootPanePanel:
    public RootPanePanel (LayoutManager layout) {
            rootPane = new JRootPane ();
            rootPane.setOpaque(true);
            rootPane.getContentPane().setLayout(layout);
            super.add (rootPane);
    }RootPanePanel also delegates calls like getContentPane/setContentPane to the JRootPane.
    To test my implementation, I wrote a main method that looks like the following:
    public static void main (String[] args) {
      SwingUtilities.invokeLater(new Runnable () {
        public void run () {
          try {
            JEditorPane editorPane = new JEditorPane ("http://www.archives.gov/exhibits/charters/print_friendly.html?page=declaration_transcript_content.html&title=NARA%20%7C%20The%20Declaration%20of%20Independence%3A%20A%20Transcription");
            JScrollPane scrollPane = new JScrollPane (editorPane);
            JFrame frame = new JFrame ("Test RootPanePanel");
            RootPanePanel panel = new RootPanePanel ();                    
            panel.add(scrollPane);
            frame.add(panel, BorderLayout.CENTER);
            scrollPane.setPreferredSize(new Dimension(800, 600));
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setSize (640, 480);
            frame.pack ();
            frame.setVisible(true);
          } catch (Exception e) {
            e.printStackTrace();
      });Note that I'm not actually using JEditorPane in my application, but it is the simplest component that displays the problem I'm encountering.
    When this code runs, it is fine, as long as the JFrame is big enough to display the scrollbars for the JScrollPane. If the JFrame is made small enough, the scrollbars are not displayed.
    If I instead add the JScrollPane to the JFrame directly, it behaves as you would expect.
    Is this a problem of mixing heavyweight and lightweight components? It doesn't seem like it should be; in both cases the JScrollPane is handling the same client component, the JEditorPane.
    Any suggestions/ideas are welcome!

    Here's the full RootPanePanel class in case people want to try it out
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.HeadlessException;
    import java.awt.LayoutManager;
    import java.io.IOException;
    import javax.swing.JEditorPane;
    import javax.swing.JFrame;
    import javax.swing.JLayeredPane;
    import javax.swing.JPanel;
    import javax.swing.JRootPane;
    import javax.swing.JScrollPane;
    import javax.swing.RootPaneContainer;
    import javax.swing.SwingUtilities;
    public class RootPanePanel extends JPanel implements RootPaneContainer {
         private JRootPane rootPane;
         public RootPanePanel () {
              this (new BorderLayout());
         public RootPanePanel (LayoutManager layout) {
              rootPane = new JRootPane ();
              rootPane.setOpaque(true);
              rootPane.getContentPane().setLayout(layout);
              super.add (rootPane);
         public Container getContentPane() {
              return rootPane.getContentPane();
         public Component getGlassPane() {
              return rootPane.getGlassPane();
         public JLayeredPane getLayeredPane() {
              return rootPane.getLayeredPane();
         public void setContentPane(Container arg0) {
              rootPane.setContentPane(arg0);
         public void setGlassPane(Component arg0) {
              rootPane.setGlassPane(arg0);
         public void setLayeredPane(JLayeredPane arg0) {
              rootPane.setLayeredPane(arg0);
         @Override
         protected void addImpl(Component comp, Object constraints, int index)
              if (comp == rootPane) {
                   super.addImpl(comp, constraints, index);
              else {
                   getContentPane().add(comp, constraints, index);
         @Override
         public Component add(Component comp, int index) {
              return rootPane.getContentPane().add(comp, index);
         @Override
         public void add(Component comp, Object constraints, int index) {
              rootPane.getContentPane().add(comp, constraints, index);
         @Override
         public void add(Component comp, Object constraints) {
              rootPane.getContentPane().add(comp, constraints);
         @Override
         public Component add(Component comp) {
              return rootPane.getContentPane().add(comp);
         @Override
         public Component add(String name, Component comp) {
              return rootPane.getContentPane().add(name, comp);
         public static void main (String[] args) {
              SwingUtilities.invokeLater(new Runnable () {
                   public void run () {
                        try {
                             JEditorPane editorPane = new JEditorPane ("http://www.archives.gov/exhibits/charters/print_friendly.html?page=declaration_transcript_content.html&title=NARA%20%7C%20The%20Declaration%20of%20Independence%3A%20A%20Transcription");
                             JScrollPane scrollPane = new JScrollPane (editorPane);
                             JFrame frame = new JFrame ("Test RootPanePanel");
                             RootPanePanel panel = new RootPanePanel ();                    
                             panel.add(scrollPane);
                             frame.add(panel, BorderLayout.CENTER);
                             scrollPane.setPreferredSize(new Dimension(800, 600));                                                                                                                                                 
                             frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                             frame.setSize (640, 480);
                             frame.pack ();
                             frame.setVisible(true);                                                                                                    
                        } catch (HeadlessException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
                        } catch (IOException e) {
                             // TODO Auto-generated catch block
                             e.printStackTrace();
         public JRootPane getRootPane() {
              return rootPane;
    }

  • Container TLF text problem!

    Hello,
    I want to copy this text paragraph from notepad (img1) and paste into a TLF container with 2 columns (img2), but it seems that something is wrong. Please look at the second picture and if anyone has any idea how to solve this problem?

    I figured it out, eventually.

  • ADF Security to J2EE Container Managed Security Problems

    Hi al!
    I had ADF security enabled in my application. I've added roles and users to embedded OC4J Server Preferences..., configured authorization using pageDefs... (following the Introduction to ADF Security in JDeveloper 10.1.3.2 howto).
    For the sake of friendlier user and roles management I decided to go to 2EE Container Managed Security (I want application manager in production environment to be able to manage users in only one place, not in DB table and extra for web app). I followed Frank Nimphius's Database Authentication and Authorization in J2EE Container Managed Security article.
    Now I have some problems. I removed users and roles from embedded OC4J Server Preferences... (I believe this are used only for ADF security, am I right?). I can log to application with admin user account (app index page doesn't have any binds and even pageDef), but when trying to access admin pages I get 401 Unauthorized page.
    What am I doing wrong, probably I've forgotten something? I'm a bit confused now with users and roles settings and ADF and container managed security.
    Part of my web.xml file:
    <servlet>
    <servlet-name>adfAuthentication</servlet-name>
    <servlet-class>oracle.adf.share.security.authentication.AuthenticationServlet</servlet-class>
    <init-param>
    <param-name>success_url</param-name>
    <param-value>/faces/app/index.jspx</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
    <servlet-name>adfAuthentication</servlet-name>
    <url-pattern>/adfAuthentication/*</url-pattern>
    </servlet-mapping>
    <security-role>
    <description>Admins</description>
    <role-name>admin_role</role-name>
    </security-role>
    <security-role>
    <description>Users</description>
    <role-name>user_role</role-name>
    </security-role>
    <security-role>
    <role-name>oc4j-administrators</role-name>
    </security-role>
    <security-constraint>
    <web-resource-collection>
    <web-resource-name>AllAdmins</web-resource-name>
    <url-pattern>faces/admin/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
    <role-name>admin_role</role-name>
    </auth-constraint>
    </security-constraint>
    <security-constraint>
    <web-resource-collection>
    <web-resource-name>AllUsers</web-resource-name>
    <url-pattern>faces/app/*</url-pattern>
    </web-resource-collection>
    <auth-constraint>
    <role-name>user_role</role-name>
    <role-name>admin_role</role-name>
    </auth-constraint>
    </security-constraint>
    <security-constraint>
    <web-resource-collection>
    <web-resource-name>adfAuthentication</web-resource-name>
    <url-pattern>/adfAuthentication</url-pattern>
    </web-resource-collection>
    <auth-constraint>
    <role-name>oc4j-administrators</role-name>
    <role-name>user_role</role-name>
    <role-name>admin_role</role-name>
    </auth-constraint>
    </security-constraint>
    Do I have to remove this adfAuthentication tags?
    I know I've made things a bit complicated for me now and for anyone to help, but I hope I will get at least some pointers what to do now and maybe some explanation about roles in container managed security? Is it enaugh to have security constraints and roles defined in web.xml file or they have to be defined somewhere else also (beside the database)?
    Thank you in advance!
    Bye
    PS
    Maybe stack trace after login:
    FINE: LoginConfigProvider.ctr: lmm=[LoginModuleManager: jznCfg=[JAZNConfig null], appConfigEntries={oracle.security.jazn.oc4j.CertificateAuthenticator=[javax.security.auth.login.AppConfigurationEntry@3625d0], oracle.security.jazn.tools.Admintool=[javax.security.auth.login.AppConfigurationEntry@eca6e7], oracle.security.jazn.oc4j.WebCoreIDSSOAuthenticator=[javax.security.auth.login.AppConfigurationEntry@c1c7c4], oracle.security.jazn.oc4j.DigestAuthenticator=[javax.security.auth.login.AppConfigurationEntry@221f81], oracle.security.wss.jaas.SAMLAuthManager=[javax.security.auth.login.AppConfigurationEntry@426e05], oracle.security.jazn.oc4j.JAZNUserManager=[javax.security.auth.login.AppConfigurationEntry@145240a], current-workspace-app=[javax.security.auth.login.AppConfigurationEntry@4120aa], oracle.security.wss.jaas.JAASAuthManager=[javax.security.auth.login.AppConfigurationEntry@1c78f98]}]
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option data_source_name = jdbc/TESTDbDS
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option table = APPLICATION_USER
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option groupMembershipTableName = APPLICATION_ROLE
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option usernameField = USR_EMAIL
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option passwordField = USR_PSW
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option groupMembershipGroupFieldName = ROLE_NAME
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option user_pk_column = USR_EMAIL
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option roles_fk_column = USR_EMAIL
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option pw_encoding_class = null
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option realm_column = null
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option application_realm = null
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule initialize
    FINE: [DBTableOraDataSourceLoginModule] option casing = toupper
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule login
    FINE: [DBTableOraDataSourceLoginModule]login called on DBTableLoginModule
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule login
    FINE: [DBTableOraDataSourceLoginModule]Calling callbackhandler ...
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule login
    FINE: [DBTableOraDataSourceLoginModule]Username returned by callback = admin
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule login
    FINE: [DBTableOraDataSourceLoginModule]Username changed to case as defined by toupper to ADMIN
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule performDbAuthentication
    FINE: [DBTableOraDataSourceLoginModule]User query string: select USR_EMAIL,USR_PSW from APPLICATION_USER where USR_EMAIL= (?)
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule performDbAuthentication
    FINE: [DBTableOraDataSourceLoginModule]User primary key value found = ADMIN
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule performDbAuthentication
    FINE: [DBTableOraDataSourceLoginModule]Password encoded by: oracle.security.jazn.login.module.db.util.DBLoginModuleClearTextEncoder
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule performDbAuthentication
    FINE: [DBTableOraDataSourceLoginModule]User ADMIN authenticated successfully
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule performDbAuthentication
    FINE: [DBTableOraDataSourceLoginModule]Roles query string: select ROLE_NAME from APPLICATION_ROLE where USR_EMAIL= (?)
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule performDbAuthentication
    FINE: [DBTableOraDataSourceLoginModule]DBUser Principal Name: ADMIN
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule performDbAuthentication
    FINE: [DBTableOraDataSourceLoginModule]DBRole Principal Name: admin_role
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule login
    FINE: [DBTableOraDataSourceLoginModule]Logon Successful = true
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule commit
    FINE: [DBTableOraDataSourceLoginModule]Subject contains 0 Principals before auth
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule commit
    FINE: [DBTableOraDataSourceLoginModule]Local LM commit succeeded
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule commit
    FINE: [DBTableOraDataSourceLoginModule]Subject contains 2 Principals after auth
    24.8.2007 10:17:19 oracle.security.jazn.login.module.db.DBTableOraDataSourceLoginModule commit
    FINE: [DBTableOraDataSourceLoginModule]Cleaning internal state!

    Hi there!
    I have another question about this. I've modified a bit DBRolePrincipal class to see what's going on. At the beginning of the equals(Object another) method I added this lines:
    log("method equals start",0);
    log("another type = " + another.getClass(), 0);
    if (another instanceof Principal)
    Principal mine = (Principal)another;
    log("Principal mine.getName() = " + mine.getName(), 0);
    The result is this output (after navigating to page that gives 401 forbidden):
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.security.jazn.oc4j.JAZNUserAdaptor
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = admin_user
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.adf.share.security.authentication.ADFRolePrincipal
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = anyone
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.security.jazn.oc4j.JAZNUserAdaptor
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = admin_user
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.adf.share.security.authentication.ADFRolePrincipal
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = anyone
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.security.jazn.oc4j.JAZNUserAdaptor
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = admin_user
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.adf.share.security.authentication.ADFRolePrincipal
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = anyone
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.security.jazn.oc4j.JAZNUserAdaptor
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = admin_user
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.adf.share.security.authentication.ADFRolePrincipal
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = anyone
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.security.jazn.oc4j.JAZNUserAdaptor
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = admin_user
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.adf.share.security.authentication.ADFRolePrincipal
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = anyone
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.security.jazn.oc4j.JAZNUserAdaptor
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = admin_user
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.adf.share.security.authentication.ADFRolePrincipal
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = anyone
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.security.jazn.oc4j.JAZNUserAdaptor
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = admin_user
    07/10/12 08:38:36 [DBRolePrincipal] method equals start
    07/10/12 08:38:36 [DBRolePrincipal] another type = class oracle.adf.share.security.authentication.ADFRolePrincipal
    07/10/12 08:38:36 [DBRolePrincipal] Principal mine.getName() = anyone
    Why is the name of ADFRolePrincipal always anyone? When I sign in with this user the output says:
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] User query string: select USERNAME,PASSWORD from ACTIVE_APP_USER_V where USERNAME= (?)
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] User primary key value found = admin_user
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] Password encoded by: oracle.sample.dbloginmodule.util.DBLoginModuleCearTextEncoder
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] User admin_user authenticated successfully
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] Roles query string: select ROLE_NAME from ACTIVE_APP_ROLE_V where USERNAME= (?)
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] DBRole Principal Name: admin_role
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] DBUser Principal Name: admin_user
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] Logon Successful = true
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] Subject contains 0 Principals before auth
    07/10/12 08:46:09 [DBUserPrincipal] method equals start
    07/10/12 08:46:09 [DBUserPrincipal] another type = class oracle.sample.dbloginmodule.principals.DBRolePrincipal
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] Local LM commit succeeded
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] Subject contains 2 Principals after auth
    07/10/12 08:46:09 [DBTableOraDatasourceLoginModule] Cleaning internal state!
    Frank, if you haven't given up on this issue yet could you please try to explain this to me? Why doesn't admin_role principal never get compared in [equals[/i] method?
    Thank you!
    BB

  • Custom Actionscript Container (Get Child Problems)

    I've extended the Container class to create a custom
    component. In this component, I take the children (can be anything:
    panels, images, etc) and move them around to different positions on
    the screen based on the mouse position. Everything is working
    fine... except, I need to capture the names of each child in the
    container as soon as it loads and add the names to an array (THIS
    ARRAY MUST BE STATIC). The problem that I am having is that I
    cannot seem to do it statically. That means that when I change the
    index of a child. The change affects the order of the array because
    the array is rebuilt every time. I don't want this. Any
    thoughts?

    You gotta specify your child table recon-field in the process definition mappings as a Key Field. Refer OOTB AD connector and check:
    Process Definition -> AD User ->Reconciliation Field Mappings -> memberOf

  • GetContentPane() problem

    Hi everyone,
    I new in Swing package and for this reason, there is smth makes me confused about Swings's classes,
    I can not keep the idea that why we always use getContentPane() method to add some component to the Frame container or set Layout ??
    Thanks

    Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/toplevel.html]How to Use Top Level Containers.

  • Container (JPanel) refresh problem

    Hello,
    In fact i have a panel (mainPanel) with a button OK, a another panel which display a specific MyJTable and combo box.
    In fact, when I clic OK Button, i want to charge my MyJTable with data depends on comboBox.
    First, i display a empty white panel and when i clic Ok i want to display my MyJTable.
    JPanel mainPanel = new JPanel();
    JPanel emptyPanel = new JPanel();
    JPanel combo = new JComboBox();
    JButton okButton = new JButton();
    MyJTable myJTable;
    mainPanel.add(emptyPanel);
    mainPanel.add(combo);
    mainPanel.add(okButton);I have a refresh problem, i try mainPanel.remove(emptyPanel) and thus mainPanel.add(myJTable), the remove works but the add no :(
    In ActionPerformed method when okButton:
    myJTable = new myJTable(combo);
    mainPanel.remove(emptyPanel);
    mainPanel.add(myJTable);
    mainPanel.repaint();Thanks for yu help!!

    Hi,
    have you tried playing with
    mainPanel.revalidate();
    mainPanel.revalidate();??
    Might help
    Phil

  • Overflow container Scroll bars problem

    Trying to add scroll bar for group body in a fragment. We put Overflow container for the groupbody within the page fragment. But no scroll bars are appearing. Scroll bar comes only if it is in a view.

    This question has been restated in this [url http://forum.java.sun.com/thread.jsp?forum=57&thread=530550&tstart=0&trange=30]thread. Please reply there so we don't have multiple threads going on at the same time.

  • Excel containing pivot table - Problem when opening

    Hi,
    There is jsp that generates an excel with few pivot tables in it. In the open/save dialog, if I save the excel and open it, it displays fine but if it is opened up directly, it gives an error saying "Reference is invalid".
    Note: The range for the pivot tables are specified using named ranges ( data is in different sheet from that of the pivot table ) ... but it works fine if saved and reopened.
    just confused of this behaviour... any ideas would be greatly appreciated...
    Regards...

    This seems to be a bug with the Excel. This works fine with Netscape and also should work fine with other browsers. In IE, the temp file is created with a file name that ends with a square bracket at the end( eg. myExcel[1].xls ) and this is contrary to the file naming convention of ms-excel ( should not contain '[' or ']' ).
    Only solution is, open the excel file as inline...
    response.setHeader("Content-Disposition", "inline; filename = myExcel.xls");Please advice if my perception is wrong or is there any other work around for this? I have tried using all types of headers when sending the response but nothing helps.
    To check this,
    Create an excel file and try to save it with a file name that contains square brackets...
    Regards...
    Edited by: Praveeen on Jun 27, 2008 1:36 AM

  • JS ScriptUI container.children[name] problem

    Has anyone any experience accessing controls by name?
    The JS Tools reference mentions that a control should have been created using the creation property {name: } syntax, which I obey. Nonetheless, I cannot get the control afterwards.
    I have to use this approach because I'm creating containers on the fly, assigning them names with variables, so the syntax container.children[index] is not a way to go for me.
    Anyone of knowledge out there?
    Regards

    Yeah, one might hear it's a feature not a bug, but I pronounce it a 'bug'.
    Group containers don't return children controls by their name. You have to use panels instead.
    Filed a bug to Adobe, FWIW.

  • ALV grid container toolbar refresh problem

    Hi All,
    I use OO to display alv (set_table_for_first_display).
    I use 
    it_toolbar_excluding = lt_exclude  parameters to hide some buttons.
    but when I tried to show up a button in toolbar  (when screen  comes CHANGE MODE From DISPLAY MODE)
    I can not refresh the toolbar.
    here is the code.
    thanks in advance
      IF r_container IS INITIAL .
    **ALV Grid
      CREATE OBJECT r_container
        EXPORTING
          container_name = 'CONTAINER'.
      CREATE OBJECT r_grid
        EXPORTING
          i_parent = r_container.
      CREATE OBJECT :
                      v_event_receiver.
      CALL METHOD r_grid->set_ready_for_input
        EXPORTING
          i_ready_for_input = 1.
    **ALV Grid
    *passing the layout structure, fieldcatalog and output table for display
      CALL FUNCTION 'API_RE_CN_GET_DETAIL'
        EXPORTING
          io_object     = lo_busobj
        IMPORTING
          es_contract   = ls_contract
          et_object_rel = lt_object_rel
        EXCEPTIONS
          OTHERS        = 0.
      IF ld_activity NE '01'.
        REFRESH t_itab.
        SELECT * FROM zrecn_sp_cond INTO CORRESPONDING FIELDS OF TABLE t_itab
          WHERE intreno = ls_contract-intreno.
      ENDIF.
      gs_fieldcat-fieldname = 'Z_DESC'.
      gs_fieldcat-ref_table = 'ZRECN_SP_COND'.
      gs_fieldcat-outputlen = '50'.
      gs_fieldcat-key = 'X'.
      gs_fieldcat-edit       = edit_flag.
      gs_fieldcat-auto_value = 'X'.
      APPEND gs_fieldcat TO gt_fieldcat.
      gs_fieldcat-fieldname = 'Z_VALIDFROM'.
      gs_fieldcat-ref_table = 'ZRECN_SP_COND'.
      gs_fieldcat-outputlen = '10'.
      gs_fieldcat-key = 'X'.
      gs_fieldcat-edit       = edit_flag.
      gs_fieldcat-auto_value = 'X'.
      APPEND gs_fieldcat TO gt_fieldcat.
      gs_fieldcat-fieldname = 'Z_VALIDTO'.
      gs_fieldcat-ref_table = 'ZRECN_SP_COND'.
      gs_fieldcat-outputlen = '10'.
      gs_fieldcat-key = 'X'.
      gs_fieldcat-edit       = edit_flag.
      gs_fieldcat-auto_value = 'X'.
      APPEND gs_fieldcat TO gt_fieldcat.
      gs_fieldcat-fieldname = 'INTRENO'.
      gs_fieldcat-ref_table = 'ZRECN_SP_COND'.
      gs_fieldcat-outputlen = '10'.
      gs_fieldcat-key = 'X'.
      gs_fieldcat-edit       = edit_flag.
      gs_fieldcat-auto_value = 'X'.
      gs_fieldcat-no_out = 'X'.
      APPEND gs_fieldcat TO gt_fieldcat.
      REFRESH :lt_exclude.
      PERFORM exclude_tb_functions USING 'LST1' activity  CHANGING lt_exclude ."decde to hide or not
        CALL METHOD r_grid->set_table_for_first_display
          EXPORTING
            i_structure_name     = 'ZRECN_SP_COND_STR'
            it_toolbar_excluding = lt_exclude
            is_layout            = fs_layout
          CHANGING
            it_fieldcatalog      = gt_fieldcat
            it_outtab            = t_itab[].
        SET HANDLER v_event_receiver->handle_user_command FOR r_grid.
        SET HANDLER v_event_receiver->handle_data_changed FOR r_grid.
        SET HANDLER v_event_receiver->handle_hotspot_click FOR r_grid.
        SET HANDLER v_event_receiver->handle_toolbar FOR r_grid.
        SET HANDLER v_event_receiver->handle_data_changed_finished FOR r_grid.
        CALL METHOD r_grid->set_toolbar_interactive.
      ELSE .
        ls_stable-row = 'X' .
        ls_stable-col = 'X' .
        CALL METHOD r_grid->refresh_table_display
          EXPORTING
            is_stable = ls_stable.
      ENDIF.

    Hi
    Try this.
    if o_grid is initial.
    create object <container>
    exporting
    container_name = 'container1'.
    create object o_grid
    exporting
    i_parent = container_name.
    perform fieldcatalog.
    CALL METHOD o_grid->set_table_for_first_display
    EXPORTING
    is_variant = gs_variant
    i_save = 'A'
    i_default = 'X'
    it_toolbar_excluding = i_exclude
    is_layout = wa_layout
    CHANGING
    it_fieldcatalog = i_fieldcat[]
    it_outtab = i_final_act[].
    ( after that I think you  need to call the method for selecting rows.
    like what I did in my code is below:
    create object event.
    set handler event->handle_double_click for o_grid.
    else.
    call method o_grid->refresh_table_display. )
    *Refreshing ALV Grid display
    CALL METHOD o_grid->refresh_table_display
    EXPORTING
    i_soft_refresh = 'X'
    EXCEPTIONS
    finished = 1
    OTHERS = 2.
    IF sy-subrc 0.
    --Exception handling
    ENDIF.
    endif.
    In this code if your o_grid is intial then it will process all the coding before refresh method else if your o_grid is not intial it will refresh the  table which is going to be displayed.
    I hope this will work for you
    Thanks
    Lalit Guptaa

  • Minimise front panel of vi containing timed loop = problem

    Is this expected behaviour...
    Run the attached VI.
    All it is supposed to do is beep every 10 cycles.
    When you minimise it and try to restore the front panel though... it locks up for a random amount of time.
    I don't think it is supposed to do that. (I'm running it on XP Pro.)
    Originally I was chasing this problem in a data acquisition loop. The buffer would overflow and exit the app with an error when it was minimised.
    It took all day to track it down to this.
    Hmmm... I just tried to save it back to a version 8.0 vi and it doesn't seem to have the same error!
    Message Edited by Troy K on 10-03-2008 05:26 PM
    Message Edited by Troy K on 10-03-2008 05:31 PM
    Troy
    CLDEach snowflake in an avalanche pleads not guilty. - Stanislaw J. Lec
    I haven't failed, I've found 10,000 ways that don't work - Thomas Edison
    Beware of the man who won't be bothered with details. - William Feather
    The greatest of faults is to be conscious of none. - Thomas Carlyle
    Attachments:
    Timed Loop minimised.vi ‏85 KB
    minimisetimedloop.png ‏7 KB

    I'm using LabVIEW 8.5.1 on two PCs and it does it on both of them.
    I just emailed the vi to a colleague and after a few minimise/maximises it locked up on him too.
    I've just found that if I remove the left and right data nodes inside the timed loop the bug seems to go away.
    Steps to repeat bug:
    1. Minimise all windows (Windows+m)
    2. Restore vi front panel and run it. (It should start beeping twice a second)
    3. Minimise / Restore it rapidly by repeatedly clicking on the vi's Front Panel 'task bar button' (down the bottom).
    After a while the beeping will stop when the front panel is minimised and it wont restore. Then after a while (with or without clicking on the task bar button) the front panel will restore and the missed periods will execute very quickly (as the timed loop does what it is configured to do).
    I think because of the simplicity of the example vi the bug doesn't show up as often. When I ran it in the real application (too many vi's to post) it crashed every time. In the real application there isn't much going on in the timed loop, it is just used to queue items into a separate consumer loop. The problem is that when the bug occurs, ALL LABVIEW CODE stops executing, not just the code inside the timed loop. So another vi running in parallel (in a daemon) that retrieves messages from a device queue stops and the device buffer overflows.
    Attached is a modified vi to demonstrate that code outside the timed loop stops executing too. The bug occurs here on three different PCs, the only common thing I can think of is LabVIEW 8.5.1.
    Troy
    CLDEach snowflake in an avalanche pleads not guilty. - Stanislaw J. Lec
    I haven't failed, I've found 10,000 ways that don't work - Thomas Edison
    Beware of the man who won't be bothered with details. - William Feather
    The greatest of faults is to be conscious of none. - Thomas Carlyle
    Attachments:
    Timed Loop minimised 2.vi ‏89 KB

  • Container updating problem

    Hello everyone! I've been working on an applet, it's a login box and I have it designed to where you enter your login information hit enter than an actionPerformed is called which does:
    contentPane.removeAll();
    contentPane.setLayout(new GridLayout(0,1));
    contentPane.add(postLoginBox);contentPane is 'Container contentPane = getContentPane();' which was initialized earlier to display the login boxes.
    So I have it like this because I want there to be the login boxes then once a user hits enter and his login information sent I want it to then display a TextArea (postLoginBox). But the problem seems to be that once the user hits enter and the information is sent to the TextArea the TextArea never loads. All the components are removed but there is no textArea. I noticed in eclipse if I resize the applet by using the mouse it will load the textArea box.
    Any ideas on how to "refresh" the contentPane?
    Thanks!

    Doing a contentPane.validate() should solve your problem.

  • JFrames and Java3D simple problem

    Hi ive created a program using jframes in Java and im wanting to move it over to java 3d but im having problems. Ive litterally just looked at java 3d so my knowledge is limited. All i want is to set up my canvas so that i have a Jframe panel on the right and a 3d ball on the left. Here's my failed attempt......
    import com.sun.j3d.utils.geometry.*;
    import com.sun.j3d.utils.universe.*;
    import com.sun.j3d.utils.image.*;//imports image functions
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import javax.swing.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.awt.*;
    public class Prog extends JFrame
        private Canvas3D canvas;
        private SimpleUniverse universe = new SimpleUniverse();  // Create the universe      
        private BranchGroup group = new BranchGroup(); // Create a structure to contain objects
        private Bounds bounds;
        public Prog()
            super("Program");
            GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
            canvas = new Canvas3D(config);
            //getContentPane().setLayout( new BorderLayout( ) );
            //getContentPane().add(canvas, "Center");
            Container c = getContentPane();
            setSize(600,400);
            c.setLayout(new BorderLayout( ));
            JPanel leftPanel = new JPanel( );
            leftPanel.setBackground(Color.BLACK);
            c.add(leftPanel, BorderLayout.CENTER);
            c.setLayout(new BorderLayout( ));
            JPanel rightPanel = new JPanel( );
            rightPanel.setBackground(Color.GRAY);
            c.add(rightPanel, BorderLayout.EAST);
            JButton goButton = new JButton("  Go  ");
            goButton.setBackground(Color.RED);
            rightPanel.add(goButton);
         Light();//Creates A Light Source
           // Create a ball and add it to the group of objects
           Sphere sphere = new Sphere(0.5f);
           group.addChild(sphere);
           // look towards the ball
           universe.getViewingPlatform().setNominalViewingTransform();
           // add the group of objects to the Universe
           universe.addBranchGraph(group);
        public void Light()
            // Create a white light that shines for 100m from the origin
            Color3f light1Color = new Color3f(1.8f, 1.8f, 1.8f);
           BoundingSphere bounds = new BoundingSphere(new Point3d(0.0,0.0,0.0), 100.0);
            Vector3f light1Direction = new Vector3f(4.0f, -7.0f, -12.0f);
           DirectionalLight light1 = new DirectionalLight(light1Color, light1Direction);
            light1.setInfluencingBounds(bounds);
           group.addChild(light1);
        public static void main(String[] args)
           Prog frame = new Prog();
         frame.setVisible(true);
    }It Compiles but the 3d ball and the Jframe gui are in different windows but i want them in the same window but i duno how ?

    Hi tesla66 I'm sorry if I didn't correct your code, but drop some new code trying to solve the problem. I've used the cube instead the sphere because it's easier to see is rotating but just change "new ColorCube(0.4f)" with " new Sphere( 0.4f )". I wrote even some coments tought they're helpful. Tell me if I solved the problem
    import java.awt.*;
    import javax.swing.*;
    import javax.media.j3d.*;
    import javax.vecmath.*;
    import com.sun.j3d.utils.universe.SimpleUniverse;
    import com.sun.j3d.utils.geometry.*;
    public class JFrameAndCanvas3D extends JFrame
         private Canvas3D canvas3D;
         public static void main(String[] args)
            new JFrameAndCanvas3D();
         public JFrameAndCanvas3D()
              initialize();
        public BranchGroup createSceneGraph()
            BranchGroup objRoot = new BranchGroup(); //root
            // Creates a bounds for lights and interpolator
            BoundingSphere bounds = new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);
            //Ambient light
            Color3f ambientColour = new Color3f(0.2f, 0.2f, 0.2f);
            AmbientLight ambientLight = new AmbientLight(ambientColour);
            ambientLight.setInfluencingBounds(bounds);
            objRoot.addChild(ambientLight);
            ///Creates a group for transforms
            TransformGroup objMove = new TransformGroup();
            //You must set the capability bit to allow to write transform on the object
            objMove.setCapability(TransformGroup.ALLOW_TRANSFORM_WRITE);
            //Adds a color cube
            objMove.addChild(new ColorCube(0.4));
            //Creates a timer
            Alpha rotationAlpha = new Alpha(-1, //-1 = infinite loop
                                            4000 // rotation time in ms
            //creates a transform 3D based on Y axis roation
            Transform3D t3d = new Transform3D();
            t3d.rotY(Math.PI/2);
            //Creates an rotation interpolator with an alpha and a TransformGroup
            RotationInterpolator rotator = new RotationInterpolator(rotationAlpha, objMove);
            rotator.setTransformAxis(t3d);//setta l'asse di rotazione
            //sets a bounding region. withouth this scheduling bounds the interpolator won't work
            rotator.setSchedulingBounds(bounds);
            //add the interpolator to the group
            objMove.addChild(rotator);
            //Adding the group to the root
            objRoot.addChild(objMove);
            objRoot.compile();//improve the performance
            return objRoot;
        public void initialize()
            setSize(800, 600);
            setLayout(new BorderLayout());
            GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();//default config
            canvas3D = new Canvas3D(config);
            canvas3D.setSize(400, 600);
            add(canvas3D, BorderLayout.WEST); //adding the canvas to the west side of the JFrame
            SimpleUniverse simpleU = new SimpleUniverse( canvas3D );
            JPanel controlPanel = new JPanel();
            controlPanel.setLayout(new BorderLayout());
            controlPanel.setSize(400, 600);
            JLabel label = new JLabel();
            label.setText("I'm the control Panel");
            controlPanel.add(label, BorderLayout.CENTER);
            add(controlPanel, BorderLayout.EAST);
            //Positioning the view
            TransformGroup viewingPlatformGroup = simpleU.getViewingPlatform().getViewPlatformTransform();
            Transform3D t3d = new Transform3D();
            t3d.setTranslation(new Vector3f(0, 0, 3)); //moving back from the cube--> +z
            viewingPlatformGroup.setTransform(t3d);
            canvas3D.getView().setBackClipDistance(300.0d); //sets the visible distance
            canvas3D.getView().setFrontClipDistance(0.1d);
            canvas3D.getView().setMinimumFrameCycleTime(20); //minimum time refresh
            canvas3D.getView().setTransparencySortingPolicy(View.TRANSPARENCY_SORT_GEOMETRY); //rendering order
            BranchGroup scene = createSceneGraph();
            simpleU.addBranchGraph(scene);
            setVisible(true);
    }-->Davil

  • GridBagLayout and Panel Border problem

    I have 3 panels like
    A
    B
    C
    and the C panel has a Mouse Listener that on a mouseEntered creates a border around the same panel and on a mouseExited clears that border.
    When this border is created the A and B panels go up a little bit .. they move alone when the border is created.
    Is there any way to fix this problem? Is there any way to get the panels static?
    the code is close to the following:
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    import javax.swing.BorderFactory;
    import javax.swing.border.Border;
    import javax.swing.border.TitledBorder;
    import java.awt.event.*;
    import java.text.NumberFormat;
    public class Game extends JFrame implements MouseListener
    JPanel game, options, top, down, middle;
    NumberFormat nf;
    public Game() {
    super("Game");
    nf = NumberFormat.getPercentInstance();
    nf.setMaximumFractionDigits(1);
    JPanel center = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = gbc.BOTH;
    gbc.weighty = 1.0;
    gbc.weightx = 0.8;
    center.add(getGamePanel(), gbc);
    gbc.weightx = 0.104;
    center.add(getOptionsPanel(), gbc);
    Container cp = getContentPane();
    // use the JFrame default BorderLayout
    cp.add(center); // default center section
    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setSize(700,600);
    // this.setResizable(false);
    setLocationRelativeTo(null);
    setVisible(true);
    addComponentListener(new ComponentAdapter()
    public void componentResized(ComponentEvent e)
    showSizeInfo();
    showSizeInfo();
    private void showSizeInfo()
    Dimension d = getContentPane().getSize();
    double totalWidth = game.getWidth() + options.getWidth();
    double gamePercent = game.getWidth() / totalWidth;
    double optionsPercent = options.getWidth() / totalWidth;
    double totalHeight = top.getHeight() + middle.getHeight() + down.getHeight();
    double topPercent = top.getHeight() / totalHeight;
    double middlePercent = middle.getHeight() / totalHeight;
    double downPercent = down.getHeight() / totalHeight;
    System.out.println("content size = " + d.width + ", " + d.height + "\n" +
    "game width = " + nf.format(gamePercent) + "\n" +
    "options width = " + nf.format(optionsPercent) + "\n" +
    "top height = " + nf.format(topPercent) + "\n" +
    "middle height = " + nf.format(middlePercent) + "\n" +
    "down height = " + nf.format(downPercent) + "\n");
    private JPanel getGamePanel()
    // init components
    top = new JPanel(new BorderLayout());
    top.setBackground(Color.red);
    top.add(new JLabel("top panel", JLabel.CENTER));
    middle = new JPanel(new BorderLayout());
    middle.setBackground(Color.green.darker());
    middle.add(new JLabel("middle panel", JLabel.CENTER));
    down = new JPanel(new BorderLayout());
    down.setBackground(Color.blue);
    down.add(new JLabel("down panel", JLabel.CENTER));
    // layout game panel
    game = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.weightx = 1.0;
    gbc.fill = gbc.BOTH;
    gbc.gridwidth = gbc.REMAINDER;
    gbc.weighty = 0.2;
    game.add(top, gbc);
    gbc.weighty = 0.425;
    game.add(middle, gbc);
    gbc.weighty = 0.2;
    game.add(down, gbc);
    down.addMouseListener(this);
    return game;
    private JPanel getOptionsPanel()
    options = new JPanel(new BorderLayout());
    options.setBackground(Color.pink);
    options.add(new JLabel("options panel", JLabel.CENTER));
    return options;
    // mouse listener events
         public void mouseClicked( MouseEvent e ) {
    System.out.println("pressed");
         public void mousePressed( MouseEvent e ) {
         public void mouseReleased( MouseEvent e ) {
         public void mouseEntered( MouseEvent e ) {
    Border redline = BorderFactory.createLineBorder(Color.red);
    JPanel x = (JPanel) e.getSource();
    x.setBorder(redline);
         public void mouseExited( MouseEvent e ){
    JPanel x = (JPanel) e.getSource();
    x.setBorder(null);
    public static void main(String[] args ) {
    Game exe = new Game();
    exe.show();
    }

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import java.awt.event.*;
    import java.text.NumberFormat;
    public class Game extends JFrame implements MouseListener{
      JPanel game, options, top, down, middle;
      NumberFormat nf;
      public Game() {
        super("Game");
        nf = NumberFormat.getPercentInstance();
        nf.setMaximumFractionDigits(1);
        JPanel center = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = gbc.BOTH;
        gbc.weighty = 1.0;
        gbc.weightx = 0.8;
        center.add(getGamePanel(), gbc);
        gbc.weightx = 0.104;
        center.add(getOptionsPanel(), gbc);
        Container cp = getContentPane();
        // use the JFrame default BorderLayout
        cp.add(center); // default center section
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setSize(700,600);
        // this.setResizable(false);
        setLocationRelativeTo(null);
        setVisible(true);
        addComponentListener(new ComponentAdapter(){
            public void componentResized(ComponentEvent e){
            showSizeInfo();
        showSizeInfo();
      private void showSizeInfo(){
        Dimension d = getContentPane().getSize();
        double totalWidth = game.getWidth() + options.getWidth();
        double gamePercent = game.getWidth() / totalWidth;
        double optionsPercent = options.getWidth() / totalWidth;
        double totalHeight = top.getHeight() + middle.getHeight() + down.getHeight();
        double topPercent = top.getHeight() / totalHeight;
        double middlePercent = middle.getHeight() / totalHeight;
        double downPercent = down.getHeight() / totalHeight;
        System.out.println("content size = " + d.width + ", " + d.height + "\n" +
            "game width = " + nf.format(gamePercent) + "\n" +
            "options width = " + nf.format(optionsPercent) + "\n" +
            "top height = " + nf.format(topPercent) + "\n" +
            "middle height = " + nf.format(middlePercent) + "\n" +
            "down height = " + nf.format(downPercent) + "\n");
      private JPanel getGamePanel(){
        // init components
        top = new JPanel(new BorderLayout());
        top.setBackground(Color.red);
        top.add(new JLabel("top panel", JLabel.CENTER));
        middle = new JPanel(new BorderLayout());
        middle.setBackground(Color.green.darker());
        middle.add(new JLabel("middle panel", JLabel.CENTER));
        down = new JPanel(new BorderLayout());
        down.setBackground(Color.blue);
        down.add(new JLabel("down panel", JLabel.CENTER));
        // layout game panel
        game = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.weightx = 1.0;
        gbc.fill = gbc.BOTH;
        gbc.gridwidth = gbc.REMAINDER;
        gbc.weighty = 0.2;
        game.add(top, gbc);
        gbc.weighty = 0.425;
        game.add(middle, gbc);
        gbc.weighty = 0.2;
        game.add(down, gbc);
        down.addMouseListener(this);
        return game;
      private JPanel getOptionsPanel(){
        options = new JPanel(new BorderLayout());
        options.setBackground(Color.pink);
        options.add(new JLabel("options panel", JLabel.CENTER));
        return options;
      public void mouseClicked( MouseEvent e ) {
        System.out.println("pressed");
      public void mousePressed( MouseEvent e ) {
      public void mouseReleased( MouseEvent e ) {
      public void mouseEntered( MouseEvent e ) {
        Border redline = new CalmLineBorder(Color.red);
        JPanel x = (JPanel) e.getSource();
        x.setBorder(redline);
      public void mouseExited( MouseEvent e ){
        JPanel x = (JPanel) e.getSource();
        x.setBorder(null);
      public static void main(String[] args ) {
        Game exe = new Game();
        exe.setVisible(true);
    class CalmLineBorder extends LineBorder{
      public CalmLineBorder(Color c){
        super(c);
      public CalmLineBorder(Color c, int thick){
        super(c, thick);
      public CalmLineBorder(Color c, int thick, boolean round){
        super(c, thick, round);
      public Insets getBorderInsets(Component comp){
        return new Insets(0, 0, 0, 0);
    }

Maybe you are looking for

  • What is the part number for T60 DVD/RW replacement?

    Hello, I have looked through the Lenovo support site and could not find definitive information on what is the correct part number for a DVD/RW replacement for a T60 (2613-CTO).  I don't have access to this machine at this time so I can not remove the

  • How to copy a pdf file from a windows PC to an iPad?

    how to copy a pdf file from a windows PC to an iPad?

  • Trying to understand how pics are stored

    I'm new to Mac (iMac Core i5 27") and trying to understand how pictures are stored. I've searched and found some posts that are relevant, but I really wanted to try and confirm a couple of things that still aren't clear to me. First question is: Are

  • Set Metadata for custom fields on Supplier (BUPA)

    Hi, I have to add a new field to BASIC DATA view of Supplier. I have appended the field in the required structures. Now, I need to set the properties of field to make it as visible and enable. How can we set these properties? Is it through implementi

  • Exchange server 2013 error called "403 Sorry! Access denied :"

    I installed a domain and an exchange server on separate computers. After installed Exchange server 2013, tried to open "Exchange Administrative Center" there is an error message that is attached with this post and cannot go to the admin panel. so tr