Activation sub windows when running multiple apps

Good day you all,

I’ve got a question that is a bit of a hassle to describe, but I’m gonna try.

I’ve build an application (using the awesome Quark’s G4P GUI buildertool). Got one “main”-window (Setting always on top enabled) and several “sub”-windows. When I use the app along with other apps running on windows it seems that when I want to use one of the “sub”-windows there’s no response on using buttons or anything on the “sub”-window. But, when I first click on the “main”-window” and then one a “sub”-window the buttons etc. respond? The code is exported as a executable.

Can someone point me in the right direction how I can avoid first activating the main-window before I can use the sub-windows?

Cheers Marcel.

I don’t think there is an exact solution to the problem because the sub windows are create and launched from the main applet.
If this was my application I would create the sub windows and make them invisible immediately. In the main sketch I would have a welcome screen with a button to “continue” which when clicked makes all the sub windows visible and therefore available :grin:

1 Like

Hi quark,

Thanks for the tip. I’ll see if I can work around the issue taking your suggestion into account.

Cheers Marcel.

The following model may or may not work in your project depending on what you are trying to do. It uses the default Processing window with three (or more) JFrame windows with a single Swing button on each window, each with its own event handler. Therefore, button clicks are registered for each window independently. There is no event dispatch thread in this demo (which may not be mandatory in Processing). You’ll have to experiment. Draw() is non-functional on the main window, but can be fixed by repositioning the default canvas instead of removing it completely. The extra windows may be made visible or invisible as required or closed individually without terminating the main app.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

JFrame frame;
Canvas canvas;
JFrame wndTwo;
JFrame wndThree;
JFrame wndFour;
JButton btn;
JButton btn1;
JButton btn2;
JButton btn3;

int _wndW = 600;
int _wndH = 600;

void setup() {
  frame = (javax.swing.JFrame) ((processing.awt.PSurfaceAWT.SmoothCanvas) surface.getNative()).getFrame();
  canvas = (processing.awt.PSurfaceAWT.SmoothCanvas) ((processing.awt.PSurfaceAWT)surface).getNative();
  frame.setBounds(700, 100, _wndW, _wndH);
  frame.remove(canvas);
  surface.setTitle("Main Window");
  JButton btn = new JButton("Press me.");
  btn.setBounds(50, 90, 100, 30);
  frame.add(btn);
  // **** Btn Action **** //
  btn.addActionListener( new ActionListener() {
    void actionPerformed(ActionEvent actionEvent) {
      println("Hit button on mainWnd");
    }
  }
  );
  btn.repaint();
  wndTwo = new JFrame("WndTwo");
  wndTwo.setBounds(100,500,300,350);
  wndTwo.setVisible(true);
  wndTwo.setLayout(null);
  btn1 = new JButton("Press me.");
  btn1.setBounds(50, 90, 100, 30);
  wndTwo.add(btn1);
  // **** Btn1 Action **** //
  btn1.addActionListener( new ActionListener() {
    void actionPerformed(ActionEvent actionEvent) {
      println("Hit button on wndTwo");
    }
  }
  );
  btn1.repaint();
  wndThree = new JFrame("WndThree");
  wndThree.setBounds(400,200,300,350);
  wndThree.setVisible(true);
  wndThree.setLayout(null);
  btn2 = new JButton("Press me.");
  btn2.setBounds(50, 90, 100, 30);
  wndThree.add(btn2);
  // **** Btn2 Action **** //
  btn2.addActionListener( new ActionListener() {
    void actionPerformed(ActionEvent actionEvent) {
      println("Hit button on wndThree");
    }
  }
  );
  btn2.repaint();
  wndFour = new JFrame("WndFour");
  wndFour.setBounds(100,100,300,350);
  wndFour.setVisible(true);
  wndFour.setLayout(null);
  btn3 = new JButton("Press me.");
  btn3.setBounds(50, 90, 100, 30);
  wndFour.add(btn3);
  // **** Btn3 Action **** //
  btn3.addActionListener( new ActionListener() {
    void actionPerformed(ActionEvent actionEvent) {
      println("Hit button on wndFour");
    }
  }
  );
  btn3.repaint();
}

Thanks svan for replying,

I’ll give you code suggestion a try.

Cheers Marcel.