1

Currently I'm experincing with things that related to GUI making in Java and I want to try and make GUI that will look as follow :

enter image description here

How do you suggest to do it?

At first I though making class called "My Frame" it'll contain an array that holds the points of each polygon (so each polygon will be a separate frame).

But after rethinking a bit I thought of the purpose of those triangles, I want to make them buttons where each press on one of the button changes the content inside the Octagon, so it's more like the triangles are sort of buttons and the Octagon itself is the content pane, so how do you guys suggest me to achieve this?

Also another related question is that I want to make those triangles move with the Octagon, if the Octagon is being dragged by the mouse, the triangles will move with it as well so should I just parent them to the Octagon frame?

Another thing that I wanted to ask is since I set the frame to be undecorated for the purpose of changing it's shape I eliminated the option to resize the frame as well as I made the iconify and close buttons to disappear, so how can I add those features back, I searched the web but I didn't find any explanation to this.

EDITED DIALOG CLASS :

package rt;

import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ContainerListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionAdapter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.event.MouseInputAdapter;
import javax.swing.event.MouseInputListener;

public class MyDialog extends JDialog {

private int pointX;
private int pointY;
JLabel octagonLabel;
JLabel triangleAboutLabel;
MyMouseInputAdapter mmia;

public MyDialog() {
    octagonLabel = createOctagonLabel();
    triangleAboutLabel = createTriangleAboutLabel();
    JTextField textField = createTextField();
    setContentPane(octagonLabel);
    add(textField);
    setUndecorated(true);
    setBackground(new Color(0, 0, 0, 0));
    pack();
    setLocationRelativeTo(null);
    mmia = new MyMouseInputAdapter();
    addMouseListener(mmia);
    addMouseMotionListener(mmia);
    setVisible(true);
}

private JTextField createTextField() {
    final JTextField field = new JTextField(20);
    field.setText("Type \"exit\" to terminate.");
    field.addActionListener(new ActionListener(){
        @Override
        public void actionPerformed(ActionEvent e) {
            String text = field.getText();
            if ("exit".equalsIgnoreCase(text)) {
                System.exit(0);
            }
        }
    });
    return field;
}

private JLabel createOctagonLabel() {
    Image image = null;
    try {
        image = ImageIO.read(Class.class.getResourceAsStream("/resources/gui/octagon.png"));
    } catch (IOException ex) {
        Logger.getLogger(MyDialog.class.getName()).log(Level.SEVERE, null, ex);
    }
    JLabel label = new JLabel(new ImageIcon(image));
    label.setLayout(new GridBagLayout());
    return label;
}

private JLabel createTriangleAboutLabel() {
    Image image = null;
    try {
        image = ImageIO.read(Class.class.getResourceAsStream("/resources/gui/triangle_about.png"));
    } catch (IOException ex) {
        Logger.getLogger(MyDialog.class.getName()).log(Level.SEVERE, null, ex);
    }
    JLabel label = new JLabel(new ImageIcon(image));
    label.setLayout(new GridBagLayout());
    label.setLocation(octagonLabel.getLocation().x - 32, octagonLabel.getLocation().y - 32);

    return label;
}

private class MyMouseInputAdapter extends MouseInputAdapter {
    @Override
    public void mouseDragged(MouseEvent e) {
        MyDialog.this.setLocation(MyDialog.this.getLocation().x + e.getX() - pointX, MyDialog.this.getLocation().y + e.getY() - pointY);
    }

    @Override
    public void mousePressed(MouseEvent e) {
        pointX = e.getX();
        pointY = e.getY();
    }
}

}

LATEST EDIT : @peeskillet sorry for not being here the last couple of days, family member was in hospital .. I tried to implement what you said I made different mouse listener for the corner triangles, but I came across a problem, the mouseEntered and MouseExited events get called when the mouse position is withing the BORDER of the label (not the polygon) so if I enter the mouse into the borders of the label (but the position of the mouse is still outside of the polygon) and then I decide to move the mouse (while I'm still inside the borders of the label) inside the polygon's borders it won't check if it's inside since mouseEntered have already been called and the check for the point inside of the polygon is taking place in that method (same issue for mouseExited) so I tried instead of overriding the mouseEntered and mouseExited doing my own methods just called them mouseEntered2 and mouseExited2 and I call them every time the mouse moves with mouseMoves event, but after doing it when i move the mouse it doesnt even get called the mouseMoved event and I don't know why.. here's the code :

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.Polygon;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class DragDialog extends JDialog {

private int pointX;
private int pointY;

public DragDialog() {
    JTextField textField = createTextField();
    setContentPane(createBackgroundPanel());
    setUndecorated(true);
    setBackground(new Color(0, 0, 0, 0));
    pack();
    setLocationRelativeTo(null);
    setVisible(true);
}

private JPanel createBackgroundPanel() {
    JPanel panel = new JPanel() {
        @Override
        public Dimension getPreferredSize() {
            return new Dimension(527, 527);
        }
    };
    panel.setOpaque(false);
    panel.setLayout(null);

    String[] filePaths = getFilePaths();
    Map<String, ImageIcon> imageMap = initImages(filePaths);
    Map<String, Rectangle> rectMap = createRectangles();
    Map <String, Polygon> polygonMap = createPolygons();
    for (Map.Entry<String, Rectangle> entry: rectMap.entrySet()) {
        JLabel label = new JLabel();
        label.setOpaque(false);
        String fullImageKey = entry.getKey() + "-default";
        ImageIcon icon = imageMap.get(fullImageKey);
        label.setIcon(icon);
        label.setBounds(entry.getValue());
        if (entry.getKey().equals("northwest") ||
            entry.getKey().equals("northeast") ||
            entry.getKey().equals("southwest") ||
            entry.getKey().equals("southeast")) {
                label.addMouseListener(new CornerLabelMouseListener(entry.getKey(), imageMap, polygonMap.get(entry.getKey())));
        }
        else {
            label.addMouseListener(new SideLabelMouseListener(entry.getKey(), imageMap));
        }
        panel.add(label);
    }

    JLabel octagon = createOctagonLabel();
    octagon.setBounds(85, 85, 357, 357);
    panel.add(octagon);

    return panel;
}



private Map<String, Rectangle> createRectangles() {
    Map<String, Rectangle> rectMap = new HashMap<>();
    rectMap.put("north", new Rectangle(191, 0, 145, 73));
    rectMap.put("northwest", new Rectangle(74, 74, 103, 103));
    rectMap.put("northeast", new Rectangle(348, 74, 103, 103));
    rectMap.put("west", new Rectangle(0, 190, 73, 145));
    rectMap.put("east", new Rectangle(453, 190, 73, 145));
    rectMap.put("south", new Rectangle(190, 453, 145, 73));
    rectMap.put("southwest", new Rectangle(74, 348, 103, 103));
    rectMap.put("southeast", new Rectangle(349, 349, 103, 103));

    return rectMap;
}

private Map <String, Polygon> createPolygons() {
    Map <String, Polygon> polygonMap = new HashMap <> ();
    int [] x = new int[3];
    int [] y = new int [3];
    x[0] = 0;
    x[1] = 103;
    x[2] = 0;
    y[0] = 0;
    y[1] = 0;
    y[2] = 103;
    polygonMap.put("northwest", new Polygon(x, y, 3));
    x[2] = 103;
    polygonMap.put("northeast", new Polygon(x, y, 3));
    y[0] = 103;
    polygonMap.put("southeast", new Polygon(x, y, 3));
    x[1] = 0;
    polygonMap.put("southwest", new Polygon(x, y, 3));
    return polygonMap;
}

private class SideLabelMouseListener extends MouseAdapter {
    private String position;
    private Map<String, ImageIcon> imageMap;

    public SideLabelMouseListener(String position, Map<String, ImageIcon> imageMap) {
        this.imageMap = imageMap;
        this.position = position;
    }

    @Override
    public void mousePressed(MouseEvent e) {
        System.out.println(position + " pressed");
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        JLabel label = (JLabel)e.getSource();
        String fullName = position + "-hovered";
        ImageIcon icon = imageMap.get(fullName);
        label.setIcon(icon);
    }

    @Override
    public void mouseExited(MouseEvent e) {
        JLabel label = (JLabel)e.getSource();
        String fullName = position + "-default";
        ImageIcon icon = imageMap.get(fullName);
        label.setIcon(icon);
    }
}

private class CornerLabelMouseListener extends MouseAdapter{
    private String position;
    private Map <String, ImageIcon> imageMap;
    private Polygon polygon;

    public CornerLabelMouseListener(String position, Map <String, ImageIcon> imageMap, Polygon polygon) {
        this.imageMap = imageMap;
        this.position = position;
        this.polygon= polygon;
    }

    @Override
    public void mousePressed(MouseEvent e) {
        if (polygon.contains(e.getPoint())) {
            System.out.println(position + " pressed");
        }
    }

    @Override
    public void mouseMoved(MouseEvent e) {
        System.out.println("moving");
        mouseEntered2(e);
        mouseExited2(e); 
    }

    //@Override
    public void mouseEntered2(MouseEvent e) {
        System.out.println("point = " +e.getPoint().toString());
        if (polygon.contains(e.getPoint())) {
            System.out.println("here");
            JLabel label = (JLabel)e.getSource();
            String fullName = position + "-hovered";
            ImageIcon icon = imageMap.get(fullName);
            label.setIcon(icon);
        }
    }

    //@Override
    public void mouseExited2(MouseEvent e) {
        if (!polygon.contains(e.getPoint())) {
            JLabel label = (JLabel)e.getSource();
            String fullName = position + "-default";
            ImageIcon icon = imageMap.get(fullName);
            label.setIcon(icon);
        }
    }

}

private String[] getFilePaths() {
    String[] paths = { "north-default.png", "north-hovered.png",
            "northwest-default.png", "northwest-hovered.png",
            "northeast-default.png", "northeast-hovered.png",
            "west-default.png", "west-hovered.png", "east-default.png",
            "east-hovered.png", "south-default.png", "south-hovered.png",
            "southwest-default.png", "southwest-hovered.png",
            "southeast-default.png", "southeast-hovered.png"

    };
    return paths;
}

private Map<String, ImageIcon> initImages(String[] paths) {
    Map<String, ImageIcon> map = new HashMap<>();
    for (String path: paths) {
        ImageIcon icon = null;
        try {
            System.out.println(path);
            icon = new ImageIcon(ImageIO.read(getClass().getResource("/octagonframe/" + path)));
        } catch (IOException e) {

            e.printStackTrace();
        }
        String prefix = path.split("\\.")[0];
        map.put(prefix, icon);
    }
    return map;
}

private JTextField createTextField() {
    final JTextField field = new JTextField(20);
    field.setText("Type \"exit\" to terminate.");
    field.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            String text = field.getText();
            if ("exit".equalsIgnoreCase(text)) {
                System.exit(0);
            }
        }
    });
    return field;
}

private JLabel createOctagonLabel() {
    Image image = null;
    try {
        image = ImageIO.read(getClass().getResource("/octagonframe/octagon.png"));
    } catch (IOException ex) {
        Logger.getLogger(DragDialog.class.getName()).log(Level.SEVERE,
                null, ex);
    }
    JLabel label = new JLabel(new ImageIcon(image));
    label.setLayout(new GridBagLayout());
    label.add(createTextField());

    label.addMouseMotionListener(new MouseMotionAdapter() {
        public void mouseDragged(MouseEvent e) {
            DragDialog.this.setLocation(
                    DragDialog.this.getLocation().x + e.getX() - pointX,
                    DragDialog.this.getLocation().y + e.getY() - pointY);
        }
    });
    label.addMouseListener(new MouseAdapter() {
        public void mousePressed(MouseEvent e) {
            pointX = e.getX();
            pointY = e.getY();
        }
    });

    return label;
}

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            new DragDialog();
        }
    });
}
user3497284
  • 127
  • 2
  • 7

1 Answers1

1

Just Use an image. From your last post you were trying to create the shape of the frame. But you can just use a transparent image.

enter image description here

Test the program.

import java.awt.Color;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class DragDialog extends JDialog {

    private int pointX;
    private int pointY;

    public DragDialog() {
        JLabel backgroundLabel = createBackgroundLabel();
        JTextField textField = createTextField();
        setContentPane(backgroundLabel);
        add(textField);
        setUndecorated(true);
        setBackground(new Color(0, 0, 0, 0));
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    private JTextField createTextField() {
        final JTextField field = new JTextField(20);
        field.setText("Type \"exit\" to terminate.");
        field.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e) {
                String text = field.getText();
                if ("exit".equalsIgnoreCase(text)) {
                    System.exit(0);
                }
            }
        });
        return field;
    }

    private JLabel createBackgroundLabel() {
        Image image = null;
        try {
            image = ImageIO.read(new URL("https://i.stack.imgur.com/A9zlj.png"));
        } catch (IOException ex) {
            Logger.getLogger(DragDialog.class.getName()).log(Level.SEVERE, null, ex);
        }
        JLabel label = new JLabel(new ImageIcon(image));
        label.setLayout(new GridBagLayout());

        label.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
                DragDialog.this.setLocation(DragDialog.this.getLocation().x + e.getX() - pointX,
                        DragDialog.this.getLocation().y + e.getY() - pointY);
            }
        });
        label.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                pointX = e.getX();
                pointY = e.getY();
            }
        });

        return label;
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new DragDialog();
            }
        });
    }
}

Here's the image I used. (Just some simple Photoshop of your image

enter image description here


UPDATE

import java.awt.Color;
import java.awt.Dimension;
import java.awt.GridBagLayout;
import java.awt.Image;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseMotionAdapter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class DragDialog extends JDialog {

    private int pointX;
    private int pointY;

    public DragDialog() {
        JTextField textField = createTextField();
        setContentPane(createBackgroundPanel());
        setUndecorated(true);
        setBackground(new Color(0, 0, 0, 0));
        pack();
        setLocationRelativeTo(null);
        setVisible(true);
    }

    private JPanel createBackgroundPanel() {
        JPanel panel = new JPanel() {
            @Override
            public Dimension getPreferredSize() {
                return new Dimension(527, 527);
            }
        };
        panel.setOpaque(false);
        panel.setLayout(null);

        String[] filePaths = getFilePaths();
        Map<String, ImageIcon> imageMap = initImages(filePaths);
        Map<String, Rectangle> rectMap = createRectangles();

        for (Map.Entry<String, Rectangle> entry: rectMap.entrySet()) {
            JLabel label = new JLabel();
            label.setOpaque(false);
            String fullImageKey = entry.getKey() + "-default";
            ImageIcon icon = imageMap.get(fullImageKey);
            label.setIcon(icon);
            label.setBounds(entry.getValue());
            label.addMouseListener(new LabelMouseListener(entry.getKey(), imageMap));
            panel.add(label);
        }

        JLabel octagon = createOctagonLabel();
        octagon.setBounds(85, 85, 357, 357);
        panel.add(octagon);

        return panel;
    }



    private Map<String, Rectangle> createRectangles() {
        Map<String, Rectangle> rectMap = new HashMap<>();
        rectMap.put("north", new Rectangle(191, 0, 145, 73));
        rectMap.put("northwest", new Rectangle(74, 74, 103, 103));
        rectMap.put("northeast", new Rectangle(348, 74, 103, 103));
        rectMap.put("west", new Rectangle(0, 190, 73, 145));
        rectMap.put("east", new Rectangle(453, 190, 73, 145));
        rectMap.put("south", new Rectangle(190, 453, 145, 73));
        rectMap.put("southwest", new Rectangle(74, 348, 103, 103));
        rectMap.put("southeast", new Rectangle(349, 349, 103, 103));

        return rectMap;
    }

    private class LabelMouseListener extends MouseAdapter {
        private String position;
        private Map<String, ImageIcon> imageMap;

        public LabelMouseListener(String position, Map<String, ImageIcon> imageMap) {
            this.imageMap = imageMap;
            this.position = position;
        }

        @Override
        public void mousePressed(MouseEvent e) {
            System.out.println(position + " pressed");
        }

        @Override
        public void mouseEntered(MouseEvent e) {
            JLabel label = (JLabel)e.getSource();
            String fullName = position + "-hovered";
            ImageIcon icon = imageMap.get(fullName);
            label.setIcon(icon);
        }

        @Override
        public void mouseExited(MouseEvent e) {
            JLabel label = (JLabel)e.getSource();
            String fullName = position + "-default";
            ImageIcon icon = imageMap.get(fullName);
            label.setIcon(icon);
        }
    }

    private String[] getFilePaths() {
        String[] paths = { "north-default.png", "north-hovered.png",
                "northwest-default.png", "northwest-hovered.png",
                "northeast-default.png", "northeast-hovered.png",
                "west-default.png", "west-hovered.png", "east-default.png",
                "east-hovered.png", "south-default.png", "south-hovered.png",
                "southwest-default.png", "southwest-hovered.png",
                "southeast-default.png", "southeast-hovered.png"

        };
        return paths;
    }

    private Map<String, ImageIcon> initImages(String[] paths) {
        Map<String, ImageIcon> map = new HashMap<>();
        for (String path: paths) {
            ImageIcon icon = null;
            try {
                System.out.println(path);
                icon = new ImageIcon(ImageIO.read(getClass().getResource("/octagonframe/" + path)));
            } catch (IOException e) {

                e.printStackTrace();
            }
            String prefix = path.split("\\.")[0];
            map.put(prefix, icon);
        }
        return map;
    }

    private JTextField createTextField() {
        final JTextField field = new JTextField(20);
        field.setText("Type \"exit\" to terminate.");
        field.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String text = field.getText();
                if ("exit".equalsIgnoreCase(text)) {
                    System.exit(0);
                }
            }
        });
        return field;
    }

    private JLabel createOctagonLabel() {
        Image image = null;
        try {
            image = ImageIO.read(getClass().getResource("/octagonframe/octagon.png"));
        } catch (IOException ex) {
            Logger.getLogger(DragDialog.class.getName()).log(Level.SEVERE,
                    null, ex);
        }
        JLabel label = new JLabel(new ImageIcon(image));
        label.setLayout(new GridBagLayout());
        label.add(createTextField());

        label.addMouseMotionListener(new MouseMotionAdapter() {
            public void mouseDragged(MouseEvent e) {
                DragDialog.this.setLocation(
                        DragDialog.this.getLocation().x + e.getX() - pointX,
                        DragDialog.this.getLocation().y + e.getY() - pointY);
            }
        });
        label.addMouseListener(new MouseAdapter() {
            public void mousePressed(MouseEvent e) {
                pointX = e.getX();
                pointY = e.getY();
            }
        });

        return label;
    }

    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                new DragDialog();
            }
        });
    }
}

enter image description here

Community
  • 1
  • 1
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
  • Is it really the best approach ? I want to know just for future reference – user3497284 Apr 04 '14 at 12:39
  • Sorry for late responed wasn't here to answer, and by the best I ment is it like how you usually achieve such stuff or is it considered more of a "dirty" way around ? Also I need the triangles to act like buttons, each one is a button, so should I seperate the octagon from the triangles and use the octagon as a label, each triangle as a button and add them to the container (the label) ? Also 2 questions regarding to this that popped to my head after reading your code : http://tinypic.com/r/2lxxamv/8 (added as URL not enough characters) – user3497284 Apr 04 '14 at 15:34
  • Honestly I never need to do this for production. It just play. Maybe you can ask another question in regards to those question. – Paul Samsotha Apr 04 '14 at 15:43
  • As far as your image question. 1) It because I use `GridBadLayout`, That layout will center components you add to it (to an extent). 2) In this case, there _is_ no difference. I don't need a reference to it, so I can just instantiate it without a reference. – Paul Samsotha Apr 04 '14 at 15:45
  • If you did `DragDialog d = new DragDialog()`, then I can reference to object with `d`, if I wanted to do something like `d.setVisible(true);`. But In this case, I don't need to reference it. The `new` keyword already creates it, and that's all I needed to do. – Paul Samsotha Apr 04 '14 at 15:47
  • As far as the triangles as buttons, that doesn't seem like an easy task :( – Paul Samsotha Apr 04 '14 at 15:48
  • You should also take time to go over [Laying out Components Within a Container](http://docs.oracle.com/javase/tutorial/uiswing/layout/index.html) to learn about the different layout managers and what each one does. – Paul Samsotha Apr 04 '14 at 15:52
  • I see thank you, also regarding to this "Also I need the triangles to act like buttons, each one is a button, so should I seperate the octagon from the triangles and use the octagon as a label, each triangle as a button and add them to the container (the label) ?" what I said make sense ? Is it the right approach ? And If I want to add new iconify and close buttons to the program, is there a way to handle it or do I just add JButtons to do it ? and what If I want to resize the whole thing make it all resizeable how can I achieve it ? – user3497284 Apr 04 '14 at 16:01
  • Looks like you need to do some absolute positioning. You could make each triangle a different image, then add them to a label. and position those labels. Then add mouse listeners to those labels. I can actually picture it now. I'll post an updated answer some time tomorrow. I'll kind of interested to see what I can do. It's late here, so I'll notify you when I have something. – Paul Samsotha Apr 04 '14 at 16:05
  • Sounds good, I'll try to implement mine for now see if I can actually make it, I'll sure come and check your version tomorrow ! – user3497284 Apr 04 '14 at 16:32
  • Sorry been busy to make example. But I see you posted yours. Did you get it to work? – Paul Samsotha Apr 06 '14 at 11:46
  • I've added my own attemp code to the original post, I seperated the octagon and the triangles and I've tried to add 1 triangle but it seems that it only shows what ever I set the contentPane to be so the triangle wont show up unless I'll set it as the content pane, more over I tried to add general mouselistener to eliminate redundant code (because initially I want that all labels will be dragable and wherever you point and drag all the components will move as one (all the labels) but I want to make each triangle act as a seperated button so I'm not sure what i did is actually good – user3497284 Apr 06 '14 at 11:47
  • short answer no, unfortunately, waiting for you code example :S – user3497284 Apr 06 '14 at 11:48
  • Let me work on it. I've been meaning to give it a shot. Give me 30 mins or so :) – Paul Samsotha Apr 06 '14 at 11:48
  • So I finally got it to work. I've posted the code. You'll have to provide your own images through. If you want I can email you the ones I made, but I all did was use photoshop. And I'm sure you'll want to use your own images anyway. But Let me know, I can email you the images. I actually made two images for each triangle. One for hover and one for default. – Paul Samsotha Apr 06 '14 at 14:00
  • Ok I wasn't here but checked the code now, it seems to work but the triangle on the north-west, nort east, south west, south east seem to be bugged because you set their borders as rectangles and the mouselistener detects that the mouse in in the area of those labels even if youre inside the octagon because the border of those specific labels interacts with the octagon so it detects an opaque pixel from the octagon in their border's area where it shouldn't so how could we fix it? also I never worked with Maps so I'll do some reading tomorrows and hopefully I could understand if not Ill ask you – user3497284 Apr 06 '14 at 22:17
  • Just create a polygon for each of the corner labels. Set their coordinates based off the coordinate of those triangles. In the MouseAdapter you can check if the label is the northwest, check if the `northwestTriangle.contains(e.getPoint())`. You many want to use a different listener for the corner, so you don't clutter the code. – Paul Samsotha Apr 07 '14 at 01:05
  • I tried to change it to a polygon already problem is you set for each label later in the code their borders by getting their rectangles and setBorder() can only get 1 point + width & length / rectangle it can't get as params a polygon / couple of points, so I can't really do that @peeskillet – user3497284 Apr 07 '14 at 11:34
  • sorry for not being here the last couple of days, family member was in hospital .. Original post edited – user3497284 Apr 15 '14 at 20:31
  • nvm, got it to work :D I'll add what I did later to my original post because I have to go now :) – user3497284 Apr 16 '14 at 15:44