Custom JPanel moves inside JFrame when Jpanel.paintComponent(...) is called

I have a custom JPanel (CompassCalculatorPanel) that is created, setup and placed within a custom JFrame (CompassCalcFrame). Calling the JFrame constructor sets this all up and makes the Frame show up. All is good with placement and drawing initially. Then when a user changes the spinner value (change the compass heading) it is supposed to redraw the arrow within the panel. It does this just fine, but on the repaint, and subsequent paints, the Panel ends up being placed in the upper left corner of the frame, rather than at the place I positioned it. I've tried saving the upper left corner placement coordinates and calling setBounds(...) before and after the paintComponent(...) method is called. This has no effect, the panel still resides at 0, 0.
boldAny help that keeps the panel in place would be appreciated!*bold*
I am opening a new CompassCalcFrame with the following code from another GUI application like this (but this works from an example program perspective):
import com.vikingvirtual.flightsim.CompassCalcFrame;
* @author madViking
public class Main
    public static void main(String[] args)
        CompassCalcFrame CCF = new CompassCalcFrame();
}The CompassCalcFrame.java code:
package com.vikingvirtual.flightsim;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.Point;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTextField;
* @author madViking
public class CompassCalcFrame extends JFrame
    private CompassCalculatorPanel ccPanel;
    private JButton closeButton;
    private JLabel frameTitle;
    private JSeparator frameSeparator1;
    private JSpinner hdgSpinner;
    private JTextField neField;
    private JTextField eField;
    private JTextField seField;
    private JTextField sField;
    private JTextField swField;
    private JTextField wField;
    private JTextField nwField;
    private Point ccPanelPoint;
    public CompassCalcFrame()
        super ("Compass Heading Calculator");
        initComponents();
        this.setVisible(true);
        calculateAndDraw();
    private void initComponents()
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        this.setLayout(null);
        this.setBackground(Color.BLACK);
        this.setForeground(Color.BLACK);
        Container ccPane = this.getContentPane();
        Dimension panelDim = ccPane.getSize();
        Font buttonFont = new Font("Tahoma", 0, 12);
        Font compassFont = new Font("Digital-7", 0, 24);
        Font titleFont = new Font("Lucida Sans", 1, 14);
        frameTitle = new JLabel();
        frameTitle.setText("Compass Heading Calculator");
        frameTitle.setFont(titleFont);
        frameTitle.setForeground(Color.WHITE);
        closeButton = new JButton();
        closeButton.setText("Close");
        closeButton.setToolTipText("Click to close view");
        closeButton.setFont(buttonFont);
        closeButton.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt)
                                                                          {closeButtonActionPerformed(evt);}});
        hdgSpinner = new JSpinner();
        hdgSpinner.setFont(compassFont);
        hdgSpinner.setModel(new javax.swing.SpinnerNumberModel(0, 0, 359, 1));
        hdgSpinner.setToolTipText("Enter heading to see angles change");
        hdgSpinner.addChangeListener(new javax.swing.event.ChangeListener() {public void stateChanged(javax.swing.event.ChangeEvent evt)
                                                                            {hdgSpinnerStateChanged(evt);}});
        neField = new JTextField();
        neField.setBackground(Color.BLACK);
        neField.setEditable(false);
        neField.setFont(compassFont);
        neField.setForeground(Color.WHITE);
        neField.setHorizontalAlignment(JTextField.CENTER);
        neField.setBorder(null);
        eField = new JTextField();
        eField.setBackground(Color.BLACK);
        eField.setEditable(false);
        eField.setFont(compassFont);
        eField.setForeground(Color.WHITE);
        eField.setHorizontalAlignment(JTextField.CENTER);
        eField.setBorder(null);
        seField = new JTextField();
        seField.setBackground(Color.BLACK);
        seField.setEditable(false);
        seField.setFont(compassFont);
        seField.setForeground(Color.WHITE);
        seField.setHorizontalAlignment(JTextField.CENTER);
        seField.setBorder(null);
        sField = new JTextField();
        sField.setBackground(Color.BLACK);
        sField.setEditable(false);
        sField.setFont(compassFont);
        sField.setForeground(Color.WHITE);
        sField.setHorizontalAlignment(JTextField.CENTER);
        sField.setBorder(null);
        swField = new JTextField();
        swField.setBackground(Color.BLACK);
        swField.setEditable(false);
        swField.setFont(compassFont);
        swField.setForeground(Color.WHITE);
        swField.setHorizontalAlignment(JTextField.CENTER);
        swField.setBorder(null);
        wField = new JTextField();
        wField.setBackground(Color.BLACK);
        wField.setEditable(false);
        wField.setFont(compassFont);
        wField.setForeground(Color.WHITE);
        wField.setHorizontalAlignment(JTextField.CENTER);
        wField.setBorder(null);
        nwField = new JTextField();
        nwField.setBackground(Color.BLACK);
        nwField.setEditable(false);
        nwField.setFont(compassFont);
        nwField.setForeground(Color.WHITE);
        nwField.setHorizontalAlignment(JTextField.CENTER);
        nwField.setBorder(null);
        frameSeparator1 = new JSeparator();
        frameSeparator1.setForeground(Color.WHITE);
        frameSeparator1.setBackground(Color.BLACK);
        ccPanel = new CompassCalculatorPanel();
        // Add components to pane
        ccPane.add(frameTitle);
        ccPane.add(closeButton);
        ccPane.add(frameSeparator1);
        ccPane.add(nwField);
        ccPane.add(hdgSpinner);
        ccPane.add(neField);
        ccPane.add(wField);
        ccPane.add(ccPanel);
        ccPane.add(eField);
        ccPane.add(swField);
        ccPane.add(sField);
        ccPane.add(seField);
        // Begin Component Layout
        Insets paneInsets = ccPane.getInsets();
        Point P1 = new Point(0, 0);
        Point P2 = new Point(0, 0);
        Point P3 = new Point(0, 0);
        Dimension size = frameTitle.getPreferredSize();
        frameTitle.setBounds((5 + paneInsets.left), (5 + paneInsets.top), size.width, size.height);
        P1.setLocation((5 + paneInsets.left), (5 + paneInsets.top + size.height + 5));
        P2.setLocation((P1.x + size.width + 5), (paneInsets.top + 5));
        size = closeButton.getPreferredSize();
        closeButton.setBounds(P2.x, P2.y, size.width, size.height);
        frameSeparator1.setBounds(P1.x, P1.y, (panelDim.width - paneInsets.left - paneInsets.right), 10);
        P1.setLocation(P1.x, (P1.y + 10 + 5));
        P2.setLocation((P1.x + 50 + 75), P1.y);
        P3.setLocation((P1.x + 50 + 75 + 60 + 75), P1.y);
        nwField.setBounds(P1.x, P1.y, 50, 26);
        hdgSpinner.setBounds(P2.x, P2.y, 60, 26);
        neField.setBounds(P3.x, P3.y, 50, 26);
        P2.setLocation((P1.x + 50 + 5), (P1.y + 26 + 5));
        P1.setLocation(P1.x, (P1.y + 26 + 5 + 87));
        P3.setLocation((P1.x + 50 + 5 + 200 + 5), P1.y);
        wField.setBounds(P1.x, P1.y, 50, 26);
        ccPanel.setBounds(P2.x, P2.y, 200, 200);
        ccPanelPoint = new Point(P2.x, P2.y);
        eField.setBounds(P3.x, P3.y, 50, 26);
        P1.setLocation(P1.x, (P1.y + 26 + 87 + 5));
        P2.setLocation((P1.x + 50 + 80), P1.y);
        P3.setLocation((P1.x + 50 + 80 + 50 + 80), P1.y);
        swField.setBounds(P1.x, P1.y, 50, 26);
        sField.setBounds(P2.x, P2.y, 50, 26);
        seField.setBounds(P3.x, P3.y, 50, 26);
        // End with Frame sizing
        Dimension frameDim = new Dimension((paneInsets.left + 5 + 50 + 5 + 200 + 5 + 50 + 5 + paneInsets.right + 10), (P1.y + 26 + 5 + paneInsets.bottom + 40));
        this.setPreferredSize(frameDim);
        this.setSize(frameDim);
        //this.setSize((paneInsets.left + 5 + 50 + 5 + 200 + 5 + 50 + 5 + paneInsets.right), (P1.y + 26 + 5 + paneInsets.bottom));
    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt)
        this.dispose();
    private void hdgSpinnerStateChanged(javax.swing.event.ChangeEvent evt)
        calculateAndDraw();
    private void calculateAndDraw()
        int angle = (Integer)hdgSpinner.getValue();
        int[] headings = new int[7];
        int addAngle = 45;
        for (int i = 0; i < 7; i++)
            headings[i] = angle + addAngle;
            if (headings[i] >= 360)
                headings[i] -= 360;
            addAngle += 45;
        neField.setText(String.valueOf(headings[0]));
        eField.setText(String.valueOf(headings[1]));
        seField.setText(String.valueOf(headings[2]));
        sField.setText(String.valueOf(headings[3]));
        swField.setText(String.valueOf(headings[4]));
        wField.setText(String.valueOf(headings[5]));
        nwField.setText(String.valueOf(headings[6]));
        ccPanel.paintComponent(this.getGraphics(), angle);
        ccPanel.setBounds(ccPanelPoint.x, ccPanelPoint.y, 200, 200);
        //ccPanel.repaint(this.getGraphics(), angle);
}The CompassCalculatorPanel.java code:
* To change this template, choose Tools | Templates
* and open the template in the editor.
package com.vikingvirtual.flightsim;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;
import java.awt.Stroke;
* @author madViking
public class CompassCalculatorPanel extends javax.swing.JPanel
    private int xCent;
    private int yCent;
    public CompassCalculatorPanel()
        super();
    @Override
    public void paintComponent(Graphics g)
        paintComponent(g, 0);
    public void repaint(Graphics g, int angle)
        paintComponent(g, angle);
    public void paintComponent(Graphics g, int angle)
        super.paintComponent(g);
        Dimension panelDim = this.getSize();
        xCent = (panelDim.width / 2);
        yCent = (panelDim.height / 2);
        float[] dashArray = {8.0f};
        Graphics2D g2D = (Graphics2D)g;
        g2D.setColor(new Color(53, 153, 0));
        g2D.fillRect(0, 0, panelDim.width, panelDim.height);
        BasicStroke hdgLine = new BasicStroke(3.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
        BasicStroke northLine = new BasicStroke(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10.0f, dashArray, 0.0f);
        Stroke stdStroke = g2D.getStroke();
        // Setup Heading Arrow Points
        Point hdgBottom = new Point(xCent, panelDim.height - 15);
        Point hdgTop = new Point(xCent, 15);
        Point ltHdgArr = new Point(xCent - 10, 20);
        Point rtHdgArr = new Point(xCent + 10, 20);
        // Setup North Arrow Points
        Point nthBottom = new Point(xCent, panelDim.height - 15);
        Point nthTop = new Point(xCent, 15);
        Point ltNthArr = new Point(xCent - 8, 20);
        Point rtNthArr = new Point(xCent + 8, 20);
        // Rotate North Arrow Points
        nthBottom = rotatePoint(nthBottom, (0 - angle), true);
        nthTop = rotatePoint(nthTop, (0 - angle), true);
        ltNthArr = rotatePoint(ltNthArr, (0 - angle), true);
        rtNthArr = rotatePoint(rtNthArr, (0 - angle), true);
        // Draw Heading Line
        g2D.setColor(Color.RED);
        g2D.setStroke(hdgLine);
        g2D.drawLine(hdgBottom.x, hdgBottom.y, hdgTop.x, hdgTop.y);
        g2D.drawLine(ltHdgArr.x, ltHdgArr.y, hdgTop.x, hdgTop.y);
        g2D.drawLine(rtHdgArr.x, rtHdgArr.y, hdgTop.x, hdgTop.y);
        g2D.setStroke(stdStroke);
        // Draw North Line
        g2D.setColor(Color.WHITE);
        g2D.setStroke(northLine);
        g2D.drawLine(nthBottom.x, nthBottom.y, nthTop.x, nthTop.y);
        g2D.drawLine(ltNthArr.x, ltNthArr.y, nthTop.x, nthTop.y);
        g2D.drawLine(rtNthArr.x, rtNthArr.y, nthTop.x, nthTop.y);
        g2D.setStroke(stdStroke);
        // Draw circles
        g2D.setColor(Color.BLUE);
        g2D.setStroke(hdgLine);
        g2D.drawOval(5, 5, (panelDim.width - 10), (panelDim.height - 10));
        g2D.setStroke(stdStroke);
        g2D.fillOval((xCent - 2), (yCent - 2), 5, 5);
        g2D.setStroke(stdStroke);
    private Point rotatePoint(Point p, int angle, boolean centerRelative)
        double ix, iy;
        double hyp = 0.0;
        double degrees = 0.0;
        if (centerRelative == true)
            ix = (double)(p.x - xCent);
            iy = (double)((p.y - yCent)*-1);
        else
            ix = (double)p.x;
            iy = (double)p.y;
        if (ix == 0)
            ix = 1;
        hyp = Math.sqrt((Math.pow(ix, 2)) + (Math.pow(iy, 2)));
        if ((ix >= 0) && (iy >= 0))
            degrees = Math.toDegrees(Math.atan(ix/iy));
        else if((ix >= 0) && (iy < 0))
            degrees = Math.abs(Math.toDegrees(Math.atan(iy/ix)));
            degrees = degrees + 90.0;
        else if ((ix < 0) && (iy < 0))
            degrees = Math.toDegrees(Math.atan(ix/iy));
            degrees = degrees + 180.0;
        else if ((ix < 0) && (iy >= 0))
            degrees = Math.abs(Math.toDegrees(Math.atan(iy/ix)));
            degrees = degrees + 270.0;
        degrees = degrees + angle;
        if (degrees >= 360)
            degrees = degrees - 360;
        if (degrees < 0)
            degrees = degrees + 360;
        double interX = Math.sin(Math.toRadians(degrees));
        double interY = Math.cos(Math.toRadians(degrees));
        interX = interX * hyp;
        interY = ((interY * hyp) * -1);
        if (centerRelative == true)
            p.x = xCent + (int)Math.floor(interX);
            p.y = yCent + (int)Math.floor(interY);
        else
            p.x = (int)Math.floor(interX);
            p.y = (int)Math.floor(interY);
        return p;
}

In response to the first couple of comments made about using Absolute positioning (layout null), I took a look at the page on doing layouts, which happens to be the link you sent. I read about each, and decided that a GridBag layout would be best. So I created a new class called CompassCalcGridBagFrame and set it all up using the same components, but with a Grid Bag layout. I encounter the exact same problem.
Just FYI: I originally created this frame using the NetBeans (6.9.1) Frame form builder. By default that uses the Free Design setting, which creates group layouts for both vertical and horizontal spacing. This is where the problem first came to be. I next used the builder to create an absolute positioning frame, which had the same issue. That is when I started building my frames using code only - no NetBeans GUIs. This is where the absolute layout from scratch code started. Same effect. And now, I've created a Grid Bag layout from code, and same effect. There has to be something I'm missing overall, as this effects all of my different layout designs.
The one thing from gimbal2's previous comment is, should I be using this custom panel within another panel? I am currently adding all of the components (and in Grid Bag, the GridBag layout) to the frame pane itself. Is that OK, or should I use a generic JPanel, and have the components all within that?
Here is the code for the newest frame class (CompassCalcGridBagFrame):
package com.vikingvirtual.flightsim;
import java.awt.Color;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.Point;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JSeparator;
import javax.swing.JSpinner;
import javax.swing.JTextField;
* @author madViking
public class CompassCalcGridBagFrame extends JFrame
    private CompassCalculatorPanel ccPanel;
    private JButton closeButton;
    private JLabel frameTitle;
    private JSeparator frameSeparator1;
    private JSpinner hdgSpinner;
    private JTextField neField;
    private JTextField eField;
    private JTextField seField;
    private JTextField sField;
    private JTextField swField;
    private JTextField wField;
    private JTextField nwField;
    private Point ccPanelPoint;
    public CompassCalcGridBagFrame()
        super ("Compass Heading Calculator");
        initComponents();
        this.pack();
        this.setVisible(true);
        calculateAndDraw();
    private void initComponents()
        this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
        Container ccPane = this.getContentPane();
        ccPane.setLayout(new GridBagLayout());
        ccPane.setBackground(Color.BLACK);
        ccPane.setForeground(Color.BLACK);
        Font buttonFont = new Font("Tahoma", 1, 12);
        Font compassFont = new Font("Digital-7", 0, 24);
        Font titleFont = new Font("Lucida Sans", 1, 14);
        frameTitle = new JLabel();
        frameTitle.setText("Compass Heading Calculator");
        frameTitle.setFont(titleFont);
        frameTitle.setHorizontalAlignment(JLabel.CENTER);
        frameTitle.setPreferredSize(new Dimension(220, 25));
        frameTitle.setForeground(Color.BLACK);
        closeButton = new JButton();
        closeButton.setText("Close");
        closeButton.setToolTipText("Click to close view");
        closeButton.setFont(buttonFont);
        closeButton.setPreferredSize(new Dimension(75, 25));
        closeButton.addActionListener(new java.awt.event.ActionListener() {public void actionPerformed(java.awt.event.ActionEvent evt)
                                                                          {closeButtonActionPerformed(evt);}});
        hdgSpinner = new JSpinner();
        hdgSpinner.setFont(compassFont);
        hdgSpinner.setModel(new javax.swing.SpinnerNumberModel(0, -1, 360, 1));
        hdgSpinner.setToolTipText("Enter heading to see angles change");
        hdgSpinner.setPreferredSize(new Dimension(50, 26));
        hdgSpinner.addChangeListener(new javax.swing.event.ChangeListener() {public void stateChanged(javax.swing.event.ChangeEvent evt)
                                                                            {hdgSpinnerStateChanged(evt);}});
        neField = new JTextField();
        neField.setBackground(Color.BLACK);
        neField.setEditable(false);
        neField.setFont(compassFont);
        neField.setForeground(Color.WHITE);
        neField.setHorizontalAlignment(JTextField.CENTER);
        neField.setPreferredSize(new Dimension(50, 26));
        neField.setBorder(null);
        eField = new JTextField();
        eField.setBackground(Color.BLACK);
        eField.setEditable(false);
        eField.setFont(compassFont);
        eField.setForeground(Color.WHITE);
        eField.setHorizontalAlignment(JTextField.CENTER);
        eField.setPreferredSize(new Dimension(50, 26));
        eField.setBorder(null);
        seField = new JTextField();
        seField.setBackground(Color.BLACK);
        seField.setEditable(false);
        seField.setFont(compassFont);
        seField.setForeground(Color.WHITE);
        seField.setHorizontalAlignment(JTextField.CENTER);
        seField.setPreferredSize(new Dimension(50, 26));
        seField.setBorder(null);
        sField = new JTextField();
        sField.setBackground(Color.BLACK);
        sField.setEditable(false);
        sField.setFont(compassFont);
        sField.setForeground(Color.WHITE);
        sField.setHorizontalAlignment(JTextField.CENTER);
        sField.setPreferredSize(new Dimension(50, 26));
        sField.setBorder(null);
        swField = new JTextField();
        swField.setBackground(Color.BLACK);
        swField.setEditable(false);
        swField.setFont(compassFont);
        swField.setForeground(Color.WHITE);
        swField.setHorizontalAlignment(JTextField.CENTER);
        swField.setPreferredSize(new Dimension(50, 26));
        swField.setBorder(null);
        wField = new JTextField();
        wField.setBackground(Color.BLACK);
        wField.setEditable(false);
        wField.setFont(compassFont);
        wField.setForeground(Color.WHITE);
        wField.setHorizontalAlignment(JTextField.CENTER);
        wField.setPreferredSize(new Dimension(50, 26));
        wField.setBorder(null);
        nwField = new JTextField();
        nwField.setBackground(Color.BLACK);
        nwField.setEditable(false);
        nwField.setFont(compassFont);
        nwField.setForeground(Color.WHITE);
        nwField.setHorizontalAlignment(JTextField.CENTER);
        nwField.setPreferredSize(new Dimension(50, 26));
        nwField.setBorder(null);
        frameSeparator1 = new JSeparator();
        frameSeparator1.setForeground(Color.WHITE);
        frameSeparator1.setBackground(Color.BLACK);
        frameSeparator1.setPreferredSize(new Dimension(320, 10));
        ccPanel = new CompassCalculatorPanel();
        ccPanel.setPreferredSize(new Dimension(250, 250));
        GridBagConstraints gbc = new GridBagConstraints();
        // Begin Component Layout
        gbc.insets = new Insets(0, 0, 0, 0);
        gbc.fill = GridBagConstraints.NONE;
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 0.5;
        gbc.weighty = 0.5;
        gbc.anchor = GridBagConstraints.FIRST_LINE_START;
        ccPane.add(nwField, gbc);
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.gridwidth = 2;
        gbc.gridheight = 1;
        gbc.weightx = 0.4;
        gbc.weighty = 0.4;
        gbc.anchor = GridBagConstraints.PAGE_START;
        ccPane.add(hdgSpinner, gbc);
        gbc.gridx = 3;
        gbc.gridy = 0;
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 0.5;
        gbc.weighty = 0.5;
        gbc.anchor = GridBagConstraints.FIRST_LINE_END;
        ccPane.add(neField, gbc);
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 0.5;
        gbc.weighty = 0.5;
        gbc.anchor = GridBagConstraints.LINE_START;
        ccPane.add(wField, gbc);
        gbc.gridx = 1;
        gbc.gridy = 1;
        gbc.gridwidth = 2;
        gbc.gridheight = 1;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        gbc.anchor = GridBagConstraints.CENTER;
        ccPane.add(ccPanel, gbc);
        gbc.gridx = 3;
        gbc.gridy = 1;
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 0.5;
        gbc.weighty = 0.5;
        gbc.anchor = GridBagConstraints.LINE_END;
        ccPane.add(eField, gbc);
        gbc.gridx = 0;
        gbc.gridy = 2;
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 0.5;
        gbc.weighty = 0.5;
        gbc.anchor = GridBagConstraints.LAST_LINE_START;
        ccPane.add(swField, gbc);
        gbc.gridx = 1;
        gbc.gridy = 2;
        gbc.gridwidth = 2;
        gbc.gridheight = 1;
        gbc.weightx = 0.5;
        gbc.weighty = 0.5;
        gbc.anchor = GridBagConstraints.PAGE_END;
        ccPane.add(sField, gbc);
        gbc.gridx = 3;
        gbc.gridy = 2;
        gbc.gridwidth = 1;
        gbc.gridheight = 1;
        gbc.weightx = 0.5;
        gbc.weighty = 0.5;
        gbc.anchor = GridBagConstraints.LAST_LINE_END;
        ccPane.add(seField, gbc);
        gbc.gridx = 0;
        gbc.gridy = 3;
        gbc.gridwidth = 4;
        gbc.gridheight = 1;
        gbc.insets = new Insets(10, 5, 10, 5);
        gbc.weightx = 0.6;
        gbc.weighty = 0.6;
        gbc.anchor = GridBagConstraints.CENTER;
        ccPane.add(frameSeparator1, gbc);
        gbc.gridx = 1;
        gbc.gridy = 4;
        gbc.gridwidth = 2;
        gbc.gridheight = 1;
        gbc.anchor = GridBagConstraints.PAGE_START;
        ccPane.add(closeButton, gbc);
    private void closeButtonActionPerformed(java.awt.event.ActionEvent evt)
        this.dispose();
    private void hdgSpinnerStateChanged(javax.swing.event.ChangeEvent evt)
        calculateAndDraw();
    private void calculateAndDraw()
        int angle = (Integer)hdgSpinner.getValue();
        if (angle == -1)
            angle = 359;
        if (angle == 360)
            angle = 0;
        int[] headings = new int[7];
        int addAngle = 45;
        for (int i = 0; i < 7; i++)
            headings[i] = angle + addAngle;
            if (headings[i] >= 360)
                headings[i] -= 360;
            addAngle += 45;
        hdgSpinner.setValue(Integer.valueOf(angle));
        neField.setText(String.valueOf(headings[0]));
        eField.setText(String.valueOf(headings[1]));
        seField.setText(String.valueOf(headings[2]));
        sField.setText(String.valueOf(headings[3]));
        swField.setText(String.valueOf(headings[4]));
        wField.setText(String.valueOf(headings[5]));
        nwField.setText(String.valueOf(headings[6]));
        ccPanel.paintComponent(this.getGraphics(), angle);
}

Similar Messages

  • Play a flash file inside a container or component like jframe or jpanel

    sir ,
    i want to embed a flash file inside a jframe or jpanel,
    is it possible ,please give me related reference of URL providing
    plugin for this.
    i will be very thankful for this great help.
    it is very importent for me.
    bye

    I think JMF will support flash files.

  • Problem with JFrame and JPanel

    Okay, well I'm busy doing a lodge management program for a project and I have programmed this JFrame
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class FinalTest extends JFrame
         public JPanel contentPane;
         public JImagePanel imgPanel;
         private JLabel[] cottageIcon;
         private boolean keepMoving;
         private int selectedCottage;
         public FinalTest()
              super();
              initializeComponent();
              addActionListeners();
              this.setVisible(true);
         private void initializeComponent()
              contentPane = (JPanel)getContentPane();
              contentPane.setLayout(null);
              imgPanel = new JImagePanel("back.png");
               imgPanel.setLayout(null);
              imgPanel.setBackground(new Color(1, 0, 0));
                   addComponent(contentPane, imgPanel, 10,10,imgPanel.getImageWidth(),imgPanel.getImageHeight());
              cottageIcon = new JLabel[6];
              keepMoving = true;
              selectedCottage = 0;
              cottageIcon[0] =  new JLabel();
              //This component will never be added or shown, but needs to be there to cover for no cottage selected
              for(int a = 1; a < cottageIcon.length; a++)
                   cottageIcon[a] = new JLabel("C" + (a));
                   cottageIcon[a].setBackground(new Color(255, 0, 0));
                    cottageIcon[a].setHorizontalAlignment(SwingConstants.CENTER);
                    cottageIcon[a].setHorizontalTextPosition(SwingConstants.LEADING);
                    cottageIcon[a].setForeground(new Color(255, 255, 255));
                    cottageIcon[a].setOpaque(true);
                    addComponent(imgPanel,cottageIcon[a],12,(a-1)*35 + 12,30,30);
                this.setTitle("Cottage Chooser");
                this.setLocationRelativeTo(null);
              this.setSize(new Dimension(540, 430));
         private void addActionListeners()
              imgPanel.addMouseListener(new MouseAdapter()
                   public void mousePressed(MouseEvent e)
                        imgPanel_mousePressed(e);
                   public void mouseReleased(MouseEvent e)
                        imgPanel_mouseReleased(e);
                   public void mouseEntered(MouseEvent e)
                        imgPanel_mouseEntered(e);
              imgPanel.addMouseMotionListener(new MouseMotionAdapter()
                   public void mouseDragged(MouseEvent e)
                        imgPanel_mouseDragged(e);
         private void addComponent(Container container,Component c,int x,int y,int width,int height)
              c.setBounds(x,y,width,height);
              container.add(c);
         private void imgPanel_mousePressed(MouseEvent e)
              for(int a = 1; a < cottageIcon.length; a++)
                   if(withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()))
                        System.out.println("B" + withinBounds(e.getX(),e.getY(),cottageIcon[a].getBounds()));
                        selectedCottage = a;
                        keepMoving = true;
         private void imgPanel_mouseReleased(MouseEvent e)
              System.out.println("called");
              selectedCottage = 0;
              keepMoving = false;
         private void imgPanel_mouseDragged(MouseEvent e)
               System.out.println("XXX" + Math.random() * 100);
              if(keepMoving)
                   int x = e.getX();
                    int y = e.getY();
                    if(selectedCottage!= 0)
                         cottageIcon[selectedCottage].setBounds(x-(30/2),y-(30/2),30,30);
                    if(!legalBounds(imgPanel,cottageIcon[selectedCottage]))
                        keepMoving = false;
                        cottageIcon[selectedCottage].setBounds(imgPanel.getWidth()/2,imgPanel.getHeight()/2,30,30);
              System.out.println(cottageIcon[selectedCottage].getBounds());
         private void imgPanel_mouseEntered(MouseEvent e)
               System.out.println("entered");
         private void but1_actionPerformed(ActionEvent e)
              String input = JOptionPane.showInputDialog(null,"Enter selected cottage");
              selectedCottage = Integer.parseInt(input) - 1;
         public boolean legalBounds(Component containerComponent, Component subComponent)
              int contWidth = containerComponent.getWidth();
              int contHeight = containerComponent.getHeight();
              int subComponentX = subComponent.getX();
              int subComponentY = subComponent.getY();
              int subComponentWidth = subComponent.getWidth();
              int subComponentHeight = subComponent.getHeight();
              if((subComponentX < 0) || (subComponentY < 0) || (subComponentX > contWidth) || (subComponentY > contHeight))
                   return false;
              return true;
         public boolean withinBounds(int mouseX, int mouseY, Rectangle componentRectangle)
              int componentX = (int)componentRectangle.getX();
              int componentY = (int)componentRectangle.getY();
              int componentHeight = (int)componentRectangle.getHeight();
              int componentWidth = (int)componentRectangle.getWidth();
              if((mouseX >= componentX) && (mouseX <= (componentX + componentWidth)) && (mouseY >= componentY) && (mouseY <= (componentY + componentWidth)))
                   return true;
              return false;
         public static void main(String[] args)
              JFrame.setDefaultLookAndFeelDecorated(true);
              //JDialog.setDefaultLookAndFeelDecorated(true);
              try
                   UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
              catch (Exception ex)
                   System.out.println("Failed loading L&F: ");
                   System.out.println(ex);
              FinalTest ft = new FinalTest();
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Image;
    import javax.swing.ImageIcon;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class JImagePanel extends JPanel
      private Image image;
      public JImagePanel(String imgFileName)
           image = new ImageIcon(imgFileName).getImage();
        setLayout(null);
      public void paintComponent(Graphics g)
        g.drawImage(image, 0, 0, null);
      public Dimension getImageSize()
                Dimension size = new Dimension(image.getWidth(null), image.getHeight(null));
             return size;
      public int getImageWidth()
                int width = image.getWidth(null);
                return width;
      public int getImageHeight()
              int height = image.getHeight(null);
              return height;
    }Now the problem I'm having is changing that class to a JFrame, it seems simple but I keep having problems like when it runs from another JFrame nothing pops up. I can do it like this:
    FinalTest ft = new FinalTest();
    ft.setVisible(false);
    JPanel example = ft.contentPanehowever I will probably be marked down on this for bad code. I'm not asking for the work to be done for me, but I'm really stuck on this and just need some pointers so I can carry on with the project. Thanks,
    Steve

    CeciNEstPasUnProgrammeur wrote:
    I'd actually consider your GUI being a JPanel instead of a JFrame quite good design - makes it easy to put the stuff into an applet when necessary...
    Anyway, you should set setVisible() to true to make it appear, not to false. Otherwise, I don't seem to understand your problem.That is actually my problem. I am trying to convert this JFrame to a JPanel

  • Disposing JFrame from JPanel

    Right, I suspect this has an easy solution, or maybe I have already happened on it, but I thought I'd best ask just in case.
    I have an application that creates a JFrame from another JFrame, with a JPanel internal to it. What I want to happen is for the JPanel to do its business in its paintComponent method, and then dispose of its parent JFrame (that's dispose - no System.exit(0)'s here please :) ).
    The only way I can see to do it is to pass a reference to the JFrame when the JPanel is created. But this seems to be a bit messy encapsulation-wise.
    Any comers?

    you could make the parent JFrame have a thread that checked the status of the child JFrame's JPanel every second or so and then close itself when the JPanel is finished doing whatever it is doing.

  • How do I add multiple JPanels to a JFrame?

    I've been trying to do my own little side project to just make something for me and my friends. However, I can't get multiple JPanels to display in one JFrame. If I add more than one JPanel, nothing shows up in the frame. I've tried with SpringLayout, FlowLayout, GridBagLayout, and whatever the default layout for JFrames is. Here is the code that's important:
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import javax.swing.*;
    public class CharSheetMain {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              CharSheetFrame frame=new CharSheetFrame();
              abilityPanel aPanel=new abilityPanel();
              descripPanel dPanel=new descripPanel();
              frame.setLayout(new FlowLayout());
              abilityScore st=new abilityScore();
              abilityScore de=new abilityScore();
              abilityScore co=new abilityScore();
              abilityScore in=new abilityScore();
              abilityScore wi=new abilityScore();
              abilityScore ch=new abilityScore();
              frame.add(aPanel);
              frame.add(dPanel);
              frame.validate();
              frame.repaint();
              frame.pack();
              frame.setVisible(true);
    }aPanel and dPanel both extend JPanel. frame extends JFrame. I can get either aPanel or dPanel to show up, but not both at the same time. Can someone tell me what I'm doing wrong?

    In the future, Swing related questions should be posted in the Swing forum.
    You need to read up on [How to Use Layout Managers|http://download.oracle.com/javase/tutorial/uiswing/layout/index.html]. The tutorial has working example of how to use each layout manager.
    By default the content pane of the frame uses a BorderLayout.
    For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org], that demonstrates the incorrect behaviour.
    The code you posted in NOT a SSCCE, since we don't have access to any of your custom classes. To do simple tests of adding a panel to frame then just create a panel, give it a preferred size and give each panel a different background color so you can see how it works with your choosen layout manager.

  • How do I replace one JPanel on a JFrame with another?

    I want to replace one JPanel on a JFrame with a different JPanel when the user clicks on a certain menu item. The menu item is working corrrectly but I cant seem to repaint / refresh the component.
    My code is as follows:
    c.add(knotPanel, BorderLayout.CENTER);
    c.add(stepPanel, BorderLayout.NORTH);
         if (stepChoice != 9) {
         c.remove(ownPanel);
         c.add(lessonPanel, BorderLayout.EAST);
         else {
         c.remove(lessonPanel);
         c.add(ownPanel, BorderLayout.EAST);
         c.invalidate();
         c.validate();
         c.update(c.getGraphics());
    Any ideas?

    I think you should use CardLayout manager.
    With CardLayout you can switch beetwen JPanels without removing or adding.

  • Putting a jpanel into a jframe

    I have a main JFrame which was created by:
    public class ControllerGUI extends javax.swing.JFrameand inside this somewhere is a JPanel called myPanel.
    I have a seperate class which is a JPanel created by:
    public class Calc extends javax.swing.JPanelI am quite new to swing and have been using the GUI builder in Netbeans, so could someone please tell me how to put the seperate Calc JPanel into the JPanel myPanel which is in the JFrame. Is it something to do with creating a container for it? Thanks.
    Thanks.

    Not sure if you're still around, but here's a very simple example of putting a JPanel derived object into another JPanel. The Calc class here extends JPanel. It does nothing but shows a 3 by 3 grid of JLabels:
    import java.awt.Color;
    import java.awt.GridLayout;
    import javax.swing.BorderFactory;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.SwingConstants;
    class Calc extends JPanel
        public Calc()
            setBorder(BorderFactory.createEmptyBorder(15, 0, 15, 0));
            // what the heck, have it show a 3x3 label grid
            setLayout(new GridLayout(0, 3, 10, 10)); // sets layout for the grid
            for (int i = 0; i < 3; i++)
                for (int j = 0; j < 3; j++)
                    String labelString = "[" + (i + 1) + ", " + (j + 1) + "]";
                    JLabel label = new JLabel(labelString);
                    label.setBorder(BorderFactory.createLineBorder(Color.blue));
                    label.setHorizontalAlignment(SwingConstants.CENTER);
                    add(label); // adds each label to the grid
    }Now I'll add it to myPanel which is a JPanel object, but before adding it, I'll set the myPanel's layout to be BorderLayout, and I'll add the Calc class to the CENTER position:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.GridLayout;
    import javax.swing.BorderFactory;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    public class FooFrame extends JFrame
        // declare and initialize the myPanel JPanel object and
        // the myCalc Calc object:
        private JPanel myPanel = new JPanel();
        private Calc myCalc = new Calc();
        public FooFrame(String s)
            super(s);
            getContentPane().add(myPanel); // add myPanel to the contentPane making it the main panel
            setPreferredSize(new Dimension(500, 400));
            myPanel.setLayout(new BorderLayout());  // here set the layout of mypanel
            myPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
            // create a title panel and add it to the top of myPanel
            JLabel title = new JLabel("Application Title");
            JPanel titlePanel = new JPanel(new FlowLayout()); // redundant since jpanels
                                                            //use flowlayout by default
            titlePanel.add(title);
            myPanel.add(titlePanel, BorderLayout.PAGE_START); // adds title to top of myPanel
            // create a button panel and add it to the bottom of myPanel
            // here we'll use gridlayout
            JPanel buttonPanel = new JPanel(new GridLayout(1, 2, 15, 0));
            JButton okButton = new JButton("OK"); // create buttons
            JButton cancelButton = new JButton("Cancel");
            buttonPanel.add(okButton); // add buttons to button panel
            buttonPanel.add(cancelButton);
            myPanel.add(buttonPanel, BorderLayout.PAGE_END); // adds buttonpanel to bottom of myPanel
            //** add the myCalc object to the center of the myPanel via borderlayout
            myPanel.add(myCalc, BorderLayout.CENTER);
        // initialize and show the JFrame
        private static void createAndShowUI()
            JFrame frame = new FooFrame("FooFrame");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setLocationRelativeTo(null);
            frame.setVisible(true);
        // but be careful to show the JFrame in a thread-safe manner:
        public static void main(String[] args)
            java.awt.EventQueue.invokeLater(new Runnable()
                public void run()
                    createAndShowUI();
    }

  • Having trouble displaying a JPanel on a JFrame

    Hello all,
    I'm fairly new to Java and I am having trouble displaying a JPanel on a JFrame. Pretty much I have a class called Task which has a JPanel object. Everytime the user creates a new task, a JPanel with the required information is created on screen. However, I cannot get the JPanel to display.
    Here is some of the code I have written. If you guys need to see more code to help don't hesitate to ask.
    The user enters the information on the form and clicks the createTask button. If the information entered is valid, a new task is created and the initializeTask method is called.
    private void createTaskButtonMouseClicked(java.awt.event.MouseEvent evt) {                                             
        if (validateNewTaskEntry())
         String name = nameTextField.getText().trim();
         Date dueDate = dueDateChooser.getDate();
         byte hourDue = Byte.parseByte(hourFormattedTextField.getText());
         byte minuteDue = Byte.parseByte(minuteFormattedTextField.getText());
         String amOrPm = amPmComboBox.getSelectedItem().toString();
         String group = groupComboBox.getSelectedItem().toString();
         numberTasks++;
    //     if (numberTasks == 1)
    //     else
         Task newTask = new Task(mainForm, name, dueDate, hourDue, minuteDue,
             amOrPm, group);
         newTask.initializeTask();
         this.setVisible(false);
    }This is the code that I thought would display the JPanel. If I put this code in anther form's load event it will show the panel with the red border.
    public void initializeTask()
         taskPanel = new JPanel();
         taskPanel.setVisible(true);
         taskPanel.setBorder(BorderFactory.createLineBorder(Color.RED));
         taskPanel.setBounds(0,0,50,50);
         taskPanel.setLayout(new BorderLayout());
         mainForm.setLayout(new BorderLayout());
         mainForm.getContentPane().add(taskPanel);
    }I was also wondering if this code had anything to do with it:
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new AddTaskForm(new MainForm()).setVisible(true);
        }As you can see I create a new MainForm. The MainForm is where the task is supposed to be drawn. This code is from the AddTaskForm (where they enter all the information to create a new task). I had to do this because AddTaskForm needs to use variables and methods from the MainForm class. I tried passing the mainForm I already created, but I get this error: non-static variable mainForm cannot be referenced from a static context. So to allow the program to compile I passed in new MainForm() instead. However, in my AddTaskForm class constructor, I pass the original MainForm. Here is the code:
    public AddTaskForm(MainForm mainForm)
       initComponents();
       numberTasks = 0;
       this.mainForm = mainForm;
    }Is a new mainForm actually being created and thats why I can't see the JPanel on the original mainForm? If this is the case, how would I pass the mainForm to addTaskForm? Thanks a ton for any help/suggestions!
    Brian

    UPDATE
    While writing the post an idea popped in my head. I decided to not require a MainForm in the AddTaskForm. Instead to get the MainForm I created an initializeMainForm method.
    This is what I mean by not having to pass new MainForm():
        public static void main(String args[])
         java.awt.EventQueue.invokeLater(new Runnable()
             public void run()
              new MainForm().setVisible(true);
        }Even when I don't create the new MainForm() the JPanel still doesn't show up.
    Again, thanks for any help.
    Brian

  • How to have focus in 2 JPanels on 1 JFrame?

    Hey all..
    Like i wrote in the subject, how can i do that?
    I have 2 JPanels in 1 JFrame. 1 top JPanel and 1 buttom JPanel. I've a keylistener in top JPanel and a buttonslistener in buttom JPanel. When i press on the button on the buttom JPanel, then my keylistener wont trigger in the top JPanel.
    Plz help.
    Thx.

    The whole point to window focus is to avoid this! There is at most one focused component per window.
    As a rule of thumb, when someone uses a KeyListener, they're mistaken. You should be using key binding. This can make your focus problems go away, since you can choose to associate the keyStoke with the whole window, not just the focused component.
    [http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]

  • The JPanel did not show when the menu is selected

    My program consists a JMenu bar with sub menu items. When the user select on the menu items a panel with the gridbag layout will show with all the labels.but the panel did not show. Can anyone show the problem for me ?
    AdminFrameMain.java
    public class AdminFrameMain
         private DisplayMenuBar menubar;
         private DisplayToolBar toolbar;
         private DisplayStatusBar statusbar;     
         public AdminFrameMain()
              JFrame frame = new JFrame("S-League Administration Management System");
              Toolkit kit = frame.getToolkit();
              Dimension windowsize =kit.getScreenSize();
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              Container content = frame.getContentPane();
              content.setLayout(new BorderLayout());
              menubar = new DisplayMenuBar(frame,content);
              toolbar = new DisplayToolBar(content);
              statusbar = new DisplayStatusBar(content);
              frame.setSize(800,600);
              frame.setVisible(true);
         public static void main(String [] args){
              AdminFrameMain tm = new AdminFrameMain();
    DisplayMenuBar.java
    public class DisplayMenuBar
         private JMenu addMenu,addTeamMenu;
         private JMenuBar bar = new JMenuBar();
         private JToolBar toolbar = new JToolBar();
         private JMenuItem addTeamItem;
         private JFrame setFrame;
         private Container setContent;
         private AddTeamManagement addTeamMang;
         public DisplayMenuBar(JFrame frame,Container c)
              setFrame = frame;
              setContent = c;
              SetMenuBar();
         public void SetMenuBar()
         setFrame.setJMenuBar(bar);
         addMenu = new JMenu("Add");
         //file menu items list
         //Add sub menu
         addTeamMenu = new JMenu("Team Management");
         addMenu.add(addTeamMenu);
         //Add sub menu items
         addTeamMenu.add(addTeamItem = new JMenuItem("Add Team"));
         addTeamMenu.setMnemonic('T');     
         addTeamItem.setMnemonic('T');
         //team items listener
         //addTeamItem.addActionListener(taskcommand);          
         addTeamItem.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent e)
                   AddTeamManagement addTeamMang = new AddTeamManagement(setFrame,setContent);
         bar.add(addMenu);
    AddTeamManagement.java
    public class AddTeamManagement
         private JPanel addTeamPanel;
         private JFrame frame;
         private JButton createTeamBt,resetTeamBt;
         private Container addTeamContent;
         private JTextArea teamDescTextArea,teamIndpTextArea;
         private JTextField teamNameField;
         private JLabel teamID,teamDesc,teamInfo,numOfPlayers,teamZone,playersNum;
         private GridBagLayout gridBag;
         private GridBagConstraints constraints;
         public AddTeamManagement(JFrame f,Container c)
              System.out.println("add team mg");
              addTeamPanel = new JPanel();
              frame = f;
              addTeamContent = c;
              gridBag = new GridBagLayout();
              addTeamPanel.setLayout(gridBag);
              addTeamPanel.setBackground(Color.pink);
              constraints = new GridBagConstraints();
              teamID = new JLabel("Team ID:");
              teamDesc = new JLabel("Team Description:");
              teamInfo = new JLabel("Team Info:");
              numOfPlayers = new JLabel("No Of Players:");
              playersNum = new JLabel("15 Maximun");
              teamZone = new JLabel("Team Zone:");
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(teamID,0,0,1,1);
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(teamDesc,1,0,1,1);
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(teamInfo,2,0,1,1);
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(numOfPlayers,3,0,1,1);
              constraints.fill = constraints.VERTICAL;
              constraints.weightx = 1;
              constraints.weighty = 0;
              addComponent(teamZone,4,0,1,1);
              System.out.println("showing");
              addTeamContent.add(addTeamPanel,BorderLayout.CENTER);
         public void addComponent(Component component,int row,int column,int width,int height)
              System.out.println("adding c");
              constraints.gridx = column;
              constraints.gridy = row;
              constraints.gridwidth = width;
              constraints.gridheight = height;
              gridBag.setConstraints(component,constraints);
              addTeamPanel.add(component);
              addTeamPanel.setVisible(true);
    }

    Hello,
    you are missing only one link, just add following line to your actionPerformed method of DisplayMenuBar class and all problem will be solved
    setContent.validate();
    Actually, Swing component does not updated automatically. when you do any changes to the component layout it will set that component as invalidated component. To update the view you need to call validate() method defined in JComponent class.
    Virus

  • Resizing JFrames and JPanels !!!

    Hi Experts,
    I had one JFrame in which there are three objects, these objects are of those classes which extends JPanel. So, in short in one JFrame there are three JPanels.
    My all JPanels using GridBagLayout and JFrame also using same. When I resize my JFrame ,it also resize my all objects.
    My Problem is how should i allow user to resize JPanels in JFrame also?? and if user is resizing one JPanel than other should adjust according to new size ...
    Plese guide me, how should i do this ...
    Thanknig Java Community,
    Dhwanit Shah

    Hey there, thanx for your kind intereset.
    Here is sample code .
    In which there is JFrame, JPanel and in JPanel ther is one JButton.Jpanel is added to JFrame.
    I want to resize JPanel within JFrame,I am able to do resize JFrame and JPanel sets accroding to it.
    import java.awt.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    public class FramePanel extends JFrame {
    JPanel contentPane;
    GridBagLayout gridBagLayout1 = new GridBagLayout();
    public FramePanel() {
    try {
    jbInit();
    catch(Exception e) {
    e.printStackTrace();
    public static void main(String[] args) {
    FramePanel framePanel = new FramePanel();
    private void jbInit() throws Exception {
    contentPane = (JPanel) this.getContentPane();
    contentPane.setLayout(gridBagLayout1);
    this.setSize(new Dimension(296, 284));
    this.setTitle("Frame and Panel Together");
    MyPanel myPanel = new MyPanel();
    this.getContentPane().add(myPanel);
    this.setVisible(true);
    class MyPanel extends JPanel {
    public MyPanel() {
    this.setSize(200,200);
    this.setLayout(new FlowLayout());
    this.setBackground(Color.black);
    this.setVisible(true);
    this.add(new JButton("Dhwanit Shah"));
    I think i might explained my problem
    Dhwanit Shah
    [email protected]

  • Can we add JFrame to JPanel?

    hi
    I m trying to add JFrame which has JPanel with BufferedImage to another JPanel.
    Is it possible? if yes kindly tell me how to achieve this.
    thanx

    Just another cross poster.
    [http://www.java-forums.org/java-2d/16085-how-add-jframe-inside-jpanel.html]
    db

  • JFram or Jpanel maximum size

    How should I set maximum and minimum size of JFrame (or JPanel using BorderLayout) ? Please note setPreferredSize() and setMaximumSize() are not effective.
    Thanks

    You can't set the min/max size of a JPanel in a BorderLayout.
    You can't directly set the min/max size of a JFrame, but you can add a ComponentListener the the JFrame and resize the JFrame when it exceeds you specified sizes.
    Search the forum using "+maximum +addcomponentlistener".
    Of course since this is a Swing question, you should be searching the Swing forum.

  • Add JPanel to a JFrame

    I have two classes. One is the main frame, and the other class is a panel. The constructor of the main frame looks like this:
              JFrame.setDefaultLookAndFeelDecorated(true);
              JFrame frame = new JFrame("main");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JPanel entryMgmt = new EntriesMgmt(dbConn);     
              frame.getContentPane().add(entryMgmt);
              frame.pack();
              frame.setVisible(true);The EntriesMgmt class extends JPanel. The constructor for it looks like this:
    public EntriesMgmt(SqlBackend.DbConn conn){
              this.conn = conn;
              JPanel pane = new JPanel();
              //Add radio buttons
              pane.add(initRadioBtns());
              //Add input area
              pane.add(initInputArea());
              //Add buttons
              pane.add(initButtons());
         }The problem is that only the main window appears and there is nothing in it. I tried creating another JFrame in the EntriesMgmt constructor but it would cause 2 windows to appear and i don't want to use internalFrame because what I'm actually trying to do is have a JTabbedPane in the main window and I would have external JPanel under each tab. But let's concentrate on why is it that my EntriesMgmt panel does not appera in the main window.

    What i did to fix this problem was the following. Since EntriesMgmt class extends JPanel I did not have to define another JPanel in the constructor but I could directly add components. Instead of :
    public EntriesMgmt(){
    JPanel pane = new JPanel();
              //Add radio buttons
              pane.add(initRadioBtns());
              //Add input area
              pane.add(initInputArea());
              //Add buttons
              pane.add(initButtons());I have:
    public EntriesMgmt(){
              //Add radio buttons
              add(initRadioBtns());
              //Add input area
              add(initInputArea());
              //Add buttons
              add(initButtons());And somehow it works. Anyways I would like to know if there was any other way to do it.

  • How can I move some image on JPanel ?

    How can I move some image on JPanel ?
    I want to move it with my arrow keys.
    Plees, give me example code

    1) Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html]Using Layout Managers. You would need to use Absolute Positioning so you can control the position of the image
    2) Add the image to a JLabel and the label to the panel
    3) Read the tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/misc/keybinding.html]How to Use Key Bindings. Then you just assign an Action to each of the arrow keys and use setLocation(...) to move the label.

Maybe you are looking for

  • Font issue: Arabic Transparent/Bold

    I initially posted this comment here: http://forums.adobe.com/thread/773857?tstart=0 (in the wrong forum) so I'm reposting it here: In December 2010, I was not having  problems pdf'ing an MS Word document with Arabic Transparent and Arabic  Transpare

  • E-commerce gateway setup for PO Outbound

    I am trying to configure E-commerce gateway in R12.1.1. I have completed Trading partner setup.( As per the Implementation guide) While i am trying to export a PO using - OUT: Purchase Order (850/ORDERS) program i am getting a blank file. Would appri

  • Lots of code clean-up / inclusion paths throwing errors.

    I just built a test app and I am getting errors all over the place. First, every page has an include with the 'virtual' method. IE... virtual('/Connections/conNightclub.php'); I need this to be include ('Connections/conNightclub.php'); I also noticed

  • Response time is increasing with increase in Clients

    HI All, I have a stateless session bean which is performing a multi-table SQL query via the weblogic connection pool using JDBC thin drivers to Oracle. I have used threads to check the performance of the EJB when the Clients are more than one at a po

  • IPhone backup problem

    So i restored to 2.2 firmware and of course I backed up right before, then when the update finished it asked to setup as a new phone or restore from a backup I did as a new phone thinking I could backup later on, and what happened was it backed up au