Scrollable/scalable image with buttons on top of it?

Hey guys,
I've had a few half-goes at doing this before but now have to do it for real in my project and I'm struggling to get something clean and I'm looking for pointers.
I want to have an image (typically a schematic, or a map) which is scrollable and zoomable. I want to overlay some buttons on the image for controlling zoom (and other things, but lets keep it simple for now). I want the whole thing to be a custom component that I can drop into another panel, and for that custom component to be resized nicely inline with its parent (i.e. if I put it in a BorderPane.center it should take up the available space and no more or less).
So I started with something logical/simple, a StackPane at the top-level with a ScrollPane containing an ImageView as the first child, and then an 'overlay' panel as the top child of the StackPane to conatain my buttons. I want to anchor my buttons to the top right of the image so I use an Anchor Pane for this. Something like:
public class MapView extends StackPane
    public MapView()
        ImageView imageView = new ImageView(new Image("C:/temp/my-image.jpg"));
        ScrollPane scrollPane = new ScrollPane();
        scrollPane.setPannable(true);
        scrollPane.setContent(imageView);
        getChildren().add(scrollPane);
        HBox zoomButtons = new HBox(5);
        Button zoomInButton = new Button("+");
        zoomButtons.getChildren().add(zoomInButton);
        Button zoomOutButton = new Button("-");
        zoomButtons.getChildren().add(zoomOutButton);
        AnchorPane controls = new AnchorPane();
        AnchorPane.setRightAnchor(zoomButtons, 20.0);
        AnchorPane.setTopAnchor(zoomButtons, 5.0);
        controls.getChildren().add(zoomButtons);
        getChildren().add(controls);
}This gives me the perfect layout but with one massive problem: the AnchorPane is stretched to take up the whole area of the StackPane (which is what I want from a layout perspective) but that means it blocks the mouse input to the underlying image view so I can't scroll.
So I try adding a call to the handy setMouseTransparent method:
controls.setMouseTransparent(true);And now I can scroll my image around, but I have the inverse problem: the buttons are now mouse transparent as well so I can't click them.
Snookered.
So maybe a Group is an option? I try using one instead of the AnchorPane:
ImageView imageView = new ImageView(new Image("C:\\temp\\corso\\pandids\\pandid-2.jpg"));
ScrollPane scrollPane = new ScrollPane();
scrollPane.setPannable(true);
scrollPane.setContent(imageView);
getChildren().add(scrollPane);
HBox zoomButtons = new HBox(5);
Button zoomInButton = new Button("+");
zoomButtons.getChildren().add(zoomInButton);
Button zoomOutButton = new Button("-");
zoomButtons.getChildren().add(zoomOutButton);
Group group = new Group(zoomButtons);
getChildren().add(group);I get my buttons in the middle of the screen and I can both scroll my image and click my buttons. But I can't figure out a way to anchor the buttons up to the top right. Group seems to resize itself to the contents of its children (I imagine there's a reason for this, but it makes Group completely unusable for every scenario I've had for it), so I can't really adjust the size or position of the Group. Calling resize() seems to have no effect and there's no setMaxSize or setPrefSize. Calling setLayoutX doesn't do anything cause its all within a StackPane. The only horribly hack I can think of is to add a dummy component to the group which is the size of the container the group is in. Too painful and too fragile to be a real option.
Snookered again.
Maybe I need a Group at the top level instead of the StackPane, but then it all goes a bit nuts with the ImageView sizing and layout pretty much totally gone.
The only other hack I can come up with is to put my own mouse listener on the anchor pane and implement 'panning' manually, but then the scroll bars won't work so I'll probably have to turn these off.
It seems like this should be really easy, and the first, logical simple approach was so close it hurts. Am I missing something simple, or is it really this hard?

Hi Zonski,
what about this?
        Group group = new Group(zoomButtons);               
        group.translateXProperty().bind(group.layoutXProperty().subtract(20));
        group.translateYProperty().bind(group.layoutYProperty().multiply(-1).add(20));
        getChildren().add(group);Works for me
Cheers
Michael

Similar Messages

  • Image with button skin

    Hi,
        I have a image control which is embed with button skin from swf. The effect is not getting affected in it. Only the image is getting loaded.
    Why is it behaving like this.
    Regards,
    Jayagopal.

    Hi Jayagopal,
    You need to apply various skins for the Button to see the effects....
    .myButton
         upSkin:"assets/buttonUp.png";
         downSkin:"assets/buttonDown.png"
         overSkin:"assets/buttonOver.png"    
    Thanks,
    Bhasker Chari

  • Background Video Menu with Buttons on Top

    Hi there.
    I am trying to create a menu that has a looping video background with the buttons on top of the video.
    I have created a short, 1min video in PPro, and imported it into the background of the menu by first creating a blank menu, then alt/dragging it into the blank menu.
    When I place a button on top of the video, the video no longer plays.
    Can I do it so that the video plays in the background and the buttons on top are active?
    Thanks,
    David

    Hi Bill.
    Here's the screen cap.I've included a screen cap of only the layers at the bottom, in case it's too small to read.
    I'm not sure what you mean by muxed. It gives you the option to pick-whip to both audio and video, or alt/drag both audio and video onto a blank menu background. Do mean using a different file format than .m2v?

  • Still image with button selection

    I'm a newbie with DVD Studio Pro so pardon me if this is a stupid question. I've created my own menu background in Photoshop for a standard menu. This is a chapter index menu. My buttons highlight and function correctly, playing the proper assets. However, in addition to selecting a button and seeing it highlight, I'd also like to have a still image appear in one quadrant of the screen. Each button would trigger a different still image to appear in that quadrant (the stills are taken from the assets relative to each button).
    I've tried bringing the stills in as shapes and putting them in a drop zone in that quadrant (which looks great) but can't figure out how to get the buttons to trigger each image. Is this even possible? Am I trying to do something in a standard menu that can only be done in a layered menu? My understanding is that you can't have music with a layered menu (I do have music) so I'd like to do this in a standard menu.
    Thanks for any help,
    Dan

    Basically layer menus would do this, but they do have issues with compatibility (really it is a series of menus wheen it is done)
    But to trigger sections like you described, no real way of doing that. You can play with overlapping buttons (NOT A GOOD IDEA) and color mapping, but to get what you want, really no good way without series of menus or perhaps using a track as a menu with subtitles/images, and even then iffy how it will work on some machines

  • Rollover images with buttons not working on subsequent pages.

    I'm trying to create an interactive PDF wherein images "pop-up" when the cursor rolls over a trigger button. I've successfully employed the Buttons feature to create three such images on one page. However, on a subsequent page images will not appear upon trigger rollover. All three work perfectly on that first page, and I'm using the same procedure on all images/buttons. I checked to see if something was going on in the Tab Order, but each page has its own Tab Order, so I don't know about that. Working in CS6 for Mac.

    In my InDesign file, I have been very meticulous to link each trigger button with the image button and to assign the appropriate actions to the trigger button. Based on what I have learned, when doing this with InDesign, you make both the trigger object--whether an image or, in my case, a box at 0% transparency that covers text--and the object to be shown/hidden into buttons. Maybe that's where I am getting this wrong? Still, that obviously works for some instances and not for others, so this is confounding.
    I do see what you mean about manually adjusting the objects in Acrobat, and that's a trick for adjusting one or two things, but it's tedious to do that with many links in a document that I'm working on. Given the number of "pop-ups" that I want to create for my completed document, the solution has to take place in InDesign.
    Additionally, I have tried just about every permutation of tab orders in the Object-->Interactive-->Set Tab Order feature in InDesign. All to no avail.
    I thank you very much for your time and efforts on this, Gilad. And I apologize for my lack of facility with forum standards (e.g. "How do I post a file, duh?"). Long time reader, first time post-er, haha.

  • Sliding images with buttons..

    Hi do you know how I could slide throught images using the same buttons... as if i have a right and left buttons and the scroll through just 3 images..
    everytime you hit the left button it keep going left through images and right as well... I tired to set up tweens and buttons but everytime I click the right/left buttons the second time it goes back to the beginning picture instead of the next picture...
    kind of something like this http://piperlime.gap.com/? (the main slide show that is)
    thanks!

    Check this out:
    http://weblogs.macromedia.com/sho/archives/2006/04/flex_sliding_dr.cfm
    Tracy

  • JSpinner with buttons at top and bottom

    I need to have an eight digit number where each digit can be individually incremented and decremented. I think a good solution would be a customized row of JSpinners - one for each digit. But I think it would look better and be easier to use if the up/down buttons were located at the top and bottom of each digit rather than the default of being next to each digit.
    I'm sure it can be done, but I'm still a novice, so can someone point me in the right direction? And any feel how hard this will be?

    Actually, in the end I wrote my own component, based on an early jSpinner done by Shazron Abdullah (IntSpinControl) (thanks Shazron!) . Mine is a multi-digit control that mimics the L&F of a pushwheel switch. I don't think the default arrows look bad, though it's easy enough to change later. Although not quite finished, it was actually easier that I thought it would be (I'm a noobie) and I have learned a lot about Java in the process.
    Thanks to all those higher up the Java ladder helping the rest of us climb up!

  • Problem placing buttons on top of a background image

    My knowledge of Java isn't the greatest and I am currently having problems placing buttons on top of a background image within a JApplet (this is also my first encounter with Applets).
    I'm using a Card Layout in order to display a series of different screens upon request.
    The first card is used as a Splash Screen which is displayed for 5 seconds before changing to the Main Menu card.
    When the Main Menu card is called the background image is not shown but the button is.
    While the Applet is running no errors are shown in the console.
    Full source code can be seen below;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.net.*;
    // First extend JApplet
    public class WOT extends JApplet {
         //--------------- Variables are declared here -----------------
         private CardLayout contentCardLayout = new CardLayout();  // declare CardLayout
         private Container contentContain;     // declare content Container
         private JPanel contentCard, splashScreen, mainMenu, menuImage; // declare content Panels
         private JLabel splash, menu, map; // declare image labels
         private ImageIcon mapBtn; // declare ImageIcons
         private JButton mapOption; // declare option Buttons
         private Timer timer; // declare Timer
         private ActionListener actionListener, mapOptionListener; // declare ActionListener
    //--------------- Initialise Applet -----------------
      public void init() {
         //--------------- Set-up Card Layout -----------------
         contentCard = new JPanel(contentCardLayout); // assign card panels to CardLayout
         //--------------- Splash Screen -----------------
         splashScreen = new JPanel();
         splash = new JLabel(new ImageIcon(getClass().getResource("img/bg.gif")));
         splashScreen.add(splash);
         splashScreen.setSize(600,800);
         splashScreen.setLocation(0,0);
    //--------------- "View Map" Option Button -----------------
         mapBtn = new ImageIcon(getClass().getResource("img/map.gif"));
         mapOption = new JButton(mapBtn);
         mapOption.setBorder(null);
         mapOption.setContentAreaFilled(false);
         mapOption.setSize(150,66);
         mapOption.setLocation(150,450);
         mapOption.setOpaque(false);
         mapOption.setVisible(true);
    //--------------- Main Menu Screen -----------------
         //menuImage = new JPanel(null);
         //menuImage.add(mainMenu);
         //menuImage.setLocation(0,0);
         mainMenu = new JPanel(null);
         menu = new JLabel(new ImageIcon(getClass().getResource("img/menu.gif")));
         menu.setLocation(0,0);
         mainMenu.add(menu);
         //mainMenu.setBackground(Color.WHITE);
         mainMenu.setLocation(0,0);
         mainMenu.setOpaque(false);
         //mainMenu.setSize(150,66);
         mainMenu.add(mapOption);
         //--------------- Map Image Screen -----------------
         map = new JLabel(new ImageIcon(getClass().getResource("img/map.gif")));
         //--------------- Add Cards to CardLayout Panel -----------------
        contentCard.add(splashScreen, "Splash Screen");
         contentCard.add(mainMenu, "Main Menu");
         contentCard.add(map, "Map Image");
    //--------------- Set-up container -----------------
          contentContain = getContentPane(); // set container as content pane
          contentContain.setBackground(Color.WHITE); // set container background colour
           contentContain.setLocation(0,0);
           contentContain.setSize(600,800);
          contentContain.setLayout(new FlowLayout()); // set container layout
           contentContain.add(contentCard);  // cards added
           //--------------- Timer Action Listener -----------------
           actionListener = new ActionListener()
                    public void actionPerformed(ActionEvent actionEvent)
                             //--------------- Show Main Menu Card -----------------
                             contentCardLayout.show(contentCard, "Main Menu");
         //--------------- Map Option Button Action Listener -----------------
           mapOptionListener = new ActionListener()
                    public void actionPerformed(ActionEvent actionEvent)
                             //--------------- Show Main Menu Card -----------------
                             contentCardLayout.show(contentCard, "Map Image");
         //--------------- Timer -----------------               
         timer = new Timer(5000, actionListener);
         timer.start();
         timer.setRepeats(false);
    }Any help would be much appreciated!
    Edited by: bex1984 on May 18, 2008 6:31 AM

    1) When posting here, please use fewer comments. The comments that you have don't help folks who know Java read and understand your program and in fact hinder this ability, which makes it less likely that someone will in fact read your code and help you -- something you definitely don't want to have happen! Instead, strive to make your variable and method names as logical and self-commenting as possible, and use comments judiciously and a bit more sparingly.
    2) Try to use more methods and even classes to "divide and conquer".
    3) To create a panel with a background image that can hold buttons and such, you should create an object that overrides JPanel and has a paintComponent override method within it that draws your image using the graphics object's drawImage(...) method
    For instance:
    an image jpanel:
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import java.net.URISyntaxException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    public class BackgroundImage
        // **** this will have to be changed for your program:
        private static final String IMAGE_PATH = "../../m02/a/images/Forest.jpg";
        private BufferedImage myImage = null;
        private JPanel imagePanel = new JPanel()
            @Override
            protected void paintComponent(Graphics g)
            {   // *** here is where I draw my image
                super.paintComponent(g);  // **** don't forget this!
                if (myImage != null)
                    g.drawImage(myImage, 0, 0, this);
        public BackgroundImage()
            imagePanel.setPreferredSize(new Dimension(600, 450));
            imagePanel.add(new JButton("Foobars Rule!"));
            try
                myImage = createImage(IMAGE_PATH);
            catch (IOException e)
                e.printStackTrace();
            catch (URISyntaxException e)
                e.printStackTrace();
        private BufferedImage createImage(String path) throws IOException,
                URISyntaxException
            URL imageURL = getClass().getResource(path);
            if (imageURL != null)
                return ImageIO.read(new File(imageURL.toURI()));
            else
                return null;
        public JPanel getImagePanel()
            return imagePanel;
    }and an applet that uses it:
    import java.lang.reflect.InvocationTargetException;
    import javax.swing.JApplet;
    import javax.swing.SwingUtilities;
    public class BackgrndImageApplet extends JApplet
        @Override
        public void init()
            try
                SwingUtilities.invokeAndWait(new Runnable()
                    @Override
                    public void run()
                        getContentPane().add(new BackgroundImage().getImagePanel());
            catch (InterruptedException e)
                e.printStackTrace();
            catch (InvocationTargetException e)
                e.printStackTrace();
    }

  • Firefox upon opening an image in a new tab, centers the image from top and bottom and surrounds the image with a grey frame. Just started having the problem today, searched Google to no avail.

    Firefox upon opening an image in a new tab, centers the image from top and bottom and surrounds the image with a grey frame. Just started having the problem today, searched Google to no avail.

    Oh wow, looks like a new feature.
    The "page" links in a stylesheet with the address "resource://gre/res/TopLevelImageDocument.css". If you remove that reference, then the image displays in the old style.
    '''''Edit: Please skip the rest of this post and check out the next one.'''''
    There might be a more elegant solution than that, but you could use a bookmarklet to strip out that link when you want to view the page in its old style. A bookmarklet is a snippet of JavaScript you save on the Bookmarks toolbar for quick access.
    First, copy the following code to the clipboard (it's all one long line):
    <br>javascript:var ssheet=document.querySelector('link[href="resource://gre/res/TopLevelImageDocument.css"]'); if(ssheet)ssheet.parentNode.removeChild(ssheet); void 0;
    Next, if you are not displaying the Bookmarks Toolbar, use View > Toolbars > Bookmarks Toolbar to display it. (If you aren't using the classic Menu bar, press Alt+v to call up the old View menu. Right-clicking the gray area just below the page address also allows you to display the Bookmarks Toolbar.)
    Right-click on the Bookmarks Toolbar (or Mac equivalent of right-click!) and choose New Bookmark.
    Paste the code into the Location box (the second box).
    Then type a useful name in the Name box (e.g., Oldstyle Picture) and click Add.
    Now, when you want to tweak the image display, click the button to run the script.
    Manual clicking is a hassle, so it might make sense to look into other solutions. (Greasemonkey didn't seem to work; I think it might not run on .jpg files.)

  • We are trying to transfer files from PS Elements 13 to our web builder.  We are getting a '?' in the top left hand corners of some of the image boxes. It seems that we are unable to transfer images with this ? on the image.  We have spent a long time taki

    We are trying to 'reconnect' files.  we seem incapable to do so, for some reason.  Try as we might, we aren't able to do it.  can anyone help?

    Please see other thread
    Re: We are trying to transfer files from PS Elements 13 to our web builder.  We are getting a '?' in the top left hand corners of some of the image boxes. It seems that we are unable to transfer images with this ? on the image.  We have spent a long time

  • How to get the original look of firefox 4 with 'firefox button' on top then bookmarks lane following with address bar..?

    i have been using firefox 3.6.16 and just upgraded to version 4 last night. actually the problem is this, in my browser the 'firefox button' and all tabes are shown in the same lane on top.
    what i want is to get the default look of firefox 4 with firefox button on top and all the tabs appearing on beneath this button..(not in same lane)
    am i having due to any preference setting or else? please help

    If the Firefox window is maximized, it will display the tabs in the same line as the Firefox button, it only displays them on a separate line on a non-maximized window.

  • I think I am having shutter issues with my 5D mark iii. image is vignetting on top of frame.

    I think I am having shutter issues with my 5D mark iii. image is vignetting on top of frame. ( left side when shooting portrait).
    does not happen all the time. shoot 20 frames, not a problem then will happen 4 or 5 in a row or every other shot for a few shots.
    Studio situation with 4 lights but it is not a light issue. subject is dark also. all lights fire at full.  happens weather at 1/100 or down to 1/20. these 4 examples were shot at 1/50  f 10 iso 100. raw converted to jpeg. shooting teathered but I dont think that matters. has anyone else had shutter issues? can any one from canon give me any info or help??

    It may be that the flash is firing as the shutter is opening... but if you're having an issue with a sticking shutter, the shutter isn't completely open when the flash fires.  
    If this is the case then it wouldn't matter how long the shutter is open because the flash doesn't provide light continuously when the shutter is open... it only gives a burst.  That momentary burst is normally fired at the moment the shutter finishes opening up completely (but if the shutter is sticky and isn't completely finished opening when the flash fires... you'd have a dark edge.)
    If you used 2nd curtain shutter so that it doesn't fire until the moment before the shutter is intended to close, you shouldn't see vignetting even if the shutter is sticking.
    But this makes me wonder what the shutter count is on your body and if it needs service.
    Tim Campbell
    5D II, 5D III, 60Da

  • Image with transparent background als foreground of a button

    I'd like to build an app with buttons using the phone's accent Color as Background and an Image with transparent Background as foreground of the button. It should look like the tiles on the start screen of WP8.1.
    The following code doesn't work (no foreground appears)
    <Button x:Name="myButton" Background="{ThemeResource PhoneAccentBrush}">
     <Button.Foreground>
         <ImageBrush ImageSource="/Assets/myImage.png"/>                    
     <Button.Foreground>
    </Button>
    Are there any ideas?
    Thanks
    Martin

    Hi mfv_technet,
    The Foreground property is used to get or set a brush that describes the foreground color. So we can not bind the Foreground to a image,
    if I do not misunderstand you, in my mind if we want to set the button look like the tiles on the start screen of WP8.1, maybe you can try to refer to the following xaml:
    <Button x:Name="myButton" Foreground="Red" Background="{ThemeResource PhoneAccentBrush}" Margin="116,136,0,363" Width="195" Height="141">
    <Button.Content>
    <StackPanel Orientation="Vertical">
    <Image Source="/Assets/myImage.png" Width="80" Height="80"></Image>
    <TextBlock Text="Button"></TextBlock>
    </StackPanel>
    </Button.Content>
    </Button>
    The result:
    If I have misunderstood you, please feel free to let me know.
    Best Regards,
    Amy Peng
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Buttons on top of an image?

    Ok, i've got a background image, currently being displayed by a custom canvas class that simply paints the image. I need add some buttons on top of this background image, but how can I do this? The canvas class doesn't allow bottons and the like to added to them, does it? Is there some other component I can extend, set the image as its background, and then add buttons to?
    Thanks in advance.

    import javax.swing.*;
    import java.awt.*;
    public class ImagePanel
    public static void main(String argv[])
    new ImagePanel();
    public ImagePanel()
    JFrame myFrame = new JFrame();
    myFrame.setSize(300, 400);
    myFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    myFrame.getContentPane().add(new MyPanel());
    myFrame.pack();
    myFrame.show();
    public class MyPanel extends JPanel
    ImageIcon aboutimage;
    public MyPanel()
    //JPanel buttonpanel = new JPanel();
    aboutimage = new ImageIcon(getClass().getResource("about.gif"));
    this.setOpaque(false);
    JButton button = new JButton("OK");
    this.add(button, BorderLayout.CENTER);
    public void paint(Graphics g)
    aboutimage.paintIcon(this, g, 0, 0);
    super.paint(g);
    public Dimension getPreferredSize()
    return new Dimension(aboutimage.getIconWidth(),aboutimage.getIconHeight());
    } //end-class-MyPanel
    } //end-class-ImagePanel

  • I Have a UITableView with 17 row. in last 17Th row i applyed cell.selectionStyle = UITableViewCellSelectionStyleNone;  and in this row i also put UIButton with Image -  my QUESTION IS that i want in 17Th row when user tapped Image on button is hide and wh

    I Have a UITableView with 17 row. in last 17Th row i applyed cell.selectionStyle = UITableViewCellSelectionStyleNone;
    and in this row i also put UIButton with Image …
    my QUESTION IS that i want in 17Th row when user tapped Image on button. then Image is hide and when user again tapped then image is shown …
    so PlZ…help me how can i put logic..
    Thanks FrNdZZzzzz…

    Sign in:
    https://developer.apple.com/devforums/
    If you're not a developer, you need to join first:
    https://developer.apple.com/programs/register/

Maybe you are looking for

  • Purchased app not showing on ipad??

    I purchased an app at the itunes store on my computer.  I synced my ipad, but the app did not show up.  It is in the "purchased" section of the app store, but the icloud symbol is shaded out and I cannot access it.  Any ideas?

  • Problems with my new 5th generation ipod nano

    I bought my ipod nano 8GB 5th generation about two months ago. I am having two problems. First, the internal speakers are giving me problems. I always plug the headphones in all the way, and they will work just fine until I barely touch the cord. Som

  • HT1473 if my song is repeated 3 times in my iPad, what's the problem here?

    if my song is repeated 3 times in my iPad, what's the problem here?

  • Reducing Imovie size

    Got 09 Imovie...Its been a drag ever since...yep Im angry....heres the challenge. I made a movie using my imac camera last night. A short clip that would be 10m in the old Imovie ended up being 500....and even when I converted it to mv4, it was still

  • Analog PSTN - ISDN

    Hello, I have a FAX server which need to be connected with ISDN lines. And as the solution is in Algeria where there is no ISDN lines. I think about using a router for conversion from analog to ISDN: Server|---(ISDN)---|Router(FXO)|------|Analog Is t