Problem with JPanel's mouse listener!

I am developing a Windows Explorer-like program. I have an JPanel and added JLabels to that panel to reprensent the folders. I think, I kind of have to add mouse listener to JPanel to interact with mouse clicks, gaining and losing focus of JLabels etc. instead of adding every JLabel to mouse listener. So when I added to JPanel a mouse listener, it didn't work how I had expected. When I clicked on labels mouse click events didn't fire but when I clicked somewhere else in the panel it did fire. Is this a bug or am I using mouse listener incorrectly??
Thank for advance :)
Here is my JPanel's mouse listener ->
public void mouseClicked(MouseEvent e) {
int x = e.getX();
int y = e.getY();
System.out.println("Mouse Clicked");
Component c = this.getComponentAt(x,y);
if(c instanceof JLabel){
JLabel label = (JLabel) c;
label.setBackground(Color.LIGHT_GRAY);
}

My main problem is as in windows explorer (if CTRL or SHIFT not pressed) there is only one selected folder (in my case JLabel) and transfering "selection" to one label to another might need lots of extra code.. So I thought using JPanel's mouse listener can overcome this handling problem. But if you are saying, this is the way it has to be done, then so be it :D :D

Similar Messages

  • Problem with Jpanel repaintingl

    Hi!
    I have a problem with Jpanel.
    First , I add a Jscrollpane to the panel and I don't
    see it.
    Second, I have a paint method in the Jpanel and I do there some painting but when I exe the application I can see the panel painting only when I put the mouse cursor
    on the place where the panel need to be.
    It is very strange.
    Help me.
    Yair.

    Example code??
    Can't tell what's wrong otherwise.
    First , I add a Jscrollpane to the panel and I don't
    see it.Have you added anything to this JScrollPane? Unless you set the scroll bar policies to always on you won't see anything if you haven't added anything to the scrollpane.
    Also, if you're only adding this scrollPane to your JPanel initilise it with
    JPanel whippet = new JPanel(new BorderLayout())
    .. then when you add your scrollPanel to your JPanel do this to make sure its added slap in the in middle of it:
    whippet.add(yourScrollPanel, BorderLayout.CENTER);
    Bit more info please - duuuuuuuuuuuuuuuude (man, "Finding Nemo" was well funny didn't you think.. anyways, that's besides the point.... could just be my 8 year old mental age though.. who knows.)?

  • Problem with jpanel zooming

    friends,
    i have a jpanel with image as background and i am adding jlabels dynamically to the jpanel. i have to move the jlabel on the image so i added mouse listener to jlabel. now i want to add zooming functionality to the jpanel.
    now if zoom out jpanel everything works well but jlabel mouse listener location is not changing so if i click on jlabel its not activating listener - i need to click outside of jlabel/jpanel (its original location when its 100% zoom) to activate the listener. how can i correct this ?
    thanks in advance
    i will add example after i cutdown (its part of big application)

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import java.net.*;
    import java.util.ArrayList;
    import java.util.List;
    import javax.imageio.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    public class PP3 extends JFrame {
        private JButton btnStart;
        private JButton btnStop;
        private JLabel logoLabel;
        private JSlider zoom;
        private JPanel mainPanel;
        private JPanel btnPanel;
        private JScrollPane jspane;
        private BackPanel3 secondPanel;
        private boolean start = false;
        public PP3() {
            initComponents();
            setVisible(true);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
        private void initComponents() {
            logoLabel = new JLabel();
            mainPanel = new JPanel();
            btnPanel = new JPanel();
            btnStart = new JButton();
            btnStop = new JButton();
            zoom = new JSlider(0,100,100);
            setBackground(Color.white);
            setLayout(new BorderLayout());
            mainPanel.setBackground(Color.white);
            mainPanel.setBorder(new EtchedBorder());
            mainPanel.setPreferredSize(new Dimension(650, 600));
            mainPanel.setLayout(new CardLayout());
            jspane = new JScrollPane(getSecondPanel());
            mainPanel.add(jspane,"Second Panel");
            add(mainPanel, BorderLayout.CENTER);
            btnPanel.setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weighty = 1.0;
            gbc.gridwidth = gbc.REMAINDER;
            btnPanel.setBackground(Color.white);
            btnPanel.setBorder(new EtchedBorder());
            btnPanel.setPreferredSize(new Dimension(150, 600));
            btnStart.setText("Start Labelling");
            btnPanel.add(btnStart, gbc);
            btnStart.setEnabled(true);
            btnStart.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    start = true;
                    btnStart.setEnabled(false);
                    btnStop.setEnabled(true);
                    if(secondPanel != null){
                        secondPanel.setStart(start);
                        Cursor moveCursor = new Cursor(Cursor.TEXT_CURSOR);
                        secondPanel.setCursor(moveCursor);
            btnStop.setText("Done Labelling");
            btnPanel.add(btnStop, gbc);
            btnStop.setEnabled(false);
            btnStop.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent ae){
                    start = false;
                    btnStart.setEnabled(true);
                    btnStop.setEnabled(false);
                    if(secondPanel != null){
                        secondPanel.setStart(start);
                        Cursor moveCursor = new Cursor(Cursor.DEFAULT_CURSOR);
                        secondPanel.setCursor(moveCursor);
            final JLabel zoomLabel = new JLabel("Zoom");
            zoomLabel.setBorder(BorderFactory.createEtchedBorder());
            gbc.weighty = 0;
            gbc.weightx = 1.0;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            btnPanel.add(zoomLabel, gbc);
            btnPanel.add(zoom, gbc);
            zoom.addChangeListener(new ChangeListener() {
                public void stateChanged(ChangeEvent ce) {
                    JSlider source = (JSlider)ce.getSource();
                    if(secondPanel != null) {
                        secondPanel.setZoomFactor((double)source.getValue());
                        zoomLabel.setText("Zoom = " + source.getValue()/100.0);
            String id = "<html><nobr>show label</nobr><br><center>locations";
            JCheckBox check = new JCheckBox(id, secondPanel.showLocations);
            check.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    secondPanel.toggleShowLocations();
            gbc.weighty = 1.0;
            gbc.fill = GridBagConstraints.NONE;
            btnPanel.add(check, gbc);
            add(btnPanel, BorderLayout.EAST);
            pack();
        public JPanel getSecondPanel() {
            if(secondPanel == null) {
                secondPanel = new BackPanel3("images/cougar.jpg", 850, 1100);
                secondPanel.setStart(false);
            return secondPanel;
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new PP3();
    class BackPanel3 extends JPanel implements MouseListener,
                                               MouseMotionListener{
        String imgPath = null;
        BufferedImage image;
        private int width = 0;
        private int height = 0;
        private double zoomFactor = 1.0;
        private boolean start = false;
        private boolean same = false;
        Cursor hourglassCursor = new Cursor(Cursor.MOVE_CURSOR);
        // choose a declaration according to your java version
        List<JLabel> labels;     // declaration for j2se 1.5+
    //    List labels;           // j2se 1.4-
        JLabel lastSelected;
        boolean showLocations;
        JLabel selectedLabel;
        boolean dragging;
        Point offset;
        int count = 0;
        private static String SELECTED = "selected";
        public BackPanel3(String path, int width, int height){
            setLayout(null);
            this.width = width;
            this.height = height;
            setPreferredSize(new Dimension(width,height));
            addMouseListener(this);
            addMouseMotionListener(this);
            // chose an instantiation according to your java version
            labels = new ArrayList<JLabel>();    // j2se 1.5+
    //        labels = new ArrayList();          // j2se 1.4-
            lastSelected = new JLabel();
            lastSelected.putClientProperty(SELECTED, Boolean.FALSE);
            showLocations = true;
            dragging = false;
            offset = new Point();
            this.imgPath = path;
            setImage();
        public void setImage(){
            try{
                image = getImage(imgPath);
            }catch(Exception e){
                System.out.println(" (init) ERROR: " + e);
                e.printStackTrace();
        public void setStart(boolean flag){
            start = flag;
        public void setZoomFactor(double zoom){
            zoomFactor = (zoom/100);
            setPreferredSize(new Dimension((int)(850*zoomFactor), (int)(1100*zoomFactor)));
            repaint();
            revalidate();
        public double getZoomFactor(){
            return zoomFactor;
        public void toggleShowLocations() {
            showLocations = !showLocations;
            repaint();
        public void mouseClicked(MouseEvent e) {
            if(start){
                JLabel msgLabel = new JLabel("Test " + count++);
                this.add(msgLabel);
                Dimension d = msgLabel.getPreferredSize();
                msgLabel.setBounds(e.getX(), e.getY(), d.width, d.height);
                labels.add(msgLabel);
                msgLabel.putClientProperty(SELECTED, Boolean.FALSE);
                return;
        public void mousePressed(MouseEvent e) {
            Point p = e.getPoint();
            for(int j = 0; j < labels.size(); j++) {
                JLabel label = (JLabel)labels.get(j);
                Rectangle bounds = label.getBounds();
                AffineTransform at =
                    AffineTransform.getScaleInstance(zoomFactor, zoomFactor);
                Shape xs = at.createTransformedShape(bounds);
                if(xs.contains(p)) {
                    selectedLabel = label;
                    Rectangle r = xs.getBounds();
                    offset.x = p.x - r.x;
                    offset.y = p.y - r.y;
                    dragging = true;
                    break;
        public void mouseReleased(MouseEvent e) {
            dragging = false;
        public void mouseDragged(MouseEvent me){
            if(dragging) {
                Rectangle bounds = selectedLabel.getBounds();
                AffineTransform at =
                    AffineTransform.getScaleInstance(1.0/zoomFactor, 1.0/zoomFactor);
                Point2D p = at.transform(me.getPoint(), null);
                int x = (int)(p.getX() - offset.x);
                int y = (int)(p.getY() - offset.y);
                selectedLabel.setLocation(x, y);
                repaint();
        public void mouseMoved(MouseEvent me){
            if(labels.size() == 0)
                return;
            Point p = me.getPoint();
            boolean hovering = false;
            boolean selectionChanged = false;
            for(int j = 0; j < labels.size(); j++) {
                final JLabel label = (JLabel)labels.get(j);
                Rectangle r = label.getBounds();
                AffineTransform at =
                    AffineTransform.getScaleInstance(zoomFactor, zoomFactor);
                Shape scaledBounds = at.createTransformedShape(r);
                if(scaledBounds.contains(p)) {
                    hovering = true;
                    if(!((Boolean)label.getClientProperty(SELECTED)).booleanValue()) {
                        label.putClientProperty("selected", Boolean.TRUE);
                        setCursor(hourglassCursor);
                        if(lastSelected != label)  // for only one JLabel
                            lastSelected.putClientProperty(SELECTED, Boolean.FALSE);
                        lastSelected = label;
                        selectionChanged = true;
                        break;
            // reset lastSelected when there is no selection/hovering
            if(!hovering &&
                ((Boolean)lastSelected.getClientProperty(SELECTED)).booleanValue()) {
                lastSelected.putClientProperty(SELECTED, Boolean.FALSE);
                setCursor(Cursor.getDefaultCursor());
                selectionChanged = true;
            if(selectionChanged)
                repaint();
        public void mouseEntered(MouseEvent e) { }
        public void mouseExited(MouseEvent e) { }
        protected void paintComponent(Graphics g){
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.scale(zoomFactor, zoomFactor);
            g2.drawImage(image, 0, 0, this);
            if(showLocations) {
                // show bounds of the actual JLabel children
                // components as they exist on this component
                AffineTransform at = AffineTransform.getScaleInstance(1.0/zoomFactor,
                                                                      1.0/zoomFactor);
                g2.setPaint(Color.blue);
                Component[] c = getComponents();
                for(int j = 0; j < c.length; j++)
                    g2.draw(at.createTransformedShape(c[j].getBounds()));
            // show selected label
            g2.setPaint(Color.red);
            for(int j = 0; j < labels.size(); j++) {
                JLabel label = (JLabel)labels.get(j);
                if(((Boolean)label.getClientProperty("selected")).booleanValue()) {
                    g2.draw(label.getBounds());
                    break;
        protected BufferedImage getImage(String path){
            try{
                URL imgURL = BackPanel3.class.getResource(path);
                if (imgURL == null &&
                       (path.indexOf(":\\") > 0 || path.indexOf(":/") > 0))
                    imgURL = new URL("file:///"+path);
                return getImage(imgURL);
            }catch(MalformedURLException mue){
                System.out.println("error "+mue);
            return null;
        protected BufferedImage getImage(URL url){
            try{
                if (url != null) {
                    BufferedImage source = ImageIO.read(url);
                    double xScale = (double)width / source.getWidth();
                    double yScale = (double)height / source.getHeight();
                    double scale = Math.min(xScale, yScale);
                    int w = (int)(scale*source.getWidth());
                    int h = (int)(scale*source.getHeight());
                    BufferedImage scaled = new BufferedImage(w, h, source.getType());
                    Graphics2D g2 = scaled.createGraphics();
                    g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION,
                                        RenderingHints.VALUE_INTERPOLATION_BICUBIC);
                    // scales faster than getScaledInstance
                    AffineTransform at = AffineTransform.getScaleInstance(scale, scale);
                    g2.drawRenderedImage(source, at);
                    g2.dispose();
                    return scaled;
                }else{
                    return null;
            }catch(IOException ioe){
                System.out.println("read error "+ioe);
                return null;
    }

  • Problem with JPanel in JFrame

    hai ashrivastava..
    thank u for sending this one..now i got some more problems with that screen .. actually i am added one JPanel to JFrame with BorderLayout at south..the problem is when i am drawing diagram..the part of diagram bellow JPanel is now not visible...and one more problem is ,after adding 6 ro 7 buttons remaing buttons are not vissible..how to increase the size of that JPanel...to add that JPanel i used bellow code
    JFrame f = new JFrame();
    JPanel panel = new JPanel();
    f.getContentPane().add(BorderLayout.SOUTH, panel);

    Hi
    JFrame f = new JFrame();
    JPanel panel = new JPanel();
    // Add this line to ur code with ur requiredWidth and requiredHeight
    panel.setPreferredSize(new Dimension(requiredWidth,requiredHeight));
    f.getContentPane().add(BorderLayout.SOUTH, panel);
    This should solve ur problem
    Ashish

  • 870A Fuzion Power has problem with keyboard and mouse movement only in games.

    Hey guys,
    recently built a new system and chose to go with the 870A Fuzion Power mainboard, everything has gone very smoothly execpt for one problem, only when I play games like Crysis 2 ect the mouse seems to jolt around now and again and the keyboard decides to stop responding if I hold down the movement keys, and this is only in game not surfing the web for example. Now, I am using a wireless mouse and keyboard but I plugged in a PS/2 keyboard and the exact same thing happened. I've installed all of the drivers that came with this board and the drivers for the mouse and keyboard. Any of you guys ever had this sort of problem or know how to fix this?
    Thanks.

    I bought a new Macbook pro in june 2010, I didn't have any keyboard or mouse issues prior to upgrading to 10.6.4 supposedly this update was made to fix some issues with keyboard and mouse becoming unresponsive. For me the opposite happened. after the upgrade, my keyboard and mouse (trackpad) becomes sometimes partially unresponsive or totally unresponsive. the only way to solve the problem is by completely turning of the computer and turning back on.. granted it doesn't happen very often.. generally once every about 2-3 weeks but it is still annoying though..
    I didn't have a chance to use the computer too much on the previous version (10.6.3) so I don't know if it is software related or hardware related.. any thoughts?
    Message was edited by: msoued

  • Problem with JPanel.updateUI()

    Hello,
    i have a problem with updateUI(), here's a simple example what's wrong. just compile and run the following piece of code and look what happens after 2 seconds: the left panel will be decrease its width after calling updateUI(), but why? is it a bug of updateUI() or is it my fault?
    import java.awt.*;
    import javax.swing.*;
    public class Test extends JPanel
            private JList m_list;
            private DefaultListModel m_listModel;
            private JPanel m_buttons;
            public static GridBagConstraints creategbc (int x, int y, int w, int h, int wx, int wy, int f)
                    GridBagConstraints gbc = new GridBagConstraints();
                    gbc.gridx = x;
                    gbc.gridy = y;
                    gbc.gridwidth = w;
                    gbc.gridheight = h;
                    gbc.weightx = wx;
                    gbc.weighty = wy;
                    gbc.fill = f;
                    gbc.insets = new Insets(5, 5, 5, 5); // kleinen Rahmen ziehen
                    return gbc;
            public Test ()
                    GridBagLayout gbl = new GridBagLayout();
                    setLayout(gbl);
                    GridBagConstraints gbc;
                    initButtons();
                    gbc = creategbc(0, 0, 1, 1, 20, 100, GridBagConstraints.NONE);
                    gbc.anchor = GridBagConstraints.NORTH;
                    gbl.setConstraints(m_buttons, gbc);
                    add(m_buttons);
                    initList();
                    JScrollPane sp = new JScrollPane(m_list);
                    gbc = creategbc(1, 0, 1, 1, 100, 100, GridBagConstraints.BOTH);
                    gbl.setConstraints(sp, gbc);
                    add(sp);
            public void addItem (String item)
                    m_listModel.addElement(item);
            public void initList ()
                    m_listModel = new DefaultListModel();
                    m_list = new JList(m_listModel);
            public void initButtons ()
                    m_buttons = new JPanel();
                    m_buttons.setLayout(new GridLayout(4, 1, 0, 20));
                    m_buttons.add(new JButton("Neu"));
                    m_buttons.add(new JButton("Bearbeiten"));
                    m_buttons.add(new JButton("L�schen"));
                    m_buttons.add(new JButton("Abfrage"));
            public static void main (String[] args)
                    JFrame f = new JFrame();
                    Test t = new Test();
                    f.setContentPane(t);
                    f.setSize(600, 450);
                    f.setVisible(true);
                    try
                            Thread.sleep(2000);
                    catch (Exception e)
                    t.addItem("Hallo");
                    t.updateUI();

    Hello,
    i have a problem with updateUI(), here's a simple
    example what's wrong. just compile and run the
    following piece of code and look what happens after 2
    seconds: the left panel will be decrease its width
    after calling updateUI(), but why? is it a bug of
    updateUI() or is it my fault?updateUI() its called when the L&F is changed, there is
    rarely a case when you need to call updateUI().
    Why do you call updateUI() if you remove the call to updateUI()
    everything will work OK.
    merry xmas

  • Problem with JPanel and JDesktopPane

    Hi,
    I am having a problem with my app and I wonder if someone can see what I am doing wrong. I have a class that extends JFrame that holds a centered JPanel to draw on. There are also 3-4 other JInternalFrames that are in use.
    From what I have read to use JDesktopPane to organize the JInternalFrames, all you do is add the JInternalFrames to the JDesktopPane and setContentPane to be the JdesktopPane:
            Jpanel panel = new JPanel();
            JDesktopPane dm = new JDesktopPane();
            setContentPane(dm);
            dm.add(panel, BorderLayout.CENTER);
            dm.add(internalFrame1);
            dm.add(internalFrame2);
            dm.add(internalFrame3);But as soon as I add the panel to the JDesktopPane then my JPanel doesnt show up. As I had it before I was adding the panel to the content pane of the Jframe, and adding the JinternalFrames to the layeredPane like this:
            getContentPane().add(panel, BorderLayout.CENTER);
            lp = getLayeredPane();
            lp.add(internalFrame1);
            lp.add(internalFrame2);
            lp.add(internalFrame3);and this worked but the JInternalFrames behaved badly, not getting focus or moving to the top frame when clicked, which I guess is what JDesktopPane is supposed to do. But how do I get my original JPanel in my JFrame to show up when added to the JDesktopPanel?
    Am I missing something here?
    Thanks,
    Paul

    Thanks for your response. I will try that when I get home, although I will be surprised if that works because I am already using setPreferredSize() . It seemed to me that once a Jframe's content pane gets assigned to a JDesktopPane, then the JPanel no longer has anywhere to draw itself, as according to the Sun documentation, you can only add a JInternalFrame to a JDesktopPane.
    So I am thinking its not possible to have a JPanel as the content pane of a JFrame while having a JDesktopPane containing my JInternalFrames. Is this indeed the case?
    Thanks,
    Paul

  • Problem with keyboard and mouse pm8m-v

    I have gotten this pm8m-v from a freind who knew nothing about computers. He had problems with the keyboard and mouse not responding at start up or just freeze on him. So I check it out, called MSI and even sent it to them, they claimed that there was nothing wrong with the board. So here are the specs of the computer now:
    pm8m-v motherboard
    2-256MB memory PC-2700 DDR 333Mhz
    intel P4 2.6GHz
    codegen power supply 300W
    gateway CDW
    western digital 40 harddrive
    the rest is on board stuff
    the problem is still there and it is driving me crazy, can you please help?

    I had the same problem with the PM8M-V, today as a matter of fact, and I kept getting locked up at the point where I had to hit enter to load the WinXP CD to setup the system.  After finding this topic I tried a different keyboard. The one that was being used was a Kennsiington PS2 cheapo, I swapped it for a Microsoft (one of those ergonomic styles and I've had it for a long time) Keyboard PS2, and the problem went away.  I'm typing on the Kennsington right now, so it's fine just wasn't liked by the PM8M-V for some reason.

  • Strange problem with RDP and mouse, only solved after minimize/maximize

    Good day,
    We have this very annoying problem with a RDP Terminal Server. It is Windows Server 2008 R2 SP1.
    This server has the Session Host role installed, with local RDP user licenses.
    We only have this issue when running a certain application.
    This application is called Rockwell FactoryTalk View and this in an application to display industrial processes.
    It will take the Full Screen in a fixed resolution and will display buttons, objects, values... The application also uses Internet Explorer cache so I think it uses ActiveX, Flash or Java, I don't know.
    What sometimes happens is this:
    - The mouse point is able to move in the entire screen (good)
    - The mouse button will only work in 1 certain area of the screen (which is a small rectangle)
    - The mouse "hovering" above objects will also only highlight items that are in this rectangle
    - The keyboard remains functional and with alt-tab other objects or other applications can get focus, but still no mouse clicking
    The problem can be solved by:
    - Minimizing the RDP window and maximizing it again
    - Or: Sending a message to the session using task manager, after clicking "OK" on that message the problem is gone
    Normally, about 5 users will have this application opened in their session, the "crash" is only effecting 1 session.
    The problem seems to happen randomly and we don't know if we should point to the FactoryTalk application, or to Terminal Services/RDP. The end users have no rights to minimize/maximize, this is not the solution. 
    Is it possible to have any input on this please?
    Thank you.

    Hi,
    Thank you for posting in Windows Server Forum.
    Firstly please check with the application support team whether the application is fully supported by Windows Server 2008 R2 in remote session. In addition, suggest you to update the client RDP version to RDP 8.1 and check the result for better feature and functionality. 
    Apart from this, there is Hotfix for the issue. Please download, install and check the result.
    Cause:
    The issue occurs because the remote desktop ActiveX object does not deactivate the focus of the remote desktop session when the focus is lost. Because the focus is still activated, the remote desktop ActiveX object cannot set the focus of the remote desktop
    session again when you change the focus back to the session.
    A remote desktop session does not respond to keyboard input or mouse input after it loses the focus in Windows 7 or in Windows Server 2008 R2
    http://support.microsoft.com/kb/2579381
    Hope it helps!
    Thanks.
    Dharmesh Solanki

  • Weird problem with jpanel vs jframe

    I'm using jmathplot.jar from JMathTools which lets me do 3d plotting. I used a JFrame to get some code to work and it worked fine. Here's the code that worked for a JFrame:
    public class View extends JFrame
        private Model myModel;
        private Plot3DPanel myPanel;
        // ... Components
        public View(Model m)
            myModel = m; 
            // ... Initialize components
            myPanel = new Plot3DPanel("SOUTH");
            myPanel.addGridPlot("Test",myModel.getXRange(),myModel.getYRange(),myModel.getZValues());
            setSize(600, 600);
            setContentPane(myPanel);
            setVisible(true);
    }Here's the class that starts everything:
    public class TestApplet extends JApplet
        public void init()
            //Execute a job on the event-dispatching thread; creating this applet's GUI.
            try
                SwingUtilities.invokeAndWait(new Runnable()
                    public void run()
                        createGUI();
            catch (Exception e)
                e.printStackTrace();
        private void createGUI()
            System.out.println("Creating GUI");
            Model model = new Model();
            View view = new View(model);
    }And here's the Model:
    public class Model
        private double[] myXRange,myYRange;
        private double[][] myZValues;
        public Model()
            createDataSet();
        public double[] getXRange()
            return myXRange;
        public double[] getYRange()
            return myYRange;
        public double[][] getZValues()
            return myZValues;
        private void createDataSet()
            myXRange = new double[10];
            myYRange = new double[10];
            myZValues = new double[10][10];
            for(double i=0;i<10;i++)
                for(double j=0;j<10;j++)
                    double x = i/10;
                    double y = j/10;
                    myXRange[(int) i] = x;
                    myYRange[(int) j] = y;
                    myZValues[(int) i][(int) j]= Math.cos(x*Math.PI)*Math.sin(y*Math.PI);
    }However, as you can see, my main class is a JApplet because ideally I want View to be a JPanel that I add to the applet. All I did was change "extends JFrame" to "extends JApplet" and changed:
    setSize(600, 600);
    setContentPane(myPanel);
    setVisible(true);to
    this.add(myPanel);and added these two lines to createGUI():
            view.setOpaque(true);
            setContentPane(view);When I run it however, it appears really really small. It seems like its drawing the panel to the default size of the applet viewer and doesn't resize it when I resize the applet. I don't know if it's a problem with the library or if I'm doing something wrong in my applet.

    However, as you can see, my main class is a JApplet because ideally I want View to be a JPanel that I add to the applet. All I did was change "extends JFrame" to "extends JApplet" and (...)What do you mean? View extends JApplet? I thought View was meant to extend JPanel in the end...
    When I run it however, it appears really really small. It seems like its drawing the panel to the default size of the applet viewer and doesn't resize it when I resize the applet.Or, the panel has its preferred size, and this latter is too small. Actually the panel has the size its container's layout manager awards it (taking or not the panel's preferred, minimum, and maximum sizes into account). See the tutorial on [layout managers|http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html] .
    In particular, this line adds the myPanel to a parent panel (presumably, it is in class View which extends JPanel, whose default layout is FlowLayout):
    this.add(myPanel);
    I don't know if it's a problem with the library or if I'm doing something wrong in my applet.Likely not (presumably the library interfers only in how it computes the Plot3DPanel's preferred size). There's an easy way to tell: try to layout correctly a custom JPanel of yours, containing only e.g. a button with an icon. Once you understand the basics of layout management, revisit the example using ther 3rd-party library.
    N.B.: there are a lot of "likely" and "presumably" in my reply: in order to avoid hardly-educated guesses especially on what is or isn't in your actual code, you'd better provide an SSCCE , which means reproducing the problem without the 3rd party library.

  • I use an iMac (27" 3.4) and have problems with the Magic Mouse. It does not use contact, but opens useless and unrelated submenus with every click, even on the empty desktop. I can't shift, open or close pages. Has anyone out there the same problem?

    I use an iMac 27" (mid 2011). Until recently I had OSX 10.6.8 installed, but both, the HDD and SSD had to be replaced, and I lost all the memory.
    After the repair through Apple Care I had OSX 10.7.5. (Lion) installed, which developed a Magic Mouse problem.
    Unlike with most users, I have no problems with connection, but grapple with a different kind of erratic behaviour.
    All fancy stuff is turned off in the mouse preferences. When I try to move, open or close pages, unrelated submenus pop up and hinder the
    required task. No matter how often I click, these menus stay there, and they even come up when clicking on the bare desktop.
    It renders the mouse absolutely useless, as no work can be done with it.
    The first 'Magic Mouse' had depleted batteries every few days, despite switching it off after use.
    I was supplied a new Mouse, which does better battery-wise, but the problems are the same. I can't get a result by clicking on any link, due to
    the pop-up menus, so both 'Magic Mice' are totally useless.
    At present I am using the old USB mouse from my Mac Pro, and that works still o.k.
    The problem are not the mice, but the software. The first 2 weeks after installation of OSX 10.7.5 the Magic Mouse worked though.
    I have no idea as to what the reason may be.
    Has anyone in the community ever experienced that particular problem. Any hint would be welcomed.
    Thank you!

    Not using any mouse pad, I have a very smooth desktop. But I just tried to use a sheet of A4 printing paper, but no result, the problem persisted.
    Someone on this forum suggested, that USB3 may interfere with the magic mouse.
    I have 2 LaCie HDD's about 70 cm away from the mouse, I use them on Thunderbolt. But in operation or not - the result is the same, the mouse plays up! Just now I was clicking the desktop and the mouse created a new folder!!
    Thanks for the advice, Bee
    Cheers, Gerd

  • Problem with the speaker when listening to music

    I've been having problem with my iphones speaker when im listening to music through it, like u would hear a bad sound and annoying noise, wat can i do to fix this problem?

    Another thing to think of that might help.
    If you hear an odd sound intermittently over speakers when the iphone is near, that could be GSM interference. GSM phones produce this interference when contacting the cell network. You don't have to be using the phone for this to happen. The phone is in constant contact with the cell network to check time, signal strength and a range of other things you might have turn on the phone.
    one way you could test this is to put the iphone into airplane mode and play the music for a while.
    Hope this helps.

  • Problems with Apple Wireless Mouse and Keyboard

    Last week my keyboard started repeating letters and not responding and the mouse started acting like an old mouse with a dirty trackball. I searched many message boards and got no help for my specific problem. I'm on a PowerPC G5 running OS 10.3.9.
    Batteries are good. I have run both a hardware test and disk utility with no problems found. The problem seems to have shown up after an apple software update. Don't know if that could have caused some sort of system incompatibility problem.
    Since both mouse and keyboard work with my powerbook, I don't know what else to do. I have re-paired both mouse and keyboard and had some problems with them showing up. I also have shut down the system, unpluged everything and started up again but nothing has worked.
    If anyone has an answer I would be really greatful. Please help. thanks

    Hi again,
    No, I had not even thought of that. I just unplugged it and plugged it back in and the problem may be fixed!!!!!
    Since the problem is intermittent, I'm not sure yet. The worst trouble I've been having has been in trying to drag things across the screen and I have just been able to do that with several windows.
    Yeah!!! I think you may have done it. I will keep this thread open for a while but I think that was it. You my friend are a genius! I'm a bit embarassed to have not thought of that. I didn't even remember that that antenna existed.
    thanks sooooooo much.

  • Is anyone else experiencing problems with the Music App/listening to music via earphones?

    I am experiencing problems with the music app. It randomly stops producing sound when I'm listening to music. Also, I hear a popping noise when ever I walk with my phone in my pocket while listening with earbuds/earphones. I'm thinking it's because iOS 7 is still glitchy. Hopefully the next update corrects the issues I am having.

    I don't have those problems with my iPhone 5.  It almost sounds like your headset isn't fully plugged in and you might be getting static from the cord rubbing against your clothing.  If you are generating a static charge, it is possible that static is being interpreted by the control channel (the volume buttons, or the play/pause button inline in the headset) as commands.  Does this happen with every headset, or just the one you are using now?
    I use my iPhone 5 fairly heavily with the wired headset, and even a good bit with a Motorola S10HD  bluetooth headset.  I don't have the static issues with either, nor do I have problems with volume dropouts.
    You might want to set an appointment with your local Apple Genius Bar to have them take a look.  If it is just the headset, they should replace it on the spot.  If it is more severe and a hardware issue with your specific iPhone 5s, they should be able to help you too.

  • Problem with removing Magic Mouse battery cover (Its Stuck)

    Well i just got a new Magic mouse for 1st time, cause i needed a mouse that doesn't have a usb lead which gets caught on edges or wrapped around other cables all the time for my Macbook Pro.
    The problem with this mouse is tho, rest of it is great, but the battery cover latch, won't release the actual cover off, as i was checking what kind of batteries it had. Which from what i've seen on the forums here is completely opposite to the problem that everyone else has here of it NOT staying on, or being to loose.
    Mine however is seemingly too TIGHT, or stuck on itself, and therefore won't come free.
    Being that its a brand new mouse (Got it only just today in post 15 Jan 2013), i may not be pulling the latch right or it is actually stuck.
    So i was womdering if anyone else had this problem, and has a solution? Cause even tho i won't be worried about the battery failing straight away. I will need to replace it at some point with new ones.
    Pls help, thx.

    First turn the mouse off, using the tiny slide button below the green light.
    Then sharply flick the small rectangular black button at the bottom of the plate downwards with your finger nail.   The plate should loosen and pop off.
    To replace.   Line up the black button in its rectangular hole and press the plate at point of the circular hole where the sensor shows.
    Turn on the mouse, check the green light is steady, then click the mouse twice to activate it.

Maybe you are looking for

  • CS4 error 150:30

    My Mac had to be replaced and I used my backup hard drive to load the new one.  Nothing in CS4 will boot, giving me this message about licensing. I tried to follow the instructions to repair this -- cannot locate the folders they say are buried in my

  • How do you turn off persmissions

    I looked and couldn't fuind a tread that addressed this questiuon but is there a way as "ADMIN" that I can turn off "permissions" to ALL files, folders etc on the system so that anyone can work with them? The reason I ask is I went and transferred al

  • VBA code not working in SEM-BPS 3.2

    We are currently running on BW 3.1 and SEM-BPS 3.2 environment. I am trying to create a screen in excel with VBA code doing validation on user input. For some reason the code works perfectly fine in standalone Excel. But when it comes to BPS, the cod

  • Dynamic Calc with if statements

    Hello I have a dynamically calced member who's calculation depends on what member of another dimension the user is looking at, so in the calc we have several if statements using the @ismbr function. Our calc looks something like this: If (@ismbr("Dim

  • Can I control the print copies with Adobe forms in WD

    Hi Friends, I had one pages in my adobe form designed in SFP transaction. And I  had created a Interactive Forms include that  in WDA. My requirement is.   >>> I want to control the printing of the pages according to my requirement. How can I do when