Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

ScriptMaster + PopUp Menu + fmpro.performScript


This topic is 4526 days old. Please don't post here. Open a new topic instead.

Recommended Posts

  • Newbies
Posted (edited)

I want to change the form of ScrptMaster "PopUp Menu" to call a FileMaker script.

I state that I am a novice in Java programming.

I modified the sample script but nothing happens.

post-72035-0-44975900-1347088520_thumb.p

I really need help.

Thank you.

Edited by conte
Posted

It's because it doesn't work as written in that code....

Are you trying to use the value selected to choose which script to run??

You can change the first few lines to:




// Get the filename where it is RUN

fm_file = fmpro.evaluate("Get(FileName)")



def popup = new PopupMenu();

popup.setChoices( choices.split("n") );

popup.drawPopupMenu();

// Get the script to run from the list 

fm_script = popup.getSelectedItem()

fmpro.performScript(fm_file, fm_script)

return true

Make sure in this case TOC is one of the options available and it works as you might be expecting.

No idea if this is the 'best' way to amend this code, but it does work.

  • Newbies
Posted

I tried this code:


package swing;

import javax.swing.*;

import javax.swing.event.PopupMenuEvent;

import javax.swing.event.PopupMenuListener;

import java.awt.*;

import java.awt.event.*;

import java.lang.reflect.InvocationTargetException;

// Get the filename where it is RUN

fm_file = fmpro.evaluate("Get(FileName)")

def popup = new PopupMenu();

popup.setChoices( choices.split("n") );

popup.drawPopupMenu();

//return popup.getSelectedItem();

public class PopupMenu implements ActionListener, PopupMenuListener, ComponentListener, MouseListener {

/*If I set transparency to 0, then it doesn't detect background clicks to close the popup, so I set it to 7, which seems like the minimum threshold */

private static final Color TRANSPARENT = new Color( 255, 255, 255, 7 );

private JDialog menuFrame;

private JPopupMenu popup;

private String selectedItem;

private String[] choices;

public static void main( String[] args ) throws InterruptedException, InvocationTargetException {

  PopupMenu popup = new PopupMenu();

  String choices = "Choice 1nChoice 2nChoice 3";

  popup.setChoices( choices.split( "n" ) );

  popup.drawPopupMenu();

  System.out.println( "Selection: " + popup.getSelectedItem() );

}

public void setChoices( String[] choices ) {

  this.choices = choices;

}

public String getSelectedItem() {

  return selectedItem;

}

private void drawPopupMenu() {

  menuFrame = new JDialog( (Frame) null, true );

  popup = new JPopupMenu( "Popup" );

  popup.addPopupMenuListener( this );

  for (int n = 0; n < choices.length; n++) {

   JMenuItem choice = new JMenuItem( choices[n] );

   choice.addActionListener( this );

   popup.add( choice );

  }

  menuFrame.setUndecorated( true );

  menuFrame.setBackground( TRANSPARENT );

  Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

  menuFrame.setBounds( 0, 0, (int) screenSize.getWidth(), (int) screenSize.getHeight() );

  menuFrame.addComponentListener( this );

  menuFrame.addMouseListener( this );

  menuFrame.setVisible( true );

}



public void actionPerformed( ActionEvent e ) {

  selectedItem = ((JMenuItem) e.getSource()).getText();

  menuFrame.dispose(); /* Get rid of invisible window after making a selection */

  // If you would like this to trigger a script, reeplace this with some call to a FileMaker script, like this:

  //fmpro.performScript(fileName, scriptName, menuText ); */

  //JOptionPane.showMessageDialog( null, "You picked " + selectedItem );

// Get the script to run from the list

fm_script = popup.getSelectedItem()

fmpro.performScript(fm_file, fm_script)

//return true

}

public void componentShown( ComponentEvent e ) {

  Point mouseLoc = MouseInfo.getPointerInfo().getLocation(); /* Absolute coordinates, need to convert to component coordinates */

  mouseLoc.x -= menuFrame.getX();

  mouseLoc.y -= menuFrame.getY();

  popup.show( menuFrame, (int) mouseLoc.x, (int) mouseLoc.y );

}

public void popupMenuWillBecomeInvisible( PopupMenuEvent e ) {

}

public void popupMenuWillBecomeVisible( PopupMenuEvent e ) {

}

public void popupMenuCanceled( PopupMenuEvent e ) {

}

public void componentResized( ComponentEvent e ) {

}

public void componentMoved( ComponentEvent e ) {

}

public void componentHidden( ComponentEvent e ) {

}

public void mouseClicked( MouseEvent e ) {

  selectedItem = null;

  menuFrame.dispose();

}

public void mousePressed( MouseEvent e ) {

}

public void mouseReleased( MouseEvent e ) {

}

public void mouseEntered( MouseEvent e ) {

}

public void mouseExited( MouseEvent e ) {

}

}

with this parameter:

choices:"TOC, due "

But nothing happens!

Posted

Again, it wont work as written (after the dispose)...

Put all the code I gave you at the top of the script as the first ten lines after the imports, don't split it up.

This topic is 4526 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.