Displaying a JFrame at the centre of the screen

Hi,
I ve developed a GUI,
i want it to display at center of the screen each time i run the application,
i ve tried several options, but none of them works..
first i set the location of jframe..didnt work!!
{color:#ff0000}
this.setLocation(500,500);{color}
then i used this.. not working..
{color:#ff0000}
this.setLocationRelativeTo(null);{color}
then i wrote separate method n call it in my initialize().. still not working
{color:#ff0000}
Toolkit tk = Toolkit.getDefaultToolkit ();
Dimension screen = tk.getScreenSize ();
int lx = (int) (screen.getWidth () * 3/8);
int ly = (int) (screen.getHeight () * 3/8);
f.setLocation (lx,ly);{color}
if anyone can help me, pls reply..
thanks,
dush

hi,
here is the complete code,
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JSplitPane;
import javax.swing.JLabel;
import javax.swing.JButton;
import java.awt.Rectangle;
import javax.swing.ImageIcon;
import java.awt.Dimension;
import java.awt.*;
public class index extends JFrame {
     private static final long serialVersionUID = 1L;
     private JSplitPane jSplitPane = null;
     private JSplitPane jSplitPane1 = null;
     private JPanel jPanel = null;
     private JButton jButton = null;
     private JButton jButton1 = null;
     private JLabel jLabel = null;
     public index() {
          super();
          initialize();
     private void initialize() {
          this.setLocation(500,500);
          this.setContentPane(getJSplitPane());
          this.setLocationRelativeTo(null);
          this.setBounds(new Rectangle(500, 500, 462, 305));
          this.setTitle("GUI");
          this.setSize(new Dimension(462, 305));
          this.setResizable(false);
          this.setPreferredSize(new Dimension(350, 500));
          this.setVisible(true);
          centerFrame (this);
     private JSplitPane getJSplitPane() {
          if (jSplitPane == null) {
               jSplitPane = new JSplitPane();
               jSplitPane.setDividerLocation(150);
               jSplitPane.setDividerSize(0);
               jSplitPane.setRightComponent(getJSplitPane1());
          return jSplitPane;
     private JSplitPane getJSplitPane1() {
          if (jSplitPane1 == null) {
               jSplitPane1 = new JSplitPane();
               jSplitPane1.setDividerLocation(250);
               jSplitPane1.setOrientation(JSplitPane.VERTICAL_SPLIT);
               jSplitPane1.setTopComponent(getJPanel());
               jSplitPane1.setDividerSize(0);
          return jSplitPane1;
     private JPanel getJPanel() {
          if (jPanel == null) {
               jLabel = new JLabel();
               jLabel.setBounds(new Rectangle(66, 39, 179, 38));
               jLabel.setText("  GUI ");
               jPanel = new JPanel();
               jPanel.setLayout(null);
               jPanel.add(getJButton(), null);
               jPanel.add(getJButton1(), null);
               jPanel.add(jLabel, null);
          return jPanel;
     private JButton getJButton() {
          if (jButton == null) {
               jButton = new JButton();
               jButton.setBounds(new Rectangle(98, 92, 104, 50));
               jButton.setIcon(new ImageIcon(getClass().getResource("/images/mail.jpg")));
               jButton.setText("GUI");
               jButton.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                         first ff=new first();
                         ff.setVisible(true);
                         dispose();
          return jButton;
     private JButton getJButton1() {
          if (jButton1 == null) {
               jButton1 = new JButton();
               jButton1.setText("Exit");
               jButton1.setBounds(new Rectangle(134, 184, 55, 26));
               jButton1.addActionListener(new java.awt.event.ActionListener() {
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                         System.exit(0);
          return jButton1;
      void centerFrame (JFrame f) {
              // Need the toolkit to get info on system.
              Toolkit tk = Toolkit.getDefaultToolkit ();
              // Get the screen dimensions.
              Dimension screen = tk.getScreenSize ();
              // Make the frame 1/4th size of screen.
              int fw =  (int) (screen.getWidth ()/3);
              int fh =  (int) (screen.getWidth ()/4);
              f.setSize (fw,fh);
              // And place it in center of screen.
              int lx =  (int) (screen.getWidth ()  * 3/8);
              int ly =  (int) (screen.getHeight () * 3/8);
              f.setLocation (lx,ly);
            } // centerFrame
}  //  @jve:decl-index=0:visual-constraint="56,39"Edited by: dush82 on Oct 3, 2007 11:02 PM
Edited by: dush82 on Oct 3, 2007 11:10 PM

Similar Messages

  • I have a macbook pro from 2007 and the display memory slows do the screen so much it is almost unuseable  Any help fixing this problem?

    I have a macbook pro from 2007 and the display memory slows do the screen so much it is almost unuseable  Any help fixing this problem?

    Hi,
    Have you tried
    1.leaving the screen flipped open,
    2.connecting power
    3. connecting external monitor; waiting for it to 'wake up';
    then 4. closing lid of MBP to activate clamshell mode?

  • Resizing and/or Moving the JFrame on the Screen

    Is there any way to resize a JFrame when the undecorated property is set to true.
    I would like to have a JFrame that is both undecorated and resizable.
    Similarly, I was also wondering how to move the JFrame on the screen if the
    undecorated property is set to true since there is not Border to select the
    JFrame to initiate the Move.
    Thanks!

    yes... setSize(), setLocation().
    And if you want the user to be able to do it with the mouse, you need to add a border to the rootpane to prevent anyone adding things over the whole rootpane, and add a mouse listener to it to catch mouse click and drag events and do the calculations.
    If you look at the BasicInternalFrameUI, or some thing in there should have some code that does the same thing.

  • Move a JFrame over the screen by specifying coordinates

    Hi,
    I have a JPanel within a JFrame.
    All I wanted to do is this. I have an image loaded in that JPanel
    using MediaTracker. I can move that image anywhere inside the JPanel.
    Now ,I want to "simulate" what is happening within this JPanel in the
    entire Screen. That is, whenvever I move the image inside the JPanel,
    there should be a (different) JFrame application on the screen and it should move according to the "relative" screen coordinates.
    I thought I could use SwingUtilities.convertPointToScreen()
    function , but really dont know how to proceed exactly.ie., how to
    move a JFrame application anywhere in the screen not manually but
    moving it based on the relative coordinates I retrieve from the JPanel.
    The "simulation" here is that a JFrame in the screen
    is equated to an image in a JPanel.
    Any help would be REALLY appretiated.
    Thanks,
    Pullu

    Don't know what you're really looking for, but try:
    Rectangle parentRect=SwingUtilities.getRoot(myJPanel).getBounds();
    and see if it gives you the info you need.
    ;o)
    V.V.

  • I have an iPhone 4S and a 2012 Honda CRV . The streaming BT music is fine but now suddenly it stopped displaying song info on the screen. It worked for about 10 days and then stopped. Any thoughts?

    I have an iPhone 4S and a 2012 Honda CRV . The streaming BT music is fine but now suddenly it stopped displaying song info on the screen. It worked for about 10 days and then stopped. Any thoughts?

    I think that we all know the answer to this one.
    Unfortunatley the device is concidered damaged by water. Apple can do an out of warranty repair which would cost $199. Generally they would just replace the device in this case for the $199.
    The alternative is to Purchase a new device.

  • Locking a JFrame in the screen

    Help!!!!!, How can i lock a JFrame in the screen???
    I mean, no matter what others applications are open (or start the user after my java app) my frame will be at the front of all always.

    thats what I though too, but I has never done that.
    Do you know where could i find some documentation or code examples of programs than manipulate the OS in java???

  • How to centre a JFrame on the screen?

    hi,
    i'm just wondering how i could place a JFrame at the centre of the screen when i run the application?
    thank you very much!

    something like this should do it:
         int ix, iy;
         Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
         Dimension dd = getSize();
         ix = (d.width-dd.width)/2;
         iy = (d.height-dd.height)/2;
         if(iy < 10) iy = 10;
         if(ix < 10) ix = 10;
         setLocation(ix,iy);If you have 1.4 then there are some additional stuff like the start menu on Windows that you might want to deal with.
    Mark.

  • IPad2 display won't fit the screen

    My iPad screen display is too big so all outside margins can't be seen.  I tried to reset and tried to shrink.  Still too big. It's like my screen is 110% trying to fit a 100% screen.  Ideas?

    Did you try pinching the screen to shrink the image?
    Do you have Zoom turned On? Settings>General>Accessibility>Zoom>On. Try double tapping with three fingers. If that reduces the size of the screen, follow the path that I posted and turn Zoom off.

  • TS3274 My ipad display will not function, the screen will not display anything when turned on, you can see that the screen lights up but it is completely black

    The screen on my iPad will not display, the screen lightens up when powered on but the screen stays black, any fix for this that I can do at home?

    Try this  - Reset the iPad by holding down on the Sleep and Home buttons at the same time for about 10-15 seconds until the Apple Logo appears - ignore the red slider - let go of the buttons. (This is equivalent to rebooting your computer.) No data/files will be erased. http://support.apple.com/kb/ht1430
    Frozen or unresponsive iPad
    Resolve these most common issues:
        •    Display remains black or blank
        •    Touch screen not responding
        •    Application unexpectedly closes or freezes
    http://www.apple.com/support/ipad/assistant/ipad/
    iPad Frozen, not responding, how to fix
    http://appletoolbox.com/2012/07/ipad-frozen-not-responding-how-to-fix/
    iPad Frozen? How to Force Quit an App, Reset or Restart Your iPad
    http://ipadacademy.com/2010/11/ipad-frozen-how-to-force-quit-an-app-reset-or-res tart-your-ipad
    Black or Blank Screen on iPad or iPhone
    http://appletoolbox.com/2012/10/black-or-blank-screen-on-ipad-or-iphone/
    What to Do When Your iPad Won't Turn On
    http://ipad.about.com/od/iPad_Troubleshooting/ss/What-To-Do-When-Your-Ipad-Wo-No t-Turn-On.htm
    iOS: Not responding or does not turn on
    http://support.apple.com/kb/TS3281
    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
     Cheers, Tom

  • Need to display updated file on the screen

    Hi,
    I have a requirement in which we take beginning date(say 5-May-2010) and end date(day 15-May-2010) as input and spawn a script which processes some jobs for all the dates between these two dates.Now this script writes a log for each date the jobs have run. The jobs called by the script can take around 2 min for each day processing.Now the requirement is that the page refreshes on its own displaying the updated log.I can refresh the page after 2 minutes in OAF but how do I display the updated log on the screen so that the user comes to know which days are processed?I would be grateful if someone can provide me the clue on how can I achieve it.
    Regards

    Hi Reetesh,
    Thanks for your reply.The log of each request is going to be different.User should also be able to see the contents of the log.Actually for each date around 10 lines will follow which will give some data for that particular date and then next date will follow with its set of lines.

  • Barcode scanning and displaying other details on the screen

    Hi All,
    I have a requirement to replace the existing leagacy which has a POS functionality screen with SAP Screen.
    Currently the leagcy does the following function.
    When the user scan the Barcode of the product, other details of that are reflected and displayed.
    The same requriement has to be developed in ABAP.
    When the user scan the barcode, the details of the product should be displayed on the screen.
    This functionality is same as in POS.
    Kindly let me know how to proceed ...as I am unable to find any event where in after just scanning the barcode the detials of barcode are captured on screen field but how and which code/event triggers the other details to be displayed on the screen without any action from the user except scanning the barcode.
    Thanks in advance for any clarification and suggetion.
    Regards..
    Shakeel.

    Hi,
    the barcode scanner should be set up to trigger an Enter key after scanning a barcode.
    This will trigger your PAI right after scanning a barcode, so you can easily handle the input and process it as necessary.
    There is really no difference between entering the input through keyboard and pressing Enter, and entering it using a barcode scanner.
    You won't need anything else apart from the standard PAI/PBO processing.

  • How to display error message on the screen

    I am new to WD world and need all possible steps to resolve the following issue.
    I need to display the error message on the screen if any required field is empty when user click on SAVE button.
    I have set the attribute GO_MESSAGE_MANAGER and check the both box for  PUBLIC and REFTO and set the associated type IF_WD_MESSAGE_MANAGER under COMPONENTCONTROLLER.
    Under the method of COMPONENTCONTROLLER set the value WD_THIS-GV_NAV_FORBIDDEN = IV_NAV_FORBIDDEN. Which is type IMPORTING of associated type WDY_BOOLEAN.
    GV_NAV_FORBIDDEN has been set to attribute WDY_BOOLEAN in the COMPONENTCONTROLLER.
    Under the ACTION (on SAVE button) of my default view (VW_DEFAULT) I am doing the following.
    IF lv_f_name IS INITIAL
        CALL FUNCTION 'BALW_BAPIRETURN_GET2'
          EXPORTING
            type   = 'E'
            cl     = 'HRRCF0002'
            number = '020'
          IMPORTING
            return = ls_return.
        lv_message = ls_return-message.
    NEED TO PUT CODE TO PASS IT ON
    ENDIF.

    The thing I can not figure out is the input parameter of this call. My CONTEXT has a node1->node2->node3->f_name.
    CALL METHOD lo_message_manager->report_attribute_error_message
      EXPORTING
        message_text              = lv_message
        element                   = HOW WIILL YOU FIND THE VALUE OF THIS
        attribute_name            =
       params                    =
       msg_user_data             =
       is_permanent              = ABAP_FALSE
       scope_permanent_msg       = CO_MSG_SCOPE_CTXT_ELEMENT
       msg_index                 =
       cancel_navigation         =
       is_validation_independent = ABAP_FALSE     .
    wd_comp_controller->set_navigation_forbidden( iv_nav_forbidden = abap_true ).

  • Photoshop CS 5 will no longer open and display a file on the screen

    I am running CS5 on a pc with windows 7.  Suddenly, CS5 stopped displaying any pictures (both .jpg and .raw) on the screen after I import them from my hard drive.  I uninstalled the program and reinstalled it but the problem perisists. Can anybody tell me what to do?

    We need to know a lot more to help you. Please provide answers to the questions listed here: "FAQ: What information should I provide when asking a question on this forum?"

  • My iPod display is larger than the screen, how do,I change it  back?

    I don't know how this happened.  It was fine then I pressed the home button to get out of an app and now the display is huge and it's hard to navigate around the screen.

    Never mind, we figured it out.  Needed to double tap with three fingers to zoom back out.

  • RDP connection to remote host displays smaller resolution than the screen resolution

    Having a problem with a surface with 8.1 installed.  When connecting via Remote Desktop Connection to a remote host, the display is smaller than the display settings set for the desktop on the surface.  If I change the Display settings for the
    Surface, the display in the RDP session is still smaller. 
    I've tried changing the resolution settings for the connections under the display section of Remote Desktop Connection, but all that does is change the session to a window instead of full screen and does nothing to change the actual display size of the remote
    session.
    I believe this may be a function of DPI Scaling, but changing settings on the local surface display does nothing to change the behavior in the remote session. 

    Hi,
    Sorry for my dilatory reply. Actually acctually to your descriptioin, I doubt whether this problem caused by Surface itself problem. It would be better to contact Surface Forum for further
    assistance:
    Surface Support:
    http://answers.microsoft.com/en-us/surface
    Roger Lu
    TechNet Community Support

Maybe you are looking for

  • Universal Worklist items open in new window instead of existing frame

    After our recent upgrade we noticed that workitems in Universal Worklist open in new window instead of existing frame.  Do you know if there is a system or universal setting to make all the workitems open in existing frame?  I know we can change the

  • Help with display

    I use my Curve 8530 to navigate on trips.  My question is, how can I keep the screen for going dark so I can read my directions without having to hit a button to wake it up every few minutes? Got my first ever Blackberry on 8/10/2010 Curve 8530 Solve

  • Iphone 6 speaker issue

    Neither the ringer nor the speakerphone works.  Any word on a fix for this bug?

  • Uninstall J2re SE 1.4.2_02 and _03

    i'd like to be able to uninstall Java 2 Runtime Environment versions 1.4.2_02 and 1.4.2_03 using the command line or a scripted uninstall, rather than using add/remove programs on a windows 2000 system. is there a command line option to do this?

  • How should I edit an alpha channel after saving?

    I have a series of files in which I improperly modified the selection set prior to saving the selection, and now around the intended viewable area there is a hazy artifact that seems to correspond to where I manually edited the selection using Quick