Separator on JPanel

How can I add a separator component on JPanel similar to JSeparator available for JMeniItem.
Thanks in Advance
Sachin

Hello Sachin,
    JSeparator sepLine= new JSeparator();
    sepLine.setBorder(BorderFactory.createLineBorder(Color.black,1));
    sepLine.setBounds(16,265,500,1); // if null-layout
    myPanel.add(sepLine);Bye
Joerg

Similar Messages

  • How to add separator on JPanel?

    How do you add a separator on a JPanel like shown on the following screen shot?:
    http://www.carpenterdev.com/scrn.jpg
    Thanks,
    --BobC                                                                                                                                                                                                                                                                               

    Thanks! I'll do that - upperPanel JSeparator lowerPanel; Makes sense.
    --BobC                                                                                                                                                                                   

  • Separating a JPanel accross the pages

    Hello,
    we currently have started a new project of a pure Java editor like word, but a light version.
    The default layout we choosed is like the "Page" layout in word, it mean that our text will be separated accross the pages.
    I want to know how to implement something like a JPanel accross multiple page.
    I though about using multiple JPanel in a viewport, then the viewport inside a JScrolPane.
    But our editor is up and working, and I don't know how I'll be able to separate the editing feature accross multiple JPanel. Imagine the user select text in two JPanel, how to handle that?
    Regards
    Kuon

    Hello,
    I am responsible about doing the same editor in pure Java now. Have you find how to do a page layout? I am glad if you share your solution with me. Thank you.
    Meftun.

  • Collisions (Separating Axis Theorem)

    Hi,
    I'm working on a 2D game, it's top-down like GTA2, but I'm havinfgproblems with the collision detector. I know there are a lot of posts about collision already but they didn't help me much. I'm using the separating axis theorem (explained here: http://www.harveycartel.org/metanet/tutorials/tutorialA.html#section1) and most of the code is inspired by http://www.codeproject.com/cs/media/PolygonCollision.asp .
    Separating axis theorem:
    find all axis perpendicular to all the edges of both objects,
    project both objects on the axis,
    if there is an axis where the projections do not overlap, then the objects do not overlap.
    The problem is that I think my code should work. And guess what, it doesn't. I checked the code 30 times this weekend but maybe there is some tiny mistake I overlook each time..
    When I run the program with 6 objects I get this:
    1 2 3 4 5 6
    1: - 0 0 0 0 0
    2: 0 - 1 0 0 0
    3: 0 1 - 0 0 0
    4: 0 0 0 - 0 0
    5: 0 0 0 0 - 0
    6: 0 0 0 0 0 - (1=intersect, 0=doesn't intersect)
    but this is completely wrong. You can run the program yourself to see the exact locations of the objects.
    1 is the triangle at the top,
    2 and 3 are the triangles who share an edge
    4 is the one on the left intersecting with 3
    5 is the triangle on the right
    6 is the parallelogram
    But it really gets weird when I add a 7th object (the one in the comments):
    1 2 3 4 5 6 7
    1: - 0 0 0 0 0 0
    2: 0 - 0 0 0 0 0
    3: 0 0 - 0 0 0 0
    4: 0 0 0 - 0 0 0
    5: 0 0 0 0 - 0 0
    6: 0 0 0 0 0 - 0
    7: 0 0 0 0 0 0 -
    Now 2 and 3 don't intersect anymore! They didn't change I just added another object.
    I'm adding a short explanationof all the classes and the code itself. I know it's a lot of code but I added all the test classes so you can just run Test.Test
    I hope someone can help me with this.
    Thanks,
    El Bandano
    _<h5>package CollisionDetector:</h5>_
    <h6>CollisionDetector</h6>
    The class that is supposed to check for collisions. It will take 2 Props and return a CollisionResult
    <h6>CollisionResult</h6>
    A small class with 2 public fields. For now only the boolean Intersect matters.
    <h6>Interval</h6>
    Another small class that represents an interval of floats. It's pretty simple. Distance should return something negative if 2 intervals overlap.
    _<h5>package World</h5>_
    <h6>MovableProp</h6>
    An interface of an object. All objects should be convex.
    <h6>Vector2D</h6>
    A 2D-vector. It has an x and a y value (floats) and some simple methods. a 2D vector can represent a point or an edge/axis. For a point the x and y are the coordinates. For an axis you need a normalized vector (x^2+y^2=1) and the x and y are coordinates on a parrallell line through (0,0).
    _<h5>package Test</h5>_
    <h6>Test</h6>
    The main class. It makes some objects, prints a matrix showin which intersect eachother and shows a window with all objects.
    <h6>TestMovProp</h6>
    A basic implementation of MovableProp.
    <h6>TestPanel</h6>
    A panel that draws MovableProp.
    _<h5>package CollisionDetector:</h5>_
    <h6>CollisionDetector</h6>
    package CollsisionDetector;
    import World.MovableProp;
    import World.Vector2D;
    import java.util.ArrayList;
    public class CollisionDetector {
        public CollisionDetector(){
        public CollisionResult DetectCollision(MovableProp propA, MovableProp propB) {
            CollisionResult result = new CollisionResult();
            result.Intersect = true;
            result.WillIntersect = true;
            Vector2D[] edges = UniqueEdges(propA, propB);
            // loop through the edges
            // find an axis perpendicular to the edge
            // project the props on the axis
            // check wether they intersect on that axis
            for (Vector2D edge: edges){
                Vector2D axis = edge.getPerpendicular();
                Interval intA = projectPointsOnAxis(propA.getCoordinates(), axis);
                Interval intB = projectPointsOnAxis(propB.getCoordinates(), axis);
                if (intA.distance(intB) > 0)
                    result.Intersect = false;
            return result;
        public Interval projectPointsOnAxis(Vector2D[] points, Vector2D axis){
            Interval i = new Interval();
            for (Vector2D p: points)
                i.add(projectPointOnAxis(p, axis));
            return i;
        public float projectPointOnAxis(Vector2D point, Vector2D axis){
            // axis <-> y=a*x
            float a  = axis.y / axis.x;
            // line <-> y=(-a/1)*x+b
            float a2 = -axis.x / axis.y;
            // b = y-a2*x
            float b = point.y - a2*point.x;
            // y = a *x
            // y = a2*x + b
            // => a*x = a2*x + b
            float x = b/(a-a2);
            float y = a*x;
            // is there a better way to do this?
            return new Float(Math.sqrt(x*x + y*y)).floatValue();
         * Put all edges in 1 array, eliminate doubles (parallels).
        public Vector2D[] UniqueEdges(MovableProp propA,MovableProp propB){
            Vector2D[] aEdges = propA.getEdges();
            Vector2D[] bEdges = propB.getEdges();
            ArrayList<Vector2D> tmp = new ArrayList<Vector2D>();
            for (Vector2D v: aEdges){
                tmp.add(v);
            for (Vector2D v: bEdges){
               if (! tmp.contains(v))
                    tmp.add(v);
            return tmp.toArray(new Vector2D[tmp.size()]);
    }<h6>CollisionResult</h6>
    package CollsisionDetector;
    import World.Vector2D;
    public class CollisionResult {
        public boolean WillIntersect;
        public boolean Intersect;
        public Vector2D MinimumTranslationVector;
        public CollisionResult() {
    }<h6>Interval</h6>
    package CollsisionDetector;
    public class Interval {
        public float min;
        public float max;
        public Interval() {
            min = Float.MAX_VALUE;
            max = Float.MIN_VALUE;
        public void add(float f){
            // no 'else'! In an empty interval both will be true
            if (f>max)
                max = f;
            if (f<min)
                min = f;
        public float distance(Interval interval){
            if (this.min < interval.min) {
                return interval.min - this.min;
            } else {
                return this.min - interval.min;
    }_<h5>package World</h5>_
    <h6>MovableProp</h6>
    package World;
    public interface MovableProp {
        public int getNPoints();
        public Vector2D[] getEdges();
        public Vector2D[] getCoordinates();
    }<h6>Vector2D</h6>
    package World;
    public class Vector2D {
        public float x;
        public float y;
        public Vector2D(float x, float y) {
            this.x = x;
            this.y = y;
        public boolean equals(Object obj){
            if (!(obj instanceof Vector2D)){
                return false;
            }else
                return (this.x == ((Vector2D)obj).x && this.y == ((Vector2D)obj).y);
        public String toString() {
            return ("Vector2D  x=" + x + " ,  y=" + y);
        public void normalize(){
            if (x*x + y*y != 1){
                float x2 = x;
                x /= Math.sqrt(x2*x2+y*y);
                y /= Math.sqrt(x2*x2+y*y);
        public Vector2D getPerpendicular(){
            Vector2D per = new Vector2D(-y,x);
            per.normalize();
            return per;
    }_<h5>package Test</h5>_
    <h6>Test</h6>
    package Test;
    import CollsisionDetector.CollisionDetector;
    import World.MovableProp;
    import java.awt.Polygon;
    import java.util.ArrayList;
    import java.util.Vector;
    import javax.swing.JFrame;
    public class Test {
        public static void main(String args[]) {
            CollisionDetector detect = new CollisionDetector();
            float[] x = new float[3];
            float[] y = new float[3];
            ArrayList<MovableProp> list = new ArrayList<MovableProp>();
            x[0] = 200; x[1] = 300; x[2] = 500;
            y[0] = 400; y[1] = 200; y[2] = 300;
            list.add(new TestMovProp(x,y));
            x[0] = 300; x[1] = 500; x[2] = 600;
            y[0] = 400; y[1] = 400; y[2] = 500;
            list.add(new TestMovProp(x,y));
            x[0] = 200; x[1] = 300; x[2] = 600;
            y[0] = 600; y[1] = 400; y[2] = 500;
            list.add(new TestMovProp(x,y));
            x[0] = 100; x[1] = 200; x[2] = 300;
            y[0] = 800; y[1] = 500; y[2] = 700;
            list.add(new TestMovProp(x,y));
            x[0] = 600; x[1] = 600; x[2] = 700;
            y[0] = 400; y[1] = 700; y[2] = 500;
            list.add(new TestMovProp(x,y));
    //        x[0] = 100; x[1] = 001; x[2] = 900;
    //        y[0] = 001; y[1] = 900; y[2] = 500;
    //        list.add(new TestMovProp(x,y));
            x = new float[4];
            y = new float[4];
            x[0] = 450; x[1] = 550; x[2] = 500; x[3] = 400;
            y[0] = 200; y[1] = 250; y[2] = 650; y[3] = 600;
            list.add(new TestMovProp(x,y));
            int n = list.size();
            boolean[][] matrix = new boolean[n][n];
            for (int i=0; i<n; i++){
                for (int j=0; j<n; j++){
                    if (i!=j)
                    matrix[i][j] = detect.DetectCollision(list.get(i),list.get(j)).Intersect;
            System.out.print("  ");
            for (int i=0; i<n; i++){
                System.out.print("  " + (i+1));
            for (int i=0; i<n; i++){
                System.out.print("\n" + (i+1) + ":  ");
                for (int j=0; j<n; j++){
                    if (i==j)
                        System.out.print("-  ");
                    else if (matrix[i][j])
                        System.out.print("1  ");
                    else
                        System.out.print("0  ");
            System.out.println();
            JFrame window = new JFrame();
            window.setDefaultCloseOperation(window.EXIT_ON_CLOSE);
            window.pack();
            window.setVisible(true);
            window.setContentPane( new TestPanel(list));
            window.pack();
    }<h6>TestMovProp</h6>
    package Test;
    import World.MovableProp;
    import World.Vector2D;
    public class TestMovProp implements MovableProp{
        float[] X;
        float[] Y;
        Vector2D[] coor;
        public TestMovProp(float[] x, float[] y) {
            X=x; Y=y;
            coor = new Vector2D[getNPoints()];
            for(int i=0; i< getNPoints(); i++){
                coor[i] = new Vector2D(X, Y[i]);
    public Vector2D[] getCoordinates(){
    return coor;
    public int getNPoints() {
    return X.length;
    public Vector2D[] getEdges() {
    int n = getNPoints();
    Vector2D[] v = new Vector2D[n];
    for (int i=0; i<n-1; i++){
    v[i] = new Vector2D(X[i]-X[i+1], Y[i]-Y[i+1]);
    v[i].normalize();
    v[n-1] = new Vector2D(X[0]-X[n-1], Y[0]-Y[n-1]);
    v[n-1].normalize();
    return v;
    public String toString() {
    String s = "\n";
    for (Vector2D v: getCoordinates())
    s += ("\n" + v);
    return s;
    <h6>TestPanel</h6>package Test;
    import World.MovableProp;
    import World.Vector2D;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Polygon;
    import java.util.ArrayList;
    import javax.swing.JPanel;
    public class TestPanel extends JPanel {
    public ArrayList<MovableProp> list;
    public TestPanel(ArrayList<MovableProp> list) {
    super();
    this.list = list;
    setPreferredSize(new Dimension(1000,850));
    public void paint(Graphics g) {
    super.paint(g);
    for (MovableProp prop:list){
    Vector2D[] coor = prop.getCoordinates();
    int n = prop.getNPoints();
    g.drawLine((int)coor[0].x, (int)coor[0].y, (int)coor[n-1].x, (int)coor[n-1].y);
    for (int i=0; i<n-1; i++){
    g.drawLine((int)coor[i].x, (int)coor[i].y, (int)coor[i+1].x, (int)coor[i+1].y);

    .java wrote:
    I have been search for what seems like hours, Nice try, but in less than 15 seconds I found a complete discussion on the subject.
    and I still have not managed to find anybody or anything that can clearly answer these three questions:
    1. What is SAT?
    2. How does it apply to 2D collision detection? (How would it be different with 3D collision detection?)
    3. How can this be implemented in Java using Shape objects?
    Note: I am easily confused by geometric terminology.This really looks like a question you should have an answer for in your notes from class, or in your book. If not perhaps you need to go ask your teacher what it is and explain why you don't have it in your notes or book.

  • How can i  add more than 500 jPanels in a jScrollPane

    Hello to all ,
    I am facing a problem related to adding jPanels in jScrollPane. My application needs more than 500 jpanels in the jscrollpane.where in each jPanel 4 jtextboxes, 1 comboboxes, 1 check box is there.when the check box will be clicked then the total row( ie row means the panel containing the 4 jtextboxes, 1 comboboxes, 1 check box ).and when the user will click on move up or move down button then the selected jpanel will move up or down.
    The tool(sun java studio enterprise 8.1) is not allowing more Jpanels to add manually. so i have to add the jpanels by writing the code in to a loop. and the problem is that when i am trying to add the code in the code generated by the tool the code written out side the code by me is not integratable into the tool generated code.
    If u watch the code here am sending u ll get what am facing the problem. The idea of creating jpanels through loop is ok but when trying to impleent in tool facing difficulties.
    A example code am sending here. please tell me how i can add more panels to the scrollpane(it is the tool generated code)
    Thanks in advance , plz help me for the above
    package looptest;
    public class loopframe extends javax.swing.JFrame {
    /** Creates new form loopframe */
    public loopframe() {
    initComponents();
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jPanel1 = new javax.swing.JPanel();
    jPanel2 = new javax.swing.JPanel();
    jTextField1 = new javax.swing.JTextField();
    jComboBox1 = new javax.swing.JComboBox();
    jPanel3 = new javax.swing.JPanel();
    jTextField2 = new javax.swing.JTextField();
    jComboBox2 = new javax.swing.JComboBox();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTextField1.setText("jTextField1");
    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
    org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
    jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel2Layout.createSequentialGroup()
    .add(28, 28, 28)
    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(54, 54, 54)
    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(35, Short.MAX_VALUE))
    jPanel2Layout.setVerticalGroup(
    jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel2Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addContainerGap(21, Short.MAX_VALUE))
    jTextField2.setText("jTextField2");
    jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
    org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
    jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel3Layout.createSequentialGroup()
    .add(20, 20, 20)
    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 111, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(33, 33, 33)
    .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 168, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(40, Short.MAX_VALUE))
    jPanel3Layout.setVerticalGroup(
    jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel3Layout.createSequentialGroup()
    .add(21, 21, 21)
    .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addContainerGap(21, Short.MAX_VALUE))
    org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addContainerGap(58, Short.MAX_VALUE))
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel1Layout.createSequentialGroup()
    .add(21, 21, 21)
    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(49, 49, 49)
    .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(66, Short.MAX_VALUE))
    jScrollPane1.setViewportView(jPanel1);
    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .add(31, 31, 31)
    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 439, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(74, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .add(30, 30, 30)
    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 254, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(55, Short.MAX_VALUE))
    pack();
    }// </editor-fold>
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new loopframe().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration
    and
    package looptest;
    public class Main {
    public Main() {
    public static void main(String[] args) {
    new loopframe().setVisible(true);
    }

    Thanks for here kind attention to solve my problem.
    I am thinking to create the classes separately for the components (i.e the jpanel, combobox,textbox etc)and call their instaces from the for loop .But the problem is the jpanel will contain the other components and that jpanels (unlimited jpanels will be added later)will be later added to the jscrollpane.
    By writing code, the problem is to place components( the comboboxes,textboxes etc placed on the jpanel ) in appropriate coordinates . So i am doing it through tool .
    I am sending here the sample code related to my actual need . In this i have taken a jScrollPane, on that i have added jPanel1 and on jPanel1 i have added jPanel2.On jPanel2 jTextField1, jComboBox1,jCheckBox are added. If the u ll see the code u can understand what problem i am facing.
    If i am still not clearly explained ,please ask me. plz help me if u can as u have already handled a problem similar to this.
    package addpanels;
    public class Main {
    /** Creates a new instance of Main */
        public Main() {
        public static void main(String[] args) {
            new addpanels().setVisible(true);
    } and
    package addpanels;
    public class addpanels extends javax.swing.JFrame {
        /** Creates new form addpanels */
        public addpanels() {
            initComponents();
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jPanel1 = new javax.swing.JPanel();
            jPanel2 = new javax.swing.JPanel();
            jTextField1 = new javax.swing.JTextField();
            jComboBox1 = new javax.swing.JComboBox();
            jCheckBox1 = new javax.swing.JCheckBox();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTextField1.setText("jTextField1");
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
            jCheckBox1.setText("jCheckBox1");
            jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));
            org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jCheckBox1)
                    .addContainerGap(39, Short.MAX_VALUE))
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addContainerGap(17, Short.MAX_VALUE)
                    .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jCheckBox1))
                    .addContainerGap())
            org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(34, Short.MAX_VALUE))
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(26, 26, 26)
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(152, Short.MAX_VALUE))
            jScrollPane1.setViewportView(jPanel1);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(36, Short.MAX_VALUE)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 449, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(18, 18, 18))
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(32, 32, 32)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 230, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(38, Short.MAX_VALUE))
            pack();
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new addpanels().setVisible(true);
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JCheckBox jCheckBox1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration//GEN-END:variables
    }

  • Unable to insert multiple JPanels  to JScrolPane

    hi, i've got a problem with the following code:
    private void fillComponents(JScrollPane thumbnailPanel, final List<Slide> list) {
            //thumbnailScrollPanel.set
            JSeparator separator = new JSeparator(SwingConstants.HORIZONTAL);
            separator.setSize(thumbnailPanel.getWidth(),8);
            separator.setVisible(true);
            JLabel label = null;
            for(Iterator<Slide> it = list.iterator();it.hasNext();){
                Slide val = it.next();
                //thumbnailPanel.getViewport().add(separator);
                thumbnailPanel.add(separator);
                SlideImageLoader sldim = new SlideImageLoader(val,thumbnailPanel.getWidth()-3, (int)(0.75*thumbnailPanel.getWidth()));
                sldim.addMouseListener(new java.awt.event.MouseListener() {
                    public void mouseClicked(MouseEvent e) {
                        if(e.getButton() == MouseEvent.BUTTON1){
                            int slideNo = ((SlideImageLoader)e.getSource()).getSlideNumber();
                            slidePanel.removeAll();
                            slidePanel.updateUI();
                            slidePanel.add(new SlideImageLoader(list.get(slideNo-1), slidePanel.getWidth(), slidePanel.getHeight()));
                            Navigator.setCurrentSlideNumber(slideNo-1);
                            userEnteredSlideNumber.setText(String.valueOf(slideNo));
                    public void mousePressed(MouseEvent e) {
                        //throw new UnsupportedOperationException("Not supported yet.");
                    public void mouseReleased(MouseEvent e) {
                        //throw new UnsupportedOperationException("Not supported yet.");
                    public void mouseEntered(MouseEvent e) {
                        //throw new UnsupportedOperationException("Not supported yet.");
                    public void mouseExited(MouseEvent e) {
                        //throw new UnsupportedOperationException("Not supported yet.");
                //thumbnailPanel.getViewport().add(sldim);
                thumbnailScrollPanel.add(sldim);
                label = new JLabel(String.valueOf(val.getId()));
                label.setVisible(true);
                label.setSize(thumbnailPanel.getWidth(), getFont().getSize());          
                thumbnailPanel.add(label);
                thumbnailPanel.add(separator);
                //thumbnailPanel.getViewport().add(label);
                //thumbnailPanel.getViewport().add(separator);
                //thumbnailPanel.updateUI();
        }and what i intended to achieve was to put components in the scrollpane one under another in a sequence:
    separator, panel, label, separator, panel, label,....., but components are added one on another and i see only the first one added ;/.
    the panel i'm adding to the scrollpane containts an Image, so it basically is a scrollable thumbnails viewer.
    any help appreciated. i've tried all managers, i even added another panel to the scrollpane but then every component was followed by a blank space equals to it's size and slider didn't show up. thanks in advance. cheers

    the code of the panel class:
    package logic;
    import java.awt.BorderLayout;
    import java.awt.Graphics;
    import java.awt.Image;
    import java.io.File;
    import java.net.MalformedURLException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.ImageIcon;
    import javax.swing.JPanel;
    import schema.xsd.lecturedata.Slide;
    public class SlideImageLoader extends JPanel {
        Slide slide = null;
        //private transient final String  resources = "resources/";
        String path = null;
        //BigInteger id;
        int height;
        int width;
        int scallMethod = Image.SCALE_SMOOTH;
        Image img;
        public SlideImageLoader(Slide slide, int width, int height) {
            this.slide = slide;
            this.path = slide.getPath();
            this.width = width;
            this.height = height;       
            this.setBounds(0, 0, width, height);
            setLayout(new BorderLayout());
            img = getScaledImage();
        private Image getScaledImage(){
            File url = new File(path);
            System.out.println(path);
            System.out.println(url);      
            ImageIcon imaicon = null;
            try {
                imaicon = new ImageIcon(url.toURI().toURL());
            } catch (MalformedURLException ex) {
                Logger.getLogger(SlideImageLoader.class.getName()).log(Level.SEVERE, null, ex);
           return imaicon.getImage().getScaledInstance(width, height, scallMethod);
        @Override
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            int x = 0;
            int y = 0;
            g.drawImage(img, x, y, this);
        public int getSlideNumber(){
            return Integer.valueOf(slide.getId().toString());
    }

  • Adding mouselisteners to JPanels created through for loop

    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.io.File;
    import java.io.IOException;
    import java.util.Vector;
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JViewport;
    import javax.swing.SwingConstants;
    import javax.swing.filechooser.FileSystemView;
    public class ScrollableWrapTest {
        public static void main(String[] args) {
            try {
                  ScrollableWrapTest st = new ScrollableWrapTest();
                final JPanel mainPanel = new JPanel(new WrapScollableLayout(FlowLayout.LEFT, 10, 10));
                mainPanel.setBackground(Color.WHITE);
                JScrollPane pane = new JScrollPane(mainPanel);
                pane.setPreferredSize(new Dimension(550, 300));
                Vector v = new Vector();
                v.add("first.doc");
                v.add("second.txt");
                v.add("third.pdf");
                v.add("fourth.rar");
                v.add("fifth.zip");
                v.add("sixth.folder");
                v.add("seventh.exe");
                v.add("eighth.bmp");
                v.add("nineth.jpeg");
                v.add("tenth.wav");
                JButton button = null;
                for(int i =0;i<v.size();i++){
                    JPanel panel = new JPanel(new BorderLayout());
                    Icon icon = st.getIcone(st.getExtension(v.elementAt(i).toString().toUpperCase()));
                      panel.setBackground(Color.WHITE);
                     Action action = new AbstractAction("", icon) {
                         public void actionPerformed(ActionEvent evt) {
                     button = new JButton(action);
                     button.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
                     JPanel buttonPanel = new JPanel();
                     buttonPanel.setBackground(Color.WHITE);
                     buttonPanel.add(button);
                     JLabel label = new JLabel((String)v.elementAt(i));
                     label.setHorizontalAlignment(SwingConstants.CENTER);
                     panel.add(buttonPanel , BorderLayout.NORTH);
                     panel.add(label, BorderLayout.SOUTH);
                     mainPanel.add(panel);
                    mainPanel.revalidate();
                st.buildGUI(pane);
            } catch (Exception e) {e.printStackTrace();}
        public void buildGUI(JScrollPane scrollPane)
             JFrame frame = new JFrame("Scrollable Wrap Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(scrollPane, BorderLayout.CENTER);
            frame.setLocationRelativeTo(null);
            frame.pack();
            frame.setVisible(true);
        public String getExtension(String name)
              if(name.lastIndexOf(".")!=-1)
                   String extensionPossible = name.substring(name.lastIndexOf(".")+1, name.length());
                   if(extensionPossible.length()>5)
                        return "";
                   else
                        return extensionPossible;
              else return "";
         public Icon getIcone(String extension)
              //we create a temporary file on the local file system with the specified extension
              File file;
              String cheminIcone = "";
              if(((System.getProperties().get("os.name").toString()).startsWith("Mac")))
                   cheminIcone = System.getProperties().getProperty("file.separator");
              else if(((System.getProperties().get("os.name").toString()).startsWith("Linux")))
                   //cheminIcone = FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath()+
                   cheminIcone = "/"+"tmp"+"/BoooDrive-"+System.getProperty("user.name")+"/";
              else cheminIcone = System.getenv("TEMP") + System.getProperties().getProperty("file.separator");
              File repIcone = new File(cheminIcone);
              if(!repIcone.exists()) repIcone.mkdirs();
              try
                   if(extension.equals("FOLDER"))
                        file = new File(cheminIcone + "icon");
                        file.mkdir();
                   else
                        file = new File(cheminIcone + "icon." + extension.toLowerCase());
                        file.createNewFile();
                   //then we get the SystemIcon for this temporary File
                   Icon icone = FileSystemView.getFileSystemView().getSystemIcon(file);
                   //then we delete the temporary file
                   file.delete();
                   return icone;
              catch (IOException e){ }
              return null;
        private static class WrapScollableLayout extends FlowLayout {
            public WrapScollableLayout(int align, int hgap, int vgap) {
                super(align, hgap, vgap);
            public Dimension preferredLayoutSize(Container target) {
                synchronized (target.getTreeLock()) {
                    Dimension dim = super.preferredLayoutSize(target);
                    layoutContainer(target);
                    int nmembers = target.getComponentCount();
                    for (int i = 0 ; i < nmembers ; i++) {
                        Component m = target.getComponent(i);
                        if (m.isVisible()) {
                            Dimension d = m.getPreferredSize();
                            dim.height = Math.max(dim.height, d.height + m.getY());
                    if (target.getParent() instanceof JViewport)
                        dim.width = ((JViewport) target.getParent()).getExtentSize().width;
                    Insets insets = target.getInsets();
                    dim.height += insets.top + insets.bottom + getVgap();
                    return dim;
    }How can I add mouse listener to each of the 'panel' in 'mainpanel' created inside the 'for loop' using the code mainPanel.add(panel);Rony

    >
    How can I add mouse listener to each of the 'panel' in 'mainpanel' created inside the 'for loop' using the code mainPanel.add(panel);
    Change the first part of the code like this..
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.FlowLayout;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.io.File;
    import java.io.IOException;
    import java.util.Vector;
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.Icon;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JViewport;
    import javax.swing.SwingConstants;
    import javax.swing.filechooser.FileSystemView;
    public class ScrollableWrapTest {
        public static void main(String[] args) {
            try {
                  ScrollableWrapTest st = new ScrollableWrapTest();
                final JPanel mainPanel = new JPanel(new WrapScollableLayout(FlowLayout.LEFT, 10, 10));
                mainPanel.setBackground(Color.WHITE);
                JScrollPane pane = new JScrollPane(mainPanel);
                pane.setPreferredSize(new Dimension(550, 300));
                Vector<String> v = new Vector<String>();
                v.add("first.doc");
                v.add("second.txt");
                v.add("third.pdf");
                v.add("fourth.rar");
                v.add("fifth.zip");
                v.add("sixth.folder");
                v.add("seventh.exe");
                v.add("eighth.bmp");
                v.add("nineth.jpeg");
                v.add("tenth.wav");
                JButton button = null;
                MouseListener ml = new MouseAdapter() {
                        @Override
                        public void mouseClicked(MouseEvent me) {
                             System.out.println(me);
                for(int i =0;i<v.size();i++){
                    JPanel panel = new JPanel(new BorderLayout());
                    Icon icon = st.getIcone(st.getExtension(v.elementAt(i).toString().toUpperCase()));
                      panel.setBackground(Color.WHITE);
                     Action action = new AbstractAction("", icon) {
                         public void actionPerformed(ActionEvent evt) {
                     button = new JButton(action);
                     button.setPreferredSize(new Dimension(icon.getIconWidth(), icon.getIconHeight()));
                     JPanel buttonPanel = new JPanel();
                     buttonPanel.setBackground(Color.WHITE);
                     buttonPanel.add(button);
                     JLabel label = new JLabel((String)v.elementAt(i));
                     label.setHorizontalAlignment(SwingConstants.CENTER);
                     panel.add(buttonPanel , BorderLayout.NORTH);
                     panel.add(label, BorderLayout.SOUTH);
                     mainPanel.add(panel);
                     panel.addMouseListener( ml );
                    mainPanel.revalidate();
                st.buildGUI(pane);
            } catch (Exception e) {e.printStackTrace();}
    ...

  • JPanel methods arn't being overriden in my subclass.

    Basically I have a JPanel class which I want to use as a template (super class) for other GUI Items. These other GUI items extend off this class, but also have the ability of altering the appiernece of the panel by overiding some functions. As far as I can tell, they arn't overiding.
    Here's an example of what I'm trying to do.
    package lastGUI;
    import javax.swing.JPanel;
    import javax.swing.JSeparator;
    import com.jgoodies.forms.builder.PanelBuilder;
    import com.jgoodies.forms.layout.CellConstraints;
    import com.jgoodies.forms.layout.FormLayout;
    * A template Panel
    * @author Yves Samuel Wheeler
    public class Template extends JPanel {
         private static final long serialVersionUID = 1L;
         private JSeparator Separator;
         public Template() {
              super();
              initGUI();
         private void initGUI() {
              instantiateComponents();
              add(buildMainPanel());
         private void instantiateComponents() {
              Separator = new JSeparator(JSeparator.VERTICAL);
         private JPanel buildMainPanel() {
              FormLayout formLayout = new FormLayout(
                        "pref:grow, 15dlu, pref, 15dlu, pref:grow", // columns
                        "15dlu, pref:grow, 15dlu"); // rows
              PanelBuilder panelBuilder = new PanelBuilder(formLayout);
              CellConstraints cellConstraints = new CellConstraints();
              panelBuilder.add(buildLeftPanel(), new CellConstraints(
                        "1, 1, 1, 1, fill, fill"));
              panelBuilder.add(Separator, cellConstraints.xywh(3, 1, 1, 3));
              panelBuilder.add(buildRightPanel(), new CellConstraints(
                        "5, 1, 1, 1, fill, fill"));
              return panelBuilder.getPanel();
         protected JPanel buildRightPanel() {
              FormLayout formLayout = new FormLayout("pref", // columns
                        "pref"); // rows
              PanelBuilder panelBuilder = new PanelBuilder(formLayout);
              CellConstraints cellConstraints = new CellConstraints();
              panelBuilder.addLabel("Right", cellConstraints.xy(1, 1));
              return panelBuilder.getPanel();
         protected JPanel buildLeftPanel() {
              FormLayout formLayout = new FormLayout("pref", // columns
                        "pref"); // rows
              PanelBuilder panelBuilder = new PanelBuilder(formLayout);
              CellConstraints cellConstraints = new CellConstraints();
              panelBuilder.addLabel("Left", cellConstraints.xy(1, 1));
              return panelBuilder.getPanel();
    package lastGUI;
    import javax.swing.JPanel;
    import com.jgoodies.forms.builder.PanelBuilder;
    import com.jgoodies.forms.layout.CellConstraints;
    import com.jgoodies.forms.layout.FormLayout;
    public class MyPanel extends Template {
         public MyPanel() {
              super();
              // TODO Auto-generated constructor stub
         protected JPanel buildRightPanel() {
              FormLayout formLayout = new FormLayout("pref", // columns
                        "pref"); // rows
              PanelBuilder panelBuilder = new PanelBuilder(formLayout);
              CellConstraints cellConstraints = new CellConstraints();
              panelBuilder.addLabel("This Panel has also been overiden!",
                        cellConstraints.xy(1, 1));
              return panelBuilder.getPanel();
         protected JPanel buildLeftPanel() {
              FormLayout formLayout = new FormLayout("pref", // columns
                        "pref"); // rows
              PanelBuilder panelBuilder = new PanelBuilder(formLayout);
              CellConstraints cellConstraints = new CellConstraints();
              panelBuilder.addLabel("This Panel has been overiden!", cellConstraints
                        .xy(1, 1));
              return panelBuilder.getPanel();
    }Any help would be apprieciated.
    Thanks :)

    The MyPanel methods are overriding the parent methods alright.
    If you try:
    public static void main(String[] args)
         JFrame frame = new JFrame();
         frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         frame.add(new MyPanel());
         frame.pack();
         frame.setVisible(true);
    }the overriden panels shows up.
    Can you post the snippet where you call the MyPanel class?

  • Jpanel to jpanel

    hi,
    i need help in some swing components:
    i have two jpanels one holds a chart: and the other jpanel hold some comboboxes and checkboxes which basically change the chart accordingly:
    now i dont know how to relay these changes to the chartpanel...
    i am trying with a chart manager that knows both the jpanels and their components:
    but i cant seem to listen to any events i dont know how to implemet the logic:
    my logic is that the manager class will register and listen to each the component in the Jpanels and when they are changed , the manager will change it in the chart as well.. but i dont know how to do this..
    how do i add a listener to a component in another class
    lthis is not actual code
    class jpanel1 extends Jpanel{
    Jcombobox box = new jcombobox;
    checkbox check = new checkbox;
    /*and it has functaionalities like a boolean which states the check.isselected(); */
    class japnel2 extends jpanel{ Chart chart= new Chart(somechart); }
    class jpanelmanager
    /* constructor */
    void jpanelmanger()
    { jpanel1 controlspanel  =new Japenl1();
    jpanel2 chartpanel = new Jpanel2();
    now i have instantiated them and but how do i listen to the chnages in jpanel 1
    i would really appreciate if somebody can give me any clues to what method i can take to accomplish this.;

    Hi,
    maybe I got mixed up in all these JPanels.
    Finally did you manage to get it work or not ?
    If not, tell me the problems you have and we'll solve
    them.
    Regards,No i have not yet :(
    ok let me give you the code and tell you basically what is needed or what i am trying to accomplish here...
    /***** CLASS #1 *****/
    /* This class creates a Chart and puts it on a Panel , Think of this as a simple Jpanel with an image */
    public class SimpleJChart extends JPanel {
    /**JFCChart is an API we are using*/
    public JFCChart chart;
    public SimpleJChart(int type, JTable jTable) {
    enableEvents(AWTEvent.WINDOW_EVENT_MASK);
         this.setLayout(new BorderLayout());
         chart = new com.infragistics.ultrachart.JFCChart();
         chart.getColorAppearance().setAntialias(false);
         this.add("Center", chart);
         chart.getData().setDataSource(jTable);
         chart.setChartType(type);
    /*****CLASS #2******************/
    /*this class will have options like checkboxes to invert or to do differnet things with the JFCChart*/
    public class JChartOptions extends JPanel
    implements ActionListener {
    JComboBox style = new JComboBox();
    JCheckBox colorByRow = new JCheckBox("ColorByRow");
    public boolean colorRow = false; // to see if the ceck box was checked
    JCheckBox swapRow = new JCheckBox("Swap Rows-Columns");
    public boolean rowSwapped = false;// to see if the checkbox was checked
    boolean onlyPositive = false;
    public int chartType = 0;
    * JChartOptions Constructor
    public JChartOptions() {
    /*IN THIS CONSTRUCTOR I WILL DICTATE WHICH CONTROLS TO PLACE ON THE OPTIONSPANEL*/
    public JChartOptions(JComboBox style, JCheckBox swapRow, JCheckBox colorByRow,
                   JComboBox rows, JComboBox minMax, JSlider xSlider) {
         enableEvents(AWTEvent.WINDOW_EVENT_MASK);
         this.setBackground(Color.pink);
         this.setLayout(new BorderLayout());
         this.setPreferredSize(new Dimension(30, 82));
         int iTop = 4, iLeft = 5;
         *style is a  combobox stating types of charts taht could be displayed in the chart panel.
         if (style != null) {
         style.addItem("Column");
         style.addItem("Bar");
         style.addItem("Area");
         style.addItem("Line");
         style.addItem("Pie");
         style.addActionListener(this);
         this.add(style);
         style.setBounds(iLeft, iTop, 130, 22);
         * a feature where the columns become rows and vice versa
         if (swapRow != null) {
         swapRow.addActionListener(this);
         swapRow.setFont(f);
         this.add(swapRow);
         swapRow.setBounds(iLeft, iTop += 26, 160, 18);
         if (colorByRow != null) {
         colorByRow.addActionListener(this);
         colorByRow.setFont(f);
         this.add(colorByRow);
         colorByRow.setBounds(iLeft, iTop += 26, 160, 18);
    public void actionPerformed(ActionEvent e) {
         Object src = e.getSource();
         if (src == style) {
         fixChart();
    /* this method was changing the chart when the chart was in the same class and chart.setcharttype() was visible,.. now this panel has no idea that there is a chart thats going to be affected by the combobox changes*/
    /*at this point the manager should change the chart
         if (src == swapRow) {
         rowSwapped = swapRow.isSelected();
    // chart.getData().setSwapRowsAndColumns(swapRow.isSelected());
    /* previously chart wa a part of this japnel or class so chart was an element of this module or class now its not so the only thing that comes to my mind is set a boolean to true or false if the checkbox is checked or not .*/
         if (src == colorByRow) {
         colorRow = colorByRow.isSelected();
    //     chart.getColorAppearance().setColorByRow(colorByRow.isSelected());
    private void fixChart() {
    /*this code uses the API to change the chart */
         int i = style.getSelectedIndex();
         if (i >= com.infragistics.ultrachart.shared.styles.ChartType.CANDLE_CHART) {
         i++;
         onlyPositive = i >= com.infragistics.ultrachart.shared.styles.ChartType.STACK_BAR_CHART;
         chartType = i;
    //     chart.setChartType(chartType); this is what is supposed to be done at this point to the chart.
    /*****************CLASS#3************/
    /*THIS IS THE MANAGER CLASS*/
    public class JChartManager
    implements ActionListener {
    JTable jTable;
    JChartOptions jOptionsPanel;
    SimpleJChart chartpanel;
    public JChartManager() {
    /* an application will instantiate simplechart like this*/
         SimpleJChart chartpanel = new SimpleJChart(ChartType.AREA_CHART_3D, jTable);
    /* an appliction will also add the Jchartoptionspanel*/
         JChartOptions jOptionsPanel = new JChartOptions(null, null, null, null, null, null);
    // no options: no need to write thios constructor is all of them are null
         if (chartpanel.chart.getChartType() > 14 /*jOptionsPanel.chartType <14*/) {
         jOptionsPanel.view3D = chartpanel.chart.getTransform3D();
         if (jOptionsPanel.colorRow) {
         /*if color by row is selected.*/
         if (jOptionsPanel.rowSwapped) {
         /*if swaprowbycolumns is selected*/
         int i = jOptionsPanel.countComponents();
         Component comp = jOptionsPanel.getComponent( i-2 );
    * actionPerformed
    * @param e ActionEvent
    public void actionPerformed(ActionEvent e) {
         if (jOptionsPanel.colorRow) {
         /*if color by row is selected.*/
         chartpanel.chart.getColorAppearance().setColorByRow(jOptionsPanel.colorRow);
         if (jOptionsPanel.rowSwapped) {
         /*if swaprowbycolumns is selected*/
         chartpanel.chart.getData().setSwapRowsAndColumns(jOptionsPanel.rowSwapped);
    why i have taken this stupid approach is because we are implementing MVC architecture and so the view is separated with the control and these two are managed with the Manager class...
    so iif we want to have only the first class we will instantiate the first class and nothing will be done in the options and if we want to add options we can specify which options we need to add.
    so any application that has a JFrame can add SimpleChart to it and also add JChartOptions to it
    and when the options in the JChartoptions are moved , changed or selected : the manager will delegate those changes to the SimpleChart . as both of the Jpanels are
    so that application also has to add the manager somewhere (i dont knwo how is this going to work though yet) and ask the manager to listen to the JChartOptions that it has added.

  • TreeSelectionListener with JPanel is not reacting

    Hi all!
    I have class which extends JPanel, and is later docked in a side menu. The effect should be like the Tools menu in VisualStudio.
    Inside the JPanel I have a JTree. And the TreeSelectionListener isn't working. I tried the JTree code in a plain project and it works. So I figure it's something to do with the JPanel.
    Here my code with the JTree
    package de.lmu.ifi.pst.swep.rid.gui;
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.io.File;
    import java.io.IOException;
    import java.util.ArrayList;
    import java.util.Enumeration;
    import java.util.Map;
    import java.util.TreeMap;
    import javax.swing.*;
    import javax.swing.tree.*;
    import javax.swing.event.*;
    import com.vlsolutions.swing.docking.DockKey;
    import com.vlsolutions.swing.docking.Dockable;
    import de.lmu.ifi.pst.swep.rid.cartridgeInterface.AbstractCartridgeElement;
    import de.lmu.ifi.pst.swep.rid.cartridgeInterface.AbstractModelElement;
    import de.lmu.ifi.pst.swep.rid.cartridgeInterface.ICartridge;
    import de.lmu.ifi.pst.swep.rid.cartridgeloader.CartridgeLoader;
    import de.lmu.ifi.pst.swep.rid.cartridgeloader.ComponentLoader;
    import de.lmu.ifi.pst.swep.rid.interfaces.ICartridgeBay;
    import de.lmu.ifi.pst.swep.rid.utils.IconProvider;
    import de.lmu.ifi.pst.swep.rid.utils.Settings;
    import de.lmu.ifi.pst.swep.rid.utils.IconProvider.Identifier;
    * The toolbar for selecting canvas tools, such as select and new Cartridge
    * Element creation.
    public class CartridgeToolbar extends JPanel implements Dockable, ICartridgeBay {
         static {
              Settings.register("cartridge.selection.none", false);
              Settings.register("cartridge.selection.default", true);
              Settings.register("cartridge.selection.user", false);
              Settings.register("cartridge.selection.xul", true);
              Settings.register("cartridge.selection.uml", true);
         private static final long serialVersionUID = 8926943523499013449L;
         private DockKey dockKey = new DockKey("cartridgeToolbar", "Tools", null, IconProvider
                   .getSmallImage(Identifier.VIEW_TOOLS));
         private Map<String, ArrayList<AbstractCartridgeElement>> cartridgeGroups = new TreeMap<String, ArrayList<AbstractCartridgeElement>>();
         private JTree cartridgeTree;
         public CartridgeToolbar(ComponentLoader componentLoader) {
              super();
              dockKey.setFloatEnabled(true);
              dockKey.setMaximizeEnabled(false);
              dockKey.setResizeWeight(0.1f);          
              this.setLayout(new BorderLayout());          
              setPreferredSize(new Dimension(200, 600));
              cartridgeTree = new JTree(new DefaultMutableTreeNode("Unpainted tree"));
              DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
                 renderer.setOpenIcon(null);
                 renderer.setClosedIcon(null);
                 renderer.setLeafIcon(null);
                 cartridgeTree.setCellRenderer(renderer);
              cartridgeTree.putClientProperty("JTree.lineStyle", "None");
              DefaultTreeSelectionModel selectionModel = new DefaultTreeSelectionModel();
                 selectionModel.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
              cartridgeTree.setSelectionModel(selectionModel);
              fillTreeWith("cartridgexul.xml");
              fillTreeWith("cartridgeuml.xml");
              cartridgeTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {//FIXME: listener not working
                   @Override
                   public synchronized void valueChanged(TreeSelectionEvent e) {
                      DefaultMutableTreeNode node = (DefaultMutableTreeNode) e.getPath().getLastPathComponent();
                      System.out.println("You selected " + node);
              cartridgeTree.putClientProperty("JTree.lineStyle", "None");
              cartridgeTree.setSelectionModel(null);
              JScrollPane scrollPane = new JScrollPane(cartridgeTree);
              this.add(scrollPane, BorderLayout.CENTER);
          * Method returns the name of the currently selected Cartridge Element that is to be drawn on the canvas
          * @return
          *           Name of the selected cartridge element.
         public String getSelectedElement()
            //TODO: if inner node
              return cartridgeTree.getLastSelectedPathComponent().toString();          
         private void fillTreeWith(String cartrigdeFileName)
              File dir = new File(".");
              String rootPath;
              try {
                   rootPath = dir.getCanonicalPath() + File.separator + "resources";
                   addCartridge(rootPath, cartrigdeFileName);
              } catch (IOException e) {
                   e.printStackTrace();
         public void addCartridge(String rootPath, String cartrigdeFileName) {
              CartridgeLoader catridgeLoader = new CartridgeLoader(rootPath, cartrigdeFileName);
              ICartridge cartridgeInterface = catridgeLoader.loadCartridge();
              final String nameCartridge = cartridgeInterface.getCartridgeName();
              ArrayList<AbstractCartridgeElement> catridgeGroupElements = generateFactories(cartridgeInterface);
              DefaultMutableTreeNode root = (DefaultMutableTreeNode) cartridgeTree.getModel().getRoot();
              DefaultMutableTreeNode cartridgeGroupNode= new DefaultMutableTreeNode(nameCartridge);
              DefaultMutableTreeNode elementNode ;
              DefaultMutableTreeNode subElementNode;
              for (AbstractCartridgeElement element : catridgeGroupElements) {
                   elementNode = new DefaultMutableTreeNode(element.getElementName());//TODO: add icon
                   subElementNode = new DefaultMutableTreeNode(element.getElementName() + "1");
                   elementNode.add(subElementNode);
                   subElementNode = new DefaultMutableTreeNode(element.getElementName() + "2");
                   elementNode.add(subElementNode);
                      cartridgeGroupNode.add(elementNode);//TODO: add subType          
              root.add(cartridgeGroupNode);
              cartridgeGroups.put(cartridgeInterface.getCartridgeName(), catridgeGroupElements);
          * With getting a new cartridge interface the method will be able to create
          * all factories of the cartridge interface. Element factories are used to
          * add new elements to the canvas.
          * @return List of factories belonging to a cartridge interface
         private ArrayList<AbstractCartridgeElement> generateFactories(ICartridge cartridgeInterface) {
              ArrayList<AbstractCartridgeElement> cartridgeGroupElements = new ArrayList<AbstractCartridgeElement>();
              for (Enumeration<Integer> el = cartridgeInterface.getElementIDs(); el.hasMoreElements();) {
                   cartridgeGroupElements.add(cartridgeInterface.getElementFactoryByID((Integer) el.nextElement()));
              return cartridgeGroupElements;
         @Override
         public DockKey getDockKey() {
              return dockKey;
         @Override
         public AbstractModelElement createCartridgeElement(String id) {
              // getElementFactoryByID
              return null;
         @Override
         public Component getComponent() {
              // TODO Auto-generated method stub
              return null;
         @Override
         public JComponent getComponent(String path, String cartridgeName) {
              // TODO Auto-generated method stub
              return null;
         @Override
         public void setButtonGroup(ButtonGroup buttongroup) {
              // TODO Auto-generated method stub
    }The most important is ofcourse the constructor. Any suggestions and help would be greatly apprieciated.
    best of all,
    Szymon

    cartridgeTree.setSelectionModel(null);You creating a new selection model, add it to the tree and add a listener to it. Then you throw it away.

  • Is it legal to add a graph to a JPanel?

    Hi, I am working on a gui for one of my classes that needs to display a graph that shows the number of failed and passed questions on a test. My bar graph works perfectly when I test it separately, but when I try to implement it in the rest of my GUI, I get the following error:
    Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a container
    Here is the relevant code with this issue:
    import javax.swing.JFrame;
    public class TestStudentStatistics {
         public static void main(String[] args) {
              studentStatistics f = new studentStatistics();
              f.setTitle("Student History");
             f.setSize(1000,1000);
             f.setVisible(true);
             f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    public studentStatistics ()
              //adding the JPanels declared earlier in the code to a new container.
              Container c = this.getContentPane();
              c.add(jp1);
              c.add(jp2);
              c.add(jp3);
              c.add(jp4);
              c.add(jp5);
              /*creating an instance of the graph for the student's last three tests
               * This is currently designed for the prototype. These bars will be used in the
               * final product to show percentage failed overall per test and also per subject
               * area.
              bars graph = new bars(12,23,23,34,34,45);
              //adding the JList to the second JPanel
              jp2.add(jl1);
              //adding the graph to the third JPanel
              jp3.add(graph);
              //adding the Exit JButton declared earlier to the fourth JPanel
              jp4.add(jbtExit);
    import java.awt.*;
    import javax.swing.*;
    public class bars extends JFrame
         private int true1, true2, true3, false1, false2, false3;
         public bars (double b1, double t1, double b2, double t2, double b3, double t3)
              true1 = (int)(b1/t1 * 300);
              false1 = 300-true1;
         public void paint(Graphics g2)
              double pass1;
              double fail1;
              fail1 = (double)false1/300*100;
              fail1 = Math.round(fail1);
              pass1 = (double)true1/300*100;
              pass1 = Math.round(pass1);
              //Drawing the first bar graph
              g2.setColor(Color.GREEN);
              g2.fillRect(10, 100, true1, 40);
              g2.setColor(Color.RED);
              g2.fillRect(true1+10, 100, false1, 40);
              g2.setColor(Color.BLACK);
              //true1 + false 1 is assumed to equal 300.
              g2.drawRect(10, 100, true1 + false1, 40);
              //Drawing the legend of the incorrect percentage to the right of the graph
              g2.setColor(Color.red);
             g2.fillRect(315,104,40,12);
             g2.drawString("Incorrect % = " + fail1,360,116);
             //Drawing the legend of the correct percentage to the right of the graph
             g2.setColor(Color.green);
             g2.fillRect(315,124,40,12);
             g2.drawString("Correct % = " + pass1,360,136);
             //Title of the first graph
             g2.setColor(Color.WHITE);
             g2.drawString(" TEST ONE ", 155, 120);
    }do I have to add my graph in some other manner or is it impossible? I'm not quite sure what else I could do to implement my graph and let it still be within my gui.

    jbjohnson86 wrote:
    Exception in thread "main" java.lang.IllegalArgumentException: adding a window to a containerYou can't add window(JFrame) into a container(JPanel) but a JPanel can have nested panel extend your bar into a JPanel and add that panel to a JFrame. It should be container to a window not window to a container.
    In the future Swing related question should be posted in the Swing forum.
    http://forum.java.sun.com/forum.jspa?forumID=57

  • Serializing a JPanel

    Hi,
    I am trying to serialize a JPanel and then open it again. My JPanel (called rightPanel) contains a JButton, which has some text set to "xyz". Would I have to serialize the JPanel and JButton separately? Or if I serialize the JPanel, would that take care of the JButton too?
    At the moment my code is like this:
    JFileChooser myFileChooser = new JFileChooser ();
    myFileChooser.showSaveDialog(MyFrame.this);
    File myFile = myFileChooser.getSelectedFile();
    try{
    FileOutputStream out = new FileOutputStream(myFile);
    ObjectOutputStream s = new ObjectOutputStream(out);
    s.writeObject(rightPanel);
    s.flush
    } catch (IOException e) {};
    When I execute my Save, a file is saved onto my system. I do not know if the saved file contains my rightPanel.
    When I try to open up the file (by doing a readObject), nothing happens. What am I doing wrong?
    Any help would be much appreciated.
    Thanks.
    AU

    You make some very good points there. I do totally agree with you that serializing Swing components is discouraged.
    But you see the reason I am trying to serialize my JPanel is because of this. Say the components on my JPanel will be determined on-the-fly by clicking on buttons on my JToolbar. So that means on one occasion a user might add to my JPanel a JButton, followed by 20 JLabels, all of different sizes. On the next occasion my JPanel might contain a 100 JButtons, a few jpeg images, and a textbox. Are you suggesting I should use something like a Vector to store everything that is added to my JPanel, and that everytime I add an item to it, I also add it to the Vector...and then when I want to Save my JPanel, I traverse through my Vector, serializing the attributes of every object in my Vector.
    That makes more code for me!!!
    AU

  • How to add JPanel,JFrame to JSP Page so that it does'nt popup

    i have added a JPanel jp1
    which is as follows
    <%JPanel jp1 = new JPanel();%>
    i am getting a error in the page in webbrowser
    javax.swing.JPanel[,0,0,0x0,invalid,layout=java.awt.FlowLayout,alignmentX=null,alignmentY=null,border=,flags=9,maximumSize=,minimumSize=,preferredSize=]
    also i have added a frame as follows
    <%adminlog adllogz = new adminlog();%>
    <%adllogz.setVisible(true);%>
    so these two lines of code make a poop up window of adminlog
    from a webbrowser
    what i want is that these two lines of code should not do
    a pop up but come inside a webbrowserPlease tell asap

    The problem is that you used position:absolute, my post talked about using position:fixed.
    Also your image does not need to be inside the adBox, just use adImage by itself with this CSS:
    #adImage{
    background-color: #FF0000;
    position:fixed;
    bottom:0px;
    right:0px;
    width:100px;
    height: 100px;
    will fix adImage to bottom right 0 px from the edge of window. If you want a little separation, just change
    bottom:0px;
    right:0px;
    to 5 or 10 px or so.
    No jQuery needed.
    Best wishes,
    Adninjastrator

  • PLS help with stupid JPanel and JTable :-(

    Hi all im crying now :-(
    Ive just recreated a panel for use with SWING. Now I want the table to be displayed but it just is not there.
    Nothing i seem to do makes it appear and im really confused????? Just add this to a simple JFrame and you will see what I mean
    it should look like this
    TITLE
    lbl1 txt1 lbl2 txt2
    lbl3 txt3 lbl4 txt 4
    button
    Table
    however the table is not there :-(
    Author: Justin Thomas
    Date  : 14 Jan 2002
    Notes : A simple login display
    import java.awt.*;
    import java.awt.event.*;
    import java.text.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Options extends JPanel implements ActionListener
        private IDNTester parent;
        private TextArea Results = new TextArea(18,80);
        private JButton Start = new JButton("Start Test");
        private JLabel error = new JLabel ("");
        private JTextField txtConns = new JTextField("1",4);
        private JTextField txtClients = new JTextField("10",4);
        private JTextField txtServer = new JTextField("Nutcracker",10);
        private JTextField txtPort = new JTextField("8101",5);
        public String Server;
        public int Port;
        public int Connections;
        public int Clients;
        private String newline;
        public Options(IDNTester ref)
            parent = ref;
            newline = System.getProperty("line.separator");
            JLabel lblMain = new JLabel ("WebIDN Performance Tester");
            JLabel  lblServer = new JLabel ("Server:");
            JLabel  lblPort = new JLabel ("Port:");
            JLabel  lblConns = new JLabel ("Connections:");
            JLabel  lblClients = new JLabel ("Clients:");
            GridBagLayout gridBag = new GridBagLayout();
            GridBagConstraints constraints = new GridBagConstraints();
            setLayout(gridBag);
            constraints.anchor = GridBagConstraints.CENTER;
            constraints.gridwidth = 4;
            constraints.gridx = 0;
            gridBag.setConstraints(lblMain, constraints);
            add(lblMain);
            constraints.insets = new Insets(10,0,0,0);  //top padding
            constraints.gridy = 1;
            gridBag.setConstraints(error, constraints);
            error.setForeground(Color.red);
            add(error);
            constraints.anchor = GridBagConstraints.WEST;
            constraints.gridwidth = 1;
            constraints.gridx = 0;
            //********************************Server and COnnections***************
            constraints.fill = GridBagConstraints.BOTH;
            constraints.gridy = 2;
            gridBag.setConstraints(lblServer, constraints);
            add(lblServer);
            constraints.gridx = 1;
            gridBag.setConstraints(txtServer, constraints);
            add(txtServer);
            // Add some space between fields
            constraints.gridx = 2;
            gridBag.setConstraints(lblConns, constraints);
            add(lblConns);
            constraints.gridx = 3;
            gridBag.setConstraints(txtConns, constraints);
            add(txtConns);
            //********************************** Port and clients******************
            constraints.gridy = 3;
            constraints.insets = new Insets(5,0,0,0);
            constraints.gridx = 0;
            gridBag.setConstraints(lblPort, constraints);
            add(lblPort);
            constraints.gridx = 1;
            gridBag.setConstraints(txtPort, constraints);
            add(txtPort);
            constraints.gridx = 2;
            gridBag.setConstraints(lblClients, constraints);
            add(lblClients);
            constraints.gridx = 3;
            gridBag.setConstraints(txtClients, constraints);
            add(txtClients);
            //********************************** Buttons***************************
            constraints.anchor = GridBagConstraints.CENTER;
            constraints.gridy = 4;
            constraints.insets = new Insets(10,0,0,0);  //top padding
            constraints.gridwidth = 4;   //4 columns wide
            constraints.gridx = 0;
            gridBag.setConstraints(Start, constraints);
            add(Start);
            // Results area
            constraints.gridx = 0;
            constraints.gridy = 5;
            constraints.gridwidth = 5;   //Colum width
            //gridBag.setConstraints(Results, constraints);
            //add(Results);
            // JTable
            DefaultTableModel defaultTab = new DefaultTableModel();
            JTable jtable = new JTable(defaultTab);
            defaultTab.addColumn("ThreadID");
            defaultTab.addColumn("ClientID");
            defaultTab.addColumn("RIC");
            defaultTab.addColumn("TimeTaken");
            defaultTab.addColumn("RCount");
            defaultTab.addColumn("Bytes");
            //add scrollpane to our table
            gridBag.setConstraints(jtable, constraints);
            add(new JScrollPane(jtable));
            // Add listeners
            txtConns.addActionListener(this);
            txtClients.addActionListener(this);
            txtServer.addActionListener(this);
            txtPort.addActionListener(this);
            Start.addActionListener(this);
        public void actionPerformed(ActionEvent event)
            // Validate fields and if correct then start
            boolean valid = true;
            Server = txtServer.getText();
            try {
                Port= Integer.parseInt(txtPort.getText());
                Connections = Integer.parseInt(txtConns.getText());
                Clients = Integer.parseInt(txtClients.getText());
            catch(NumberFormatException nfe) {
                valid = false;
            if (valid && Server.length() > 0)
                error.setText("");
                parent.connect();
            else
                error.setText("Port/Client/Connections must be numerical");
                validate();
        // Add a new line to the test
        public void addLine(String text)
            Results.append(text + newline);
    }

    Hi,
    It looks like you haven't closed the comments. Is anything added after error.
    Anyway try setting the fill constrains on your table to BOTH. The table you have created in empty so it may have trouble determining it's size.
    regards,
    Terry

  • JPanel GUI question

    I am writing a program that updates a Jpanel on the gui when a button is clicked ( GUI or editGUI).
    The program currently loadsup to the GUI and switches to editGUI no problem at all, but won't switch back
    I think I've tracked down the problem to this section of code, what am I doing wrong??? (booleans checked not the problem)
    private void layoutCentre()
              if (editgui == false)
              remove(this.textcentre);
              String s = createDisplay();
              JtextArea.setText(s);     
              Jpanel.add(JTextArea);
              add(JPanel, BorderLayout.CENTER);
              Jpanel.revalidate();
              this.repaint();
              else
                   remove(this.textcentre);
                   JPanel=new EditGUI();
                   JPanel = egui.layoutEdit();
                   add(JPanel, BorderLayout.CENTER);
                   Jpanel.revalidate();
                   this.repaint();
         }

    airomega wrote:
    Thanks everyone, I'm a noob to the forums and to Java so sorry for lack of forum etiquette. No big deal. Your etiquette was fine.
    I sorted it by separating panel creation into two classes, and checking the boolean when calling the methods instead. Still that makes two of us now who have recommended that you look into CardLayout. If you haven't done so, I suggest you do this now.

Maybe you are looking for

  • My ipod is not recognized on my computer or itunes

    First, itunes told me my ipod was corrupted so I rest ored it. Then itunes wouldn't allow me to add my music back on, it gave me many pop ups saying it couldn't sync because the folder could not be foundt Lots of reports saying it couldn't copy my mu

  • Connecting guitar to new imac

    Just recieved the new 27" imac and i'm trying to connect my electric guitar. But there is no 3.5 audio input jack socket anymore just the 3.5 headphone socket? does this mean i have to buy a audio interface or a 6.5mm female to USB cable?

  • Deleting mailbox without removing user object? Exchange 2010

    In Exchange 2010, How can I delete a mailbox but keep the User Object since this user still access the network??

  • Problems with Disc Burner not being found.!?!?

    I just downloaded the newest version... I also paid for like 10 songs... but I can't burn ANYTHING b/c it says that the disc burner can't be found. Well the only thing is suggest is to reinstall!! WILL I LOOSE THE SONGS I JUST PAID FOR???? SOmeone pl

  • Having Admin Account problem

    I recently joined the Adobe Creative Cloud and downloaded many of the applications I use. Some of those applications will not open and in working with an Adobe service rep we discovered that it has something to do with my current Admin Account. I've