Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Runnable jar file not working in joined display configuration on Fedora.

  1. #1
    Junior Member
    Join Date
    Feb 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Runnable jar file not working in joined display configuration on Fedora.

    There are a number of samples that allow me to put my JPanel on screen 1 or screen 2. It works fine when running from eclipse or running the same file on a single screen system. It does however not run on my dual screen setup. There are no error message when running "java -jar GuiTest.jar" on the dual screen system and as mentioned before the same file moved over to a single screen box it runs just fine.
    Any idea what might make it work for a dual screen environment? Here is a sample of what gives this behavior taken from another site:
    	public static void gdshow() {
    		   GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    				   GraphicsDevice[] gs = ge.getScreenDevices();
    				   for (int j = 0; j < gs.length; j++) {
    				      GraphicsDevice gd = gs[j];
    				      GraphicsConfiguration gc = gd.getDefaultConfiguration();
    				      System.out.println(gs[j].getIDstring());
    				     // for (int i=0; i < 5; i++) {
    				      if(j == 0) {  
    				      	 JFrame f = new JFrame(gs[j].getDefaultConfiguration());
    				         f.setDefaultCloseOperation(3);
    				         JPanel c = new JPanel();
    				         Rectangle gcBounds = gc.getBounds();
    				         int xoffs = gcBounds.x;
    				         int yoffs = gcBounds.y;
    				         f.add(c);
    				         f.setLocation((50)+xoffs, (60)+yoffs);
    				         f.setSize(500, 500);
    				         f.setVisible(true);
    				      }
    				   }
    	}
    I am running eclipse on my dev environment which has two screens in display mode of "Join Displays" with OS of Fedora 35. The code snippet provided is only the portion being called by main of the class named GuiTest.

  2. #2
    Member
    Join Date
    Jan 2024
    Posts
    75
    Thanks
    0
    Thanked 4 Times in 4 Posts

    Default Re: Runnable jar file not working in joined display configuration on Fedora.

    It seems that the issue might be related to how the JFrame is being positioned in a dual-screen setup. When you run your code on a system with a single screen, it works fine, but on a dual-screen setup, it fails to display properly.

    One potential reason for this behavior could be that the coordinates used to position the JFrame (`f.setLocation((50)+xoffs, (60)+yoffs);`) are calculated based on assumptions about a single-screen environment. In a dual-screen setup, these coordinates might not place the JFrame where you expect it to be.

    To address this issue, you could try a few things:

    1. Use Absolute Screen Coordinates: Instead of adding offsets to the default screen bounds, try using absolute screen coordinates to position the JFrame. You can get the screen bounds directly from the GraphicsDevice and calculate the position accordingly.

    2. Determine Screen Layout Dynamically: Since you're working with a dual-screen setup, it's essential to dynamically determine which screen you want to display the JFrame on. You can get the screen bounds for each GraphicsDevice and then decide based on your requirements which screen to use.

    3. Debugging Output: Add additional debug output to your code to see if the JFrame is being created and positioned as expected. You can print out the coordinates and other relevant information to help diagnose the issue.

    Here's a revised version of your code snippet that attempts to address these points:

    ```java
    public static void gdshow() {
    GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
    GraphicsDevice[] gs = ge.getScreenDevices();

    for (int j = 0; j < gs.length; j++) {
    GraphicsDevice gd = gs[j];
    GraphicsConfiguration gc = gd.getDefaultConfiguration();
    System.out.println(gs[j].getIDstring());

    if (j == 0) {
    JFrame f = new JFrame(gc);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JPanel c = new JPanel();

    // Get screen bounds dynamically
    Rectangle screenBounds = gd.getDefaultConfiguration().getBounds();
    int screenWidth = screenBounds.width;
    int screenHeight = screenBounds.height;

    // Calculate JFrame position
    int x = screenWidth / 4; // Example: 1/4 of screen width
    int y = screenHeight / 4; // Example: 1/4 of screen height

    f.add(c);
    f.setLocation(x, y);
    f.setSize(screenWidth / 2, screenHeight / 2); // Example: Half of screen size
    f.setVisible(true);
    }
    }
    }
    ```

    This code dynamically calculates the position and size of the JFrame based on the screen bounds and divides the screen into quarters for positioning, which should work better in a dual-screen setup. Adjust the positioning and sizing logic as needed to fit your specific requirements and screen layout.

    Lastly, if you're still facing challenges with your Java assignment or need further help with programming assignment, there are resources available online to provide guidance and support like ProgrammingHomeworkHelp.com. These resources can offer valuable insights and help you navigate through any issues you encounter in your coding journey.

Similar Threads

  1. Replies: 0
    Last Post: October 3rd, 2014, 06:54 PM
  2. [SOLVED] Extracting Eclipse project as runnable java isn't working
    By Lora_91 in forum What's Wrong With My Code?
    Replies: 24
    Last Post: February 11th, 2014, 05:02 AM
  3. How to let hibernate know where to look for configuration file
    By splatter in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 23rd, 2013, 05:43 AM
  4. Code is working in Eclipse but when exported to Runnable Jar doesn't work
    By jjain.jitendra@gmail.com in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 24th, 2011, 07:12 AM
  5. How to display OS configuration ffrom JSF page?
    By rcbandit2 in forum JavaServer Pages: JSP & JSTL
    Replies: 5
    Last Post: August 4th, 2011, 05:59 PM

Tags for this Thread