September 8, 201213 yr Newbies 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. I really need help. Thank you. Edited September 8, 201213 yr by conte
September 9, 201213 yr 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.
September 10, 201213 yr Author Newbies 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!
September 10, 201213 yr 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.
Create an account or sign in to comment