BoxLayout : unslightly gaps betw vertical components?

Hi, all.
I've this BoxLayout with PAGE_AXIS alignment, it works, but there is this big gap between the components vertically. The components are self-defined and consists a pair of JLabel and JTextArea.
How do I pack the components tighter vertically?
TIA :-)
public class LayoutTest extends JApplet implements AdjustmentListener
{ LabeledTextField lblName, lblAddr1, lblAddr2, lblCity;
   public void init()
  { setBackground(Color.lightGray);
    Container contentPane = getContentPane();
    // ...java     
    JPanel px = new JPanel();
    JPanel p9 = new JPanel();
    p9.setLayout(new BoxLayout(p9, BoxLayout.PAGE_AXIS));
    p9.setBorder(BorderFactory.createLineBorder(Color.RED));
      lblName = new LabeledTextField("Name", "Inside a BoxLayout");
      lblAddr1 = new LabeledTextField("Address", "PAGE_AXIS orientation");
      lblAddr2 = new LabeledTextField("Address", "PAGE_AXIS orientation");
      lblCity = new LabeledTextField("City", "PAGE_AXIS orientation");
    p9.add(lblName);
    p9.add(lblAddr1);
    p9.add(lblAddr2);
    p9.add(lblCity);
    px.add(p9);  
    contentPane.add(px);And here is the LabeledTextField defining a pair of JLabel and JTextArea:
public class LabeledTextField extends JPanel
{ private JLabel lbl;
  private JTextField txtFld;
  public LabeledTextField(String lblString,
                          Font lblFont,
                          int txtFieldSize,
                          Font txtFont)
  { setLayout(new FlowLayout(FlowLayout.LEFT));
    lbl = new JLabel(lblString, JLabel.RIGHT);
    if (lblFont != null) {lbl.setFont(lblFont);}
    add(lbl);
    txtFld = new JTextField(txtFieldSize);
    if (txtFont != null) {txtFld.setFont(txtFont);}
    add(txtFld);
  public LabeledTextField(String lblString, String txtFieldString)
  { this(lblString, null, txtFieldString, txtFieldString.length(), null);
  public LabeledTextField(String lblString, int txtFieldSize)
  { this(lblString, null, txtFieldSize, null);
  public LabeledTextField(String lblString,
                          Font lblFont,
                          String txtFieldString,
                          int txtFieldSize,
                          Font txtFont)
  { this(lblString, lblFont, txtFieldSize, txtFont);
    txtFld.setText(txtFieldString);
  public JLabel getLabel() {return(lbl);}
  public JTextField getTextField() {return(txtFld);}
}

This might explain it. I put a border around the JLabel + JTextArea pair defined by the custom helper class LabeledTextField, and it seems LabeledTextField forces a rigid area around it.
Is this because LabeledTextField extends JPanel ???
If so how do I get rid of the rigid area enforced by JPanel ???
    JPanel p9 = new JPanel();
    p9.setLayout(new BoxLayout(p9, BoxLayout.Y_AXIS));
    //p9.setBorder(BorderFactory.createLineBorder(Color.RED));
      lblName = new LabeledTextField("Name", "Inside a BoxLayout");
        lblName.setBorder(BorderFactory.createLineBorder(Color.RED));
      lblAddr1 = new LabeledTextField("Address", "PAGE_AXIS orientation");
        lblAddr1.setBorder(BorderFactory.createLineBorder(Color.GREEN));
      lblAddr2 = new LabeledTextField("Address", "PAGE_AXIS orientation");
        lblAddr2.setBorder(BorderFactory.createLineBorder(Color.BLUE));
      lblCity = new LabeledTextField("City", "PAGE_AXIS orientation");
    p9.add(lblName);
      p9.add(Box.createVerticalStrut(1));
    p9.add(lblAddr1);
      p9.add(Box.createVerticalStrut(1));
    p9.add(lblAddr2);
      p9.add(Box.createVerticalStrut(1));
    p9.add(lblCity);
      p9.add(Box.createVerticalGlue());
    px.add(p9);  

Similar Messages

  • Charts: Gap between Vertical Axis and the chart area

    Friends,
    I have a really wierd issue and I am sure I am doing
    something wrong.
    I am trying to align 2 charts that are placed vertically. I
    want to align the left vertical axis and the gridlines within them.
    Aligning the left vertical axis is easy and done but aligning the
    grids is becoming challenging and I have already spent a few hours
    on this problem.
    Here is a wrong chart image ...
    Wrong
    chart image
    The line of the LineChart (in the top chart) is touching the
    left and right edges where as the bottom chart bars do not touch
    the left/right edges. Due to this the gridlines are not aligned.
    I had managed to solve this problem but I am not sure what
    part of the code solved the problem. Here is the right chart image:
    Right
    chart image
    In this chart, the line of the linechart (in the top chart)
    is not touching the left and right boundary hence the gridlines are
    alignd with each other.
    I wonder what property of the chart controls the series
    touching the left/right vertical axis or boundary. Your help is
    appreciated.
    Thanks

    here is some more information ...
    I started changing some of the properties of the chart which
    I mentioned is a RIGHT CHART and this is what I learnt ...
    It was a CartesianChart hence it was creating the gap
    between the left/right vertical axis and the actual chart area
    (refer to the right chart image).
    I changed it to a LineChart and it started behaving like the
    chart in the WRONG CHART image.
    Is there a solution to this problem?

  • IPhone 5 screen has visible gap between vertical pixel columns...

    Hi, i might be nitpicking the issue but my new iPhone 5 (White) has a visible gap between each pixel colum (vertical only). Ever since the iPhone 4 came out I was amazed by how "sharp" everything looked and even the smallest text would barely be very crisp and legible. We have two iPhone 5's in the family and the newest one built week 21 of 2013 has this annoying visible vertical gap. It's mostly noticable on solid lighter colors. The older 4 & 5 phones are as crisp as always. I've shown it to several people and they have been able to spot the difference. Has anyone else noticed this? I've checked out a few display models at the Apple Store and half of them seem to be like mine, the other half are not. I'm thinking the ones that are like mine must all be fitted with the same display supplier or there might be a video chip issue of some sort. Any help would be appreciated. Thank you.

    No , it's common at least I got this issue. I just replaced my iphone due to power butto failure and now I my replacement unt exactly like what ts stated. When you stare on the screen it's quite hard to notice, it's visible when move your eyes or the phone left right. It's very clear on grey and blue color.
    I think it's not screen defective but lower cost LCD vendor , I got this kind of issue on my replacement dell LCD too( Samsung ) then I straight ask for lg screen which is same brand as original and no such problem.
    Btw I will still ask for replacement from apple

  • BoxLayout: components with different alignmentX

    Hi all. Java newbie here.. Here's what I'm trying to do: Use BoxLayout to "left-align" three components, and have one component at the bottom centered at its container/frame.
    Something like this:
    | ( One )        |
    | ( Two )        |
    | ( Three )      |
    |     ( Four )   |
    `----------------'I want the Fourth component to be exactly in the center of the frame, and the others to be left-aligned to the frame. Here's the code:
    JButton b1 = new JButton("One");
    JButton b2 = new JButton("Two");
    JButton b3 = new JButton("Three");
    JButton b4 = new JButton("Four");
    b1.setAlignmentX(Component.LEFT_ALIGNMENT);
    b2.setAlignmentX(Component.LEFT_ALIGNMENT);
    b3.setAlignmentX(Component.LEFT_ALIGNMENT);
    b4.setAlignmentX(Component.CENTER_ALIGNMENT);
    // Add them all to container with BoxLayout.PAGE_AXISAccording to Sun's tutorial, fixing alignment problems can be done by setAlignmentX. Obviously, I didn't understand their documentation because the buttons come out differently.
    Any fix for this? Thanks for the help in advance.
    Message was edited by:
    astigmatik

    Just a quick note :
    In the doco for it says :
    setAlignmentX - sets the vertical alignment
    setAlignmentY - sets the horizontal alignment
    I think you want Y and not X
    I do want X because Y refers to TOP/CENTER/BOTTOM_ALIGNMENT, and I'm looking for LEFT/RIGHT/CENTER_ALIGNMENT. It is in the "Fixing Alignment Problems" (http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html#align).

  • Laying out components in a JTextPane

    After some investigation, it seems like JTextPane uses LayoutManager2 and behaves in a way similar to BoxLayout when laying out its components inside. I've got some text and JLabels inside a JTextPane, and they don't seem to line up vertically correctly... the JLabel always appears below the text. Using setAlignmentX or Y, or changing the size of the JLabel effect the positioning of the label relative to the text. But it's too hard to line things up correctly without changing the text settings.
    1. Is it possible to set some positioning attributes on the text like for JLabel?
    2. Are there any simple tricks we can use to make the JLabels line up with the text?

    JTextPane sucks, the layout really doesn't make sense. To get JLabels which are on the same line as the regular text to line up, you can make the JLabel taller than a line of text and setVerticalAlingment to top... then it will almost be aligned. But it's still off, and it wastes a lot of space between wrapped lines.
    There has got to be a better way!

  • BoxLayout alignment issue

    Hello,
    Can someone please explain why my JPanel with a BoxLayout will not align the components to the left? Can I not use the BoxLayout with a JPanel? If not, is there another LayoutManager I can use that will display the component aligned to the left going downward?
    Container pane = this.getContentPane();
    pane.setLayout( new BoxLayout( pane, BoxLayout.Y_AXIS ) );
    //the components in this panel will not align to the left
    //the components are indented
    JPanel aPanel = new JPanel();
    aPanel.setLayout( new BoxLayout( aPanel, BoxLayout.Y_AXIS ) );
    JLabel textLabel = new JLabel("test");
    aPanel.add( textLabel );
    //this panel aligns correctly
    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout( new FlowLayout( FlowLayout.LEFT ) );
    JButton okButton = new JButton( "OK" );
    okButton.addActionListener( new OkButtonListener() );
    buttonpanel.add( okButton );
    pane.add( buttonPanel ); //aligning to the left of the frame correctly
    pane.add( aPanel ); //indented 15 spaces from the left of the frame?
    Thank you.

    1) Use the "code" formatting tags when posting code, so the code retains its original formatting
    2) Read the Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/box.html]How to Use the Box Layout. It explains how the "X Alignment" of a component affects positioning.

  • Details for last question I post

    the original code for last question I post(about the DataInputStream& EOFException) is here, thanks if anyone will bother to read it
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.* ;
    public class MasterMindServer
         public MasterMindServer()
              try{
                   ServerSocket serverSocket=new ServerSocket(8000);
                   Socket socket=serverSocket.accept();
                   HandleAClient thread=new HandleAClient(socket);
                   thread.start();
                   }catch(IOException e){System.out.println("Error:"+e.toString());}
         public static void main(String args[])
              new MasterMindServer();
    //inner class
    class HandleAClient extends Thread
         DataOutputStream out;
         DataInputStream in;
         BufferedReader fromFile;
         private Socket socket;
         String line;
         public HandleAClient(Socket socket)
              this.socket=socket;
         public void run()
              int x,o;
              try{
                     out=new DataOutputStream(socket.getOutputStream());
                   in=new DataInputStream(socket.getInputStream());
                   fromFile=new BufferedReader(new FileReader("colorcode.txt"));
                  while((line=fromFile.readLine())!=null)
                    for(int i=0;i<10;i++)
                      String t=in.readUTF();
                      x=check_column(t);
                       System.out.println(x);
                       o=check_color(t);
                       System.out.println(o);
                       out.writeInt(x);
                       out.writeInt(o);
                       if(x==6) break;
                     out.writeUTF(line);
                   socket.close();
                   System.out.println("close");
             }catch(IOException e){
             System.out.println("Error:"+e.toString());}
         public int check_column(String s)
              String str;
              str=s;
              int count=0;
              for(int i=0;i<6;i++)
                   if(s.charAt(i)==line.charAt(i))
                   count++;
              return count;
         public int check_color(String s)
              String str;
              str=s;
              int count=0;
              for(int i=0;i<6;i++)
                   if((line.indexOf(s.charAt(i))!=-1)&&(line.charAt(i)!=s.charAt(i)))
                   count++;
              return count;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.* ;
    public class MasterMindClient extends JFrame implements MouseListener,ActionListener
      /** Default constructor */
      //keep track of the row (or trial) and column number
      int trial_num, col_now ;
      Socket socket;
      int count[]={5,5,5,5,5,5};
    JPanel A[]  = new JPanel[10];
      JPanel B1[] = new JPanel[10];
      JPanel B2[] = new JPanel[10] ;
      JPanel notice = new JPanel() ;
      JPanel sub_notice = new JPanel();
      JPanel D1, D2 ;
      static JTextField [][]color = new JTextField[10][6] ;
      static JTextField [][]Output = new JTextField[10][2];
      static JTextField [][]Answer = new JTextField[1][6] ;
      static JButton []ok = new JButton[10];  
      JLabel L1 = new JLabel("Click the textfield to change color");
      JLabel L2 , L3, L4 ;
      String colorRange="BCGRYW";
      Color colorName[]={Color.black,Color.cyan,Color.green,Color.red,Color.yellow,Color.white};
      String temp ;
    public MasterMindClient() {
        // initialize
        trial_num = 0;
        col_now = 0;
        //sub_notice is Panel where the heading labels are placed
        sub_notice.setLayout(new GridLayout(1,3)) ;
        L2 = new JLabel("  ") ;
        L3 = new JLabel("X");
        L3.setHorizontalAlignment(JTextField.CENTER);
        L4 = new JLabel("O");
        L4.setHorizontalAlignment(JTextField.CENTER);
        L3.setToolTipText("matching color and column");
        L4.setToolTipText("matching color but not matching column" );
        sub_notice.add(L2);
        sub_notice.add(L3);
        sub_notice.add(L4);
        notice.setLayout(new GridLayout(1,2)) ;
        notice.add(L1) ;
        notice.add(sub_notice) ;
        // Get the content pane of the frame
        Container c = getContentPane();
        // Set GridLayout, 4 rows, 3 columns, and gaps 5 between
        // components horizontally and vertically
        c.setLayout(new GridLayout(12, 1, 5, 5));
        c.add(notice);
         JPanel Display = new JPanel() ;
         Display.setLayout(new GridLayout(1,2,5,5)) ;
       //create a Panel for each row to accept use input
       // color[][] textfield is where the user input
       // Output[][] is where to display the number of X and O
        for (int i = 0; i <= A.length-1 ; i++)
        A[i] = new JPanel() ;
        A.setLayout(new GridLayout(1, 2,10,10));
    B1[i] = new JPanel();
    B1[i].setLayout(new GridLayout(1,6,5,5)) ;
    B2[i] = new JPanel();
    B2[i].setLayout(new GridLayout(1,3,5,5)) ;
    for (int j = 0; j <= color[i].length-1 ; j++)
    color[i][j] = new JTextField() ;
    color[i][j].setHorizontalAlignment(JTextField.CENTER);
    if (i == 0)
    {color[i][j].setEditable(true) ;
    else
    {color[i][j].setEditable(false);
    color[i][j].addMouseListener(this);
    B1[i].add(color[i][j]) ;
    } // j loop
    ok[i] = new JButton("SEND");
    if(i==0)
         ok[i].setEnabled(true);
    else
         ok[i].setEnabled(false);
    ok[i].addActionListener(this);
    B2[i].add(ok[i]) ;
    Output[i][0] = new JTextField();
    Output[i][1] = new JTextField();
    Output[i][0].setEditable(false);
    Output[i][1].setEditable(false);
    Output[i][0].setHorizontalAlignment(JTextField.CENTER);
    Output[i][1].setHorizontalAlignment(JTextField.CENTER);
    B2[i].add(Output[i][0]);
    B2[i].add(Output[i][1]);
    A[i].add(B1[i]);
    A[i].add(B2[i]) ;
    c.add(A[i]) ;
    } //for i loop
    //D panel is where we store the answer[][]
    D1 = new JPanel();
    D1.setLayout(new GridLayout(1,6)) ;
    D2 = new JPanel();
    D2.setLayout(new GridLayout(1,2)) ;
    for (int j = 0; j <= Answer[0].length-1 ; j++)
    Answer[0][j] = new JTextField(0) ;
    Answer[0][j].setHorizontalAlignment(JTextField.CENTER);
    Answer[0][j].setEditable(false) ;
    D1.add(Answer[0][j]) ;
    Display.add(D1) ;
    Display.add(D2) ;
    c.add(Display) ;
    public void runClient()
         try
    {      socket=new Socket("localhost",8000);
    DataInputStream in=new DataInputStream(socket.getInputStream());
    int x=0;
    int o=0;
    try{
    while(true)
         while(trial_num<10)
              x=in.readInt();
              //System.out.println(x);
              Output[trial_num][0].setText(String.valueOf(x));
              o=in.readInt();
              //System.out.println(o);
              Output[trial_num][1].setText(String.valueOf(o));
              for(int i=0;i<6;i++)
              color[trial_num][i].setEnabled(false);
         ok[trial_num].setEnabled(false);
         trial_num++;
         col_now=0;
         if(x==6)
                   JOptionPane.showMessageDialog( null, "Congratulation, you've won the game !! " );
                   //ok[trial_num].setEnabled(false);
    break;
         if(trial_num<10)
         {  for(int i=0;i<6;i++)
              color[trial_num][i].setEditable(true);
              count[i]=5;
         ok[trial_num].setEnabled(true);
         if(x!=6)
         {  JOptionPane.showMessageDialog( null, "sorry you did not win the game");
         temp=in.readUTF();
         System.out.println(temp);
         //temp=in.readUTF();
         //System.out.println("can");
         for(int i=0;i<6;i++)
         System.out.println(i);
         char a=temp.charAt(i);
         int index=colorRange.indexOf(String.valueOf(a));
         Answer[0][i].setBackground(colorName[index]);
         trial_num=0;
         for(int j=0;j<10;j++)
         for(int k=0;k<6;k++)
         color[j][k].setBackground(Color.white);
         for(int j=0;j<10;j++)
         for(int k=0;k<2;k++)
         Output[j][k].setText(null);
         for(int i=0;i<6;i++)
              color[trial_num][i].setEditable(true);
              count[i]=5;
         ok[0].setEnabled(true);
         catch(EOFException em){}
         }catch(IOException ex){
              System.out.println("Error:"+ex.toString());}
    public void mouseClicked(MouseEvent e)
    for(int i=0;i<6;i++)
         if(e.getComponent()==color[trial_num][i])
         {         col_now=i;
         break;
    count[col_now]=(count[col_now]+1)%6;
    color[trial_num][col_now].setBackground(colorName[count[col_now]]);
    public void mouseEntered(MouseEvent e)
    public void mouseExited(MouseEvent e)
    public void mouseReleased(MouseEvent e)
    public void mousePressed(MouseEvent e)
    public void actionPerformed(ActionEvent e)
         try{
              send();
         }catch(IOException et){System.out.println("Error:"+et);}
    public void send()throws IOException
         DataOutputStream out=new DataOutputStream(socket.getOutputStream());
         char cbuf[]=new char[6];
         for(int i=0;i<6;i++)
              cbuf[i]=colorRange.charAt(count[i]);
    System.out.println(cbuf);
         out.writeUTF(new String(cbuf));
    /** Main method */
    public static void main(String[] args) {
    MasterMindClient frame = new MasterMindClient();
    frame.setTitle("Master Mind");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocation(300,300) ;
    frame.setSize(450, 450);
    frame.setVisible(true);
    frame.runClient();
    } // end of class

    I notice that you have several hundred lines of GUI code there. None of them have anything to do with the problem you are trying to solve. So put them all aside and write a SMALL test program that does nothing but the little loop you are having a problem with. Shouldn't be more than 20 lines of code.

  • How can I use a FocusEvent to distinguish among editable JComboBoxes?

    Hi,
    I have a Frame with multiple editable JComboBoxes, but I am at a loss as to how to sort them out in the focusGained() method.
    It is easy when they are not editable, because the FocusEvent getSource() Method returns the box that fired the event. That lets me read an instance variable that is set differently for each box.
    But with editable boxes, the FocusEvent is not fired by the box. It is fired by a Component object returned by getEditor().getEditorComponent(). So far I cannot find a way to query that object to find the box it it tied to. (I hope this isn't going to be painfully embarassing.).
    Anyway, the code below produces a frame with four vertical components: a JTextField (textField), a NON-Editable JComboBox (comboBox1) and two Editable JComboBoxes (comboBox2 & comboBox3).
    This is the command screen produced by :
    - Running the class
    - Then tabbing through all the components to return to the text field.
    I am not sure why, but it gives the last component added the foucus on startup.Focus Gained - Begin: *****
       This is the comboBox that Is Not Editable
    Focus Gained - End: *******
    Focus Gained - Begin: *****
       This Is The TextField
    Focus Gained - End: *******
    Focus Gained - Begin: *****
       Class: class javax.swing.plaf.metal.MetalComboBoxEditor$1
       Name: javax.swing.plaf.metal.MetalComboBoxEditor$1
    Focus Gained - End: *******
    Focus Gained - Begin: *****
       Class: class javax.swing.plaf.metal.MetalComboBoxEditor$1
       Name: javax.swing.plaf.metal.MetalComboBoxEditor$1
    Focus Gained - End: *******
    Focus Gained - Begin: *****
       This is the comboBox that Is Not Editable
    Focus Gained - End: *******
    Focus Gained - Begin: *****
       This Is The TextField
    Focus Gained - End: *******As you can see, the FocusEvent source for both editable boxes is a MetalComboBoxEditor. Both have identical names.
    Can anyone help me get from there back to the actual combo box so I can read the instance variable to see which one fired the event?
    The (painfully tedious and inelegant ) code that produced the above output is:import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TestListeners extends JFrame
      implements ActionListener, DocumentListener,
                             FocusListener,  ItemListener {
      // Constructor
       TestListeners () {
          super ();
          panel.setLayout (new GridLayout (4, 1));
          textField.addActionListener (this);
          textField.getDocument ().addDocumentListener (this);
          textField.addFocusListener (this);
          panel.add(textField);
          comboBox2.addActionListener (this);
          comboBox2.getEditor().getEditorComponent ().addFocusListener (this);
          comboBox2.addItemListener (this);
          comboBox2.setEditable (true);
          panel.add (comboBox2);
          comboBox3.addActionListener (this);
          comboBox3.getEditor().getEditorComponent ().addFocusListener (this);
          comboBox3.addItemListener (this);
          comboBox3.setEditable (true);
          panel.add (comboBox3);
          comboBox1.addActionListener (this);
          comboBox1.addFocusListener (this);
          comboBox1.addItemListener (this);
          comboBox1.setEditable (false);
          panel.add (comboBox1);
          this.getContentPane ().add(panel);
          this.setVisible (true);
          pack ();
       // Nested class
        public class CB extends JComboBox {
           // Nested Constructor
          public CB  (Vector items, String str) {
             super (items);
             this.type = str;
          public String type;
       // Instance Members
       JTextField     textField = new JTextField ("Test Listener TextField");
       JPanel panel  = new JPanel ();
       String[] str = {"one", "two", "three"};
       Vector items = new Vector (Arrays.asList (str));
       CB comboBox1 = new CB (items, "Is Not Editable");
       CB comboBox2 = new CB (items, "Is Editable 2");
       CB comboBox3 = new CB (items, "Is Editable 3");
       // Methods
       public static void main(String args[]) {
          TestListeners frame = new TestListeners ();
       public void actionPerformed (ActionEvent ae) {
          System.out.print ("ActionEvent: This is ");
           if (ae.getSource ().getClass () == CB.class) {
             System.out.print ( ((CB) ae.getSource ()).type + " ");
          System.out.println (" "+ae.getActionCommand() + "\n" );
       public void focusGained (FocusEvent fge) {
          System.out.println ("Focus Gained - Begin: ***** ");
          if (fge.getSource ().getClass () == CB.class) {
          System.out.println ( "   This is the comboBox that "+((CB) fge.getSource ()).type);
          } else if (fge.getSource ().getClass () == JTextField.class) {
             System.out.println ( "   This Is The TextField");
         } else {
             System.out.println ("   Class: "+fge.getSource ().getClass());
             System.out.println ("   Name: "+fge.getSource ().getClass ().getName ());
         System.out.println ("Focus Gained - End: *******\n*\n");
       public void focusLost (FocusEvent fle) { }
       public void changedUpdate (DocumentEvent de) { }
       public void insertUpdate (DocumentEvent de) { }
       public void removeUpdate (DocumentEvent de) { }
       public void itemStateChanged (ItemEvent ie) { }
    }

    I added the following in your focusGained() method and it seemed to work:
    Component c = ((Component)fge.getSource ()).getParent();
    if (c instanceof JComboBox)
         JComboBox cb = (JComboBox)c;
         System.out.println("Selected: " + cb.getSelectedItem());
    }

  • Using my new GUI component in an applet :Help!!!

    I am seeking help for the following
    Define class MyColorChooser as a new component so it can be reused in other applications or applets. We want to use the new GUI component as part of an applet that displays the current Color value.
    The following is the code of MyColorChooser class
    * a) We define a class called MyColorChooser that provides three JSlider
    * objects and three JTextField objects. Each JSlider represents the values
    * from 0 to 255 for the red, green and blue parts of a color.
    * We use wred, green and blue values as the arguments to the Color contructeur
    * to create a new Color object.
    * We display the current value of each JSlider in the corresponding JTextField.
    * When the user changes the value of the JSlider, the JTextField(s) should be changed
    * accordingly as weel as the current color.
    * b)Define class MyColorChooser so it can be reused in other applications or applets.
    * Use your new GUI component as part of an applet that displays the current
    * Color value.
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.text.DecimalFormat;
    public class MyChooserColor extends JFrame{
         private int red, green, blue;  // color shade for red, green and blue
         private static Color myColor;  // color resultant from red, green and blue shades
         private JSlider mySlider [];      
         private JTextField textField [];
    // Panels for sliders, textfields and button components
         private JPanel mySliderPanel, textFieldPanel, buttonPanel;
    // sublcass objet of JPanel for drawing purposes
         private CustomPanel myPanel;
         private JButton okButton, exitButton;
         public MyChooserColor ()     
              super( "HOME MADE COLOR COMPONENT; composition of RGB values " );
    //       setting properties of the mySlider array and registering the events
              mySlider = new JSlider [3];
              ChangeHandler handler = new ChangeHandler();
              for (int i = 0; i < mySlider.length; i++)
              {     mySlider[i] = new JSlider( SwingConstants.HORIZONTAL,
                               0, 255, 255 );
                   mySlider.setMajorTickSpacing( 10 );
                   mySlider[i].setPaintTicks( true );
    //      register events for mySlider[i]
                   mySlider[i].addChangeListener( handler);                     
    //      setting properties of the textField array           
              textField = new JTextField [3];          
              for (int i = 0; i < textField.length; i++)
              {     textField[i] = new JTextField("100.00%", 5 );
                   textField[i].setEditable(false);
                   textField[i].setBackground(Color.white);
    // initial Background color of each slider and foreground for each textfield
    // accordingly to its current color shade
              mySlider[0].setBackground(
                        new Color ( mySlider[0].getValue(), 0, 0 ) );
              textField[0].setForeground(
                        new Color ( mySlider[0].getValue(), 0, 0 ) );           
              mySlider[1].setBackground(
                        new Color ( 0, mySlider[1].getValue(), 0 ) );
              textField[1].setForeground(
                        new Color ( 0, mySlider[1].getValue(), 0 ) );
              mySlider[2].setBackground(
                        new Color ( 0, 0, mySlider[2].getValue() ) );
              textField[2].setForeground(
                        new Color ( 0, 0, mySlider[2].getValue() ) );
    // initialize myColor to white
              myColor = Color.WHITE;
    // instanciate myPanel for drawing purposes          
              myPanel = new CustomPanel();
              myPanel.setBackground(myColor);
    // instanciate okButton with its inanymous class
    // to handle its related events
              okButton = new JButton ("OK");
              okButton.setToolTipText("To confirm the current color");
              okButton.setMnemonic('o');
              okButton.addActionListener(
                   new ActionListener(){
                        public void actionPerformed (ActionEvent e)
                        {     // code permetting to transfer
                             // the current color to the parent
                             // component backgroung color
                             //System.exit( 0 );     
    //      instanciate exitButton with its inanymous class
    //      to handle its related events           
              exitButton = new JButton("Exit");
              exitButton.setToolTipText("Exit the application");
              exitButton.setMnemonic('x');
              exitButton.addActionListener(
                        new ActionListener(){
                             public void actionPerformed (ActionEvent e)
                             {     System.exit( 0 );     
    // define the contentPane
              Container c = getContentPane();
              c.setLayout( new BorderLayout() );
    //     panel as container for sliders
              mySliderPanel = new JPanel(new BorderLayout());
    //      panel as container for textFields           
              textFieldPanel = new JPanel(new FlowLayout());
    //      panel as container for Jbuttons components           
              buttonPanel = new JPanel ();
              buttonPanel.setLayout( new BoxLayout( buttonPanel, BoxLayout.Y_AXIS ) );
    //add the Jbutton components to buttonPanel           
              buttonPanel.add(okButton);
              buttonPanel.add(exitButton);
    //     add the mySlider components to mySliderPanel
              mySliderPanel.add(mySlider[0], BorderLayout.NORTH);
              mySliderPanel.add(mySlider[1], BorderLayout.CENTER);
              mySliderPanel.add(mySlider[2], BorderLayout.SOUTH);
    //add the textField components to textFieldPanel     
              for (int i = 0; i < textField.length; i++){
                   textFieldPanel.add(textField[i]);
    // add the panels to the container c          
              c.add( mySliderPanel, BorderLayout.NORTH );
              c.add( buttonPanel, BorderLayout.WEST);
              c.add( textFieldPanel, BorderLayout.SOUTH);
              c.add( myPanel, BorderLayout.CENTER );
              setSize(500, 300);          
              show();               
    //     inner class for mySlider events handling
         private class ChangeHandler implements ChangeListener {          
              public void stateChanged( ChangeEvent e )
    // start by collecting the current color shade
    // for red , forgreen and for blue               
                   setRedColor(mySlider[0].getValue());
                   setGreenColor(mySlider[1].getValue());
                   setBlueColor(mySlider[2].getValue());
    //The textcolor in myPanel (subclass of JPanel for drawing purposes)
                   myPanel.setMyTextColor( ( 255 - getRedColor() ),
                             ( 255 - getGreenColor() ), ( 255 - getBlueColor() ) );
    //call to repaint() occurs here
                   myPanel.setThumbSlider1( getRedColor() );
                   myPanel.setThumbSlider2( getGreenColor() );
                   myPanel.setThumbSlider3( getBlueColor() );
    // display color value in the textFields (%)
                   DecimalFormat twoDigits = new DecimalFormat ("0.00");
                   for (int i = 0; i < textField.length; i++){
                        textField[i].setText("" + twoDigits.format(
                                  100.0* mySlider[i].getValue()/255) + " %") ;
    // seting the textcolor for each textField
    // and the background color for each slider               
                   textField[0].setForeground(
                             new Color ( getRedColor(), 0, 0 ) );
                   mySlider[0].setBackground(
                             new Color ( getRedColor(), 0, 0) );
                   textField[1].setForeground(
                             new Color ( 0, getGreenColor() , 0 ) );
                   mySlider[1].setBackground(
                             new Color ( 0, getGreenColor(), 0) );
                   textField[2].setForeground(
                             new Color ( 0, 0, getBlueColor() ) );
                   mySlider[2].setBackground(
                             new Color ( 0, 0, getBlueColor() ) );
    // color of myPanel background
                   myColor = new Color (getRedColor(),
                             getGreenColor(), getBlueColor());
                   myPanel.setBackground(myColor);               
    // set methods to set the basic color shade
         private void setRedColor (int r){
              red = ( (r >= 0 && r <= 255) ? r : 255 );
         private void setGreenColor (int g){
              green = ( (g >= 0 && g <= 255) ? g : 255 );
         private void setBlueColor (int b){
              blue = ( (b >= 0 && b <= 255) ? b : 255 );
    // get methods (return the basic color shade)
         private int getRedColor (){
              return red ;
         private int getGreenColor (){
              return green;
         private int getBlueColor (){
              return blue;
         public static Color getMyColor (){
              return myColor;
    // main method                
         public static void main (String args []){
              MyChooserColor app = new MyChooserColor();
              app.addWindowListener(
                        new WindowAdapter() {
                             public void windowClosing( WindowEvent e )
                             {     System.exit( 0 );
    // inner class CustomPanel for drawing purposes
         private class CustomPanel extends JPanel {
              private int thumbSlider1 = 255;
              private int thumbSlider2 = 255;
              private int thumbSlider3 = 255;
              private Color myTextColor;
              public void paintComponent( Graphics g )
                   super.paintComponent( g );
                   g.setColor(myTextColor);
                   g.setFont( new Font( "Serif", Font.TRUETYPE_FONT, 12 ) );
                   DecimalFormat twoDigits = new DecimalFormat ("0.00");
                   g.drawString( "The RGB values of the current color are : "
                             + "( "     + thumbSlider1 + " , " + thumbSlider2 + " , "
                             + thumbSlider3 + " )", 10, 40);
                   g.drawString( "The current background color is composed by " +
                             "the folllowing RGB colors " , 10, 60);
                   g.drawString( "Percentage of RED from slider1 : "
                        + twoDigits.format(thumbSlider1*100.0/255), 10, 80 );
                   g.drawString( "Percentage of GREEN from slider2 : "
                        + twoDigits.format(thumbSlider2*100.0/255), 10, 100 );
                   g.drawString( "Percentage of BLUE from slider3 : "
                        + twoDigits.format(thumbSlider3*100.0/255), 10, 120 );
    // call to repaint occurs here     
              public void setThumbSlider1(int th){
                   thumbSlider1 = (th >= 0 ? th: 255 );
                   repaint();
              public void setThumbSlider2(int th){
                   thumbSlider2 = (th >= 0 ? th: 255 );
                   repaint();
              public void setThumbSlider3(int th){
                   thumbSlider3 = (th >= 0 ? th: 255 );
                   repaint();
              public void setMyTextColor(int r, int g, int b){
                   myTextColor = new Color(r, g, b);
                   repaint();
    //The following method is used by layout managers
              public Dimension getPreferredSize()
              {     return new Dimension( 150, 100 );
    The following is the code of application that tests the component
    //Application used to demonstrating
    // the homemade GUI MyChooserColor component
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    public class ShowMyColor extends JFrame {
         private JButton changeColor;
         private Color color = Color.lightGray;
         private Container c;
         MyChooserColor colorComponent;
         public ShowMyColor()
         {     super( "Using MyChooserColor" );
              c = getContentPane();
              c.setLayout( new FlowLayout() );
              changeColor = new JButton( "Change Color" );
              changeColor.addActionListener(
                        new ActionListener() {
                             public void actionPerformed( ActionEvent e )
                             {     colorComponent = new MyChooserColor ();
                                  colorComponent.show();
                                  color = MyChooserColor.getMyColor();
                                  if ( color == null )
                                       color = Color.lightGray;
                                  c.setBackground( color );
                                  c.repaint();
              c.add( changeColor );
              setSize( 400, 130 );
              show();
         public static void main( String args[] )
         {     ShowMyColor app = new ShowMyColor();
              app.addWindowListener(
                        new WindowAdapter() {
                             public void windowClosing( WindowEvent e )
                             {  System.exit( 0 );

    Yes, I want help for the missing code to add in actionPerformed method below. As a result, when you confirm the selected color (clicking the OK button), it will be transferred to a variable color of class ShowMyColor.
    // instanciate okButton with its inanymous class
    // to handle its related events
              okButton = new JButton ("OK");
              okButton.setToolTipText("To confirm the current color");
              okButton.setMnemonic('o');
              okButton.addActionListener(
                   new ActionListener(){
                        public void actionPerformed (ActionEvent e)
                        {     // code permetting to transfer
                             // the current color to the parent
                             // component backgroung color
                             //System.exit( 0 );     
              );

  • PDA Mouse Down Event on Picture Control

    While using the Mouse Down Event on the Picture Control for LabVIEW 7.1 PocketPC PDA, I want to get the xy coordinates on where the user tapped on the pict control. Any ideas or workarounds?
    Robert

    Hello Robert �
    What do you mean by �outputting individual horizontal and vertical components�?
    In the LabVIEW PDA module (and this applies to PocketPC and PalmOS), clusters will not show up in the PDA�s screen. You can use clusters to group controls/indicators but when there is need of sending a new value/showing the value in the screen, the bundle and unbundled functions have to be used, so that you can have individual controls/indicators to pass a new value/see the value, respectively.
    So, from the Coords terminal in a Mouse Down/Up event, you need to unbundle the cluster and create individual indicators for each, the horizontal and vertical position.
    I am attaching an example to show you what I mean. For PalmOS, the same applies.
    H
    ope this helps and if I misunderstood your post, please let me know.
    Have a great day.
    S Vences
    Applications Engineer
    National Instruments
    Attachments:
    PPC_Picture_Events.vi ‏30 KB

  • ECC 5.0 Unicode error

    Hi,
    During the upgrade from 4.6B to ECC 5.0, we are facing the following problem:
    In 4.6B, when we move the contents of one internal table to another ( itabA[] = itabB[] ), its happening properly, even though the structure of both the internal tables are not the same i:e itabB has more fields than itabA.
    But, this doesn't happen in the case of ECC 5.0. Its throwing some UNICODE error, saying that the structure isn't the same.
    If anyone has come across this problem, please revert with the solution.
    Thanks,
    Raj.

    hi,
    We are getting error because of unicode issues. We get this problem bcos of Alignment gaps.
    Hope the below explanation helps you..
    To check whether two structures can be converted at all, the Unicode fragment view of the structures is set up initially by combining character type groups, byte type groups, alignment gaps, and other components. If the type and length of the fragments of the source structure are identical in the length of the shorter structure, the structures can be converted. Assignment is allowed under the following conditions:
    The fragments of both structures up to the second-last fragment of the shorter structure are identical
    The last fragment of the shorter structure is a character or byte type group
    The corresponding fragment of the longer structure is a character or byte type group with a greater length
    If the target structure is longer than the source structure, the character type components of the remaining length are filled with blank characters. All other components of the remaining length are filled with the type-adequate initial value, and alignment gaps are filled with zero bytes. Since longer structures were previously filled with blanks by default, using initial values for non-character type component types is incompatible. This incompatible change is, however, rather an error correction. Character-type components are not filled with initial values, for the sake of compatibility.
    Example
    BEGIN OF struc1,                     BEGIN OF struc2,
      a(1) TYPE C,                         a(1) TYPE C,
      x(1) TYPE X,                         b(1) TYPE C,
    END OF struc1.                       END OF struc2.
    You cannot use the struc1 = struc2 assignment in Unicode, because struc1-x only occupies one byte, in contrast to struc2-b.
    BEGIN OF struc3,                     BEGIN OF struc4,
      a(2) TYPE C,                         a(8) TYPE C,
      n(6) TYPE N,                         i    TYPE I,
      i    TYPE I,                          f   TYPE F,
    END OF struc3.                       END OF struc4.
    The struc3 = struc4 assignment is valie because the fragment views of the character-type fields and the integer numbers match.
    BEGIN OF struc5,                     BEGIN OF struc6,
      a(1)  TYPE X,                        a(1) TYPE X,
      b(1)  TYPE X,                        BEGIN OF STRUC3,
      c(1)  TYPE C,                          b(1) TYPE X,
    END OF struc5.                           c(1) TYPE C,
                                           END OF struc3
                                         END OF struc6.
    However, struc5 = struc6 is not permitted - the fragment views of the two structure are different, because of the alignment gaps before struc3 and struc3-c.
    BEGIN OF struc7,                     BEGIN OF struc8,
      p(8)  TYPE P,                        p(8) TYPE P,
      c(1)  TYPE C,                        c(5) TYPE C,
    END OF struc7.                         o(8) TYPE P,
                                         END OF struc8.
    The struc7 = struc8 works because the fragment views in the length of the structure struc1 match.
    For deep structures, the operand types must be compatible as usual. We enhanced the concept by generalizing to some extent the convertibility of object references and table components.
    Regards,
    Sailaja.

  • Create border around Grid/GridItem

    Hi,
    I am stuck with a problem and no idea on how to proceed on this.
    I have created a Grid and want to draw border around it so its appearance is like table. The borders are just not appearing. Can someone provide any direction what I may be missing.
    Here is the code
    [PHP]
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
        <mx:Style>
            Grid
                horizontal-gap:-1;
                vertical-gap:-1;
                border-color:#000000;
                border-style:solid;
                border-thickness:5;
            GridItem
                border-color:#000000;
                border-style:solid;
                border-thickness:5;
        </mx:Style>
        <mx:Grid x="31" y="24">
            <mx:GridRow>
                <mx:GridItem width="100" height="30">
                    <mx:Label text ="Nitin">
                    </mx:Label>
                </mx:GridItem>
                <mx:GridItem width="100" height="30">
                    <mx:Label text ="Nitin">
                    </mx:Label>
                </mx:GridItem>
                <mx:GridItem width="100" colSpan="2" height="30">
                    <mx:Label text ="Nitin">
                    </mx:Label>
                </mx:GridItem>
            </mx:GridRow>
            <mx:GridRow>
                <mx:GridItem width="100" height="30">
                    <mx:Label text ="Nitin">
                    </mx:Label>
                </mx:GridItem>
                <mx:GridItem width="120" colSpan="2" height="30">
                    <mx:Label text ="Nitin">
                    </mx:Label>
                </mx:GridItem>
                <mx:GridItem width="100" colSpan="3" height="11">
                    <mx:Label text ="Nitin">
                    </mx:Label>
                </mx:GridItem>
            </mx:GridRow>
            <mx:GridRow>
                <mx:GridItem width="100" height="30">
                    <mx:Label text ="Nitin">
                    </mx:Label>
                </mx:GridItem>
                <mx:GridItem width="100" height="30">
                    <mx:Label text ="Nitin">
                    </mx:Label>
                </mx:GridItem>
                <mx:GridItem width="120" colSpan="3" height="30">
                    <mx:Label text ="Nitin">
                    </mx:Label>
                </mx:GridItem>
            </mx:GridRow>
        </mx:Grid>
    </mx:Application>
    [/PHP]

    I even tried using the graphics to create border but it is not working
    private var bgColor:uint 
    = 0x000000;
    private var borderColor:uint  = 0x666666;
    private var borderSize:uint   = 2;
    private var cornerRadius:uint = 0;
    var grid:Grid = new Grid();
    grid.graphics.beginFill(bgColor);
    grid.graphics.lineStyle(borderSize, borderColor);
    grid.graphics.drawRoundRect(0, 0, grid.width, grid.height, cornerRadius);
    grid.graphics.endFill();

  • Problem with sizing

    I have this problem I cant figure out. I have this class that extends JPanel called Container. It's layout is BoxLayout (Y_AXIS), and has two components. One of the components is a JPanel with just a picture drawn in it, and the other is a control panel with play,fast forward, rewind, and pause buttons.
    Then I have a ContainerPanels class which extends JPanel and is put into a JScrollPane. What I do is add/remove Containers to Container Panels. However, when I put some in so that the ContainerPanels panel isnt fully packed so that it starts to scroll, the individual Container panels get weird. The control panel gets off-centered from the picture panel.
    In the Container class I set preferred width to be equal to the picture panel's width, and yet the control panel is all the way off to the right. Can anyone explain this?

    yea I know its a bad name but its the best for its purpose and the only problem rly comes when I ask for help on these forums. Im not sure how a JTable would fix this, sorry if I explained it wrong. Heres the relevant code:
         public Container(String n, Experiment e)
              super();
              setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
              setBackground(Color.white);
              speedBar = new ContainerSpeedBar(this);
              picture = new ContainerPicture();
              Box pictureBox = Box.createHorizontalBox();
              pictureBox.add(Box.createHorizontalGlue());
              pictureBox.add(picture);
              pictureBox.add(Box.createHorizontalGlue());
              add(speedBar);
              add(pictureBox);
              setPreferredSize(new Dimension(picture.getPreferredSize().width,picture.getPreferredSize().height+speedBar.getPreferredSize().height+1));
         public ContainerSpeedBar(Container p)
              super();
              setLayout(new BoxLayout(this,BoxLayout.Y_AXIS));
              setBackground(Color.white);
              parent = p;
              Box control = Box.createHorizontalBox();
              control.add(rewind = new Rewind());
              control.add(play = new PlayPause());
              control.add(forward = new FastForward());
              Box control = Box.createHorizontalBox();
              add(control);
              add(display = new Display());
         public ContainerExplorer()
              super();
              setLayout(new BoxLayout(this,BoxLayout.X_AXIS));
              scrollThread = new Thread(this);
              scroll = 0;
              add(new ScrollPanel(LEFT));
              scrollPane = new JScrollPane(containers = new ContainerPanels());
              scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              add(scrollPane);
              add(new ScrollPanel(RIGHT));
              scrollThread.start();
              public ContainerPanels()
    //               setLayout(new RowLayout(10));
                   setBackground(Color.white);
                   Experiment e = new Experiment("",new DefaultSpecies());
                   add(Box.createHorizontalGlue());
                   add(new Container("",e));
                   add(new Container("",e));
              }the problem is the ContainerSpeedBar appears far to the right of ContainerPicture and I cant understand y...

  • Future of JavaFx and commitment from Sun

    Hi All,
    I wanted to get some insight into the level of investment an organization could make into adopting JavaFX as the preferred UI technology for their products/applications. Is Sun committed to promoting JavaFX and making it production quality and implementing with time all the missing UI components? What is th efuture of JavaFx after the Sun-Oracle merger?
    thanks
    Sanjeev

    Hi Sanjeev
    in my opinion:
    JavaFX is a promising technology but it is currently too green to consider use in a serious application. To my knowledge, only one company has so far released a serious product written in JavaFX (Indaba), but I've never used it and they themselves describe it as "alpha". I believe Indaba went with JavaFx because they were reliant on Java APIs (they were originally going to use Flash)
    The JavaFX team seem to be working hard on improving the technology, particularly around performance, however it is still quite buggy, and this will hamper efforts to produce a serious application. Also, as you mention, there are gaps in the components available for use in applications. There is also work going on for tooling.
    There are very little public facts available on the future of JavaFX (aside from sporadic marketing pushes). Oracle made a public commitment to JavaFX at JavaOne, but I don't know whether you can bet a corporate strategy on that alone. We know that future releases are coming, albeit at a slow pace.
    It would be great if Sun/Oracle could come up with something more detailed, as I think that (alongside a stable platform) would do a lot to increase the confidence of developers.
    My guess is that it will end up as a stable technology, though I've no idea how long this will take. To that end, I would closely monitor the progress of the technology but maybe not adopt it as the preferred technology just yet.

  • JScrollPane Doesn;t appear in JScrollPane?

    hi Following is the code of JPanel that contains JScrollPane.
    And JScrollPane adds again CompareView Panel
    CompareViewPanel is using custom defined Layout CompareViewLayout .
    But this as a output this panel is not showing the proper JScrollPane when outer frame size is lesser then the current panel(which contains JScrollPane).
    public class GalleryViewRightPanel extends JPanel {
    * Layout Manager
    private List <CapturedScreenControl> students;
    * Scroll Container.
    private final JScrollPane compareScrollPane;
    private final CompareView screenCtlContainerPanel;
    public GalleryViewRightPanel(List <CapturedScreenControl> students)
    //TODO - Add in super() Your Own Made Layout that will take care
    // of all the selected elements.
    //super();
    final int unitIncr = 96;
    final int blockIncr = 192;
    this.students = students;
    this.screenCtlContainerPanel = new CompareView(new CompareViewLayout());
    this.screenCtlContainerPanel.addComponentArray(this.students);
    compareScrollPane = new JScrollPane(screenCtlContainerPanel,
    JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    compareScrollPane.getVerticalScrollBar().setUnitIncrement(unitIncr);
    compareScrollPane.getVerticalScrollBar().setBlockIncrement(blockIncr);
    compareScrollPane.getHorizontalScrollBar().setUnitIncrement(unitIncr);
    compareScrollPane.getHorizontalScrollBar().setBlockIncrement(blockIncr);
    //setSize(compareScrollPane.getPreferredSize());
    add(compareScrollPane,BorderLayout.CENTER);
    setBorder(BorderFactory.createLineBorder(new Color(0,0,255,2)));
    public List<CapturedScreenControl> getStudentList()
    return students;
    public void setStudentList(final List<CapturedScreenControl> screenControl)
    students = screenControl;
    screenCtlContainerPanel.addComponentArray(students);
    //setSize(compareScrollPane.getPreferredSize());
    public void SetInfo()
    class CompareView extends JPanel
    public CompareView(LayoutManager layout)
    super(layout);
    public void addComponentArray(List <CapturedScreenControl> screens)
    removeComponentList();
    //Add Here All Components.
    for(CapturedScreenControl s: screens)
    //add(s);
    Rectangle rect = s.getBounds();
    add(new CompareImage(null,null,false,false,rect));
    updateUI();
    public void singleComponentArray(CapturedScreenControl screen)
    //removeComponentList();
    //Add here this screen component.
    //if(screen != null)
    // add(screen);
    public void removeComponentList()
    removeAll();
    class CompareViewLayout implements LayoutManager
    private int leftGap,topGap,middleGap,rightGap,bottomGap;
    * @param left : Left Gap before arranging Components.
    * @param top : Top Gap before arranging Components.
    * @param middle : Middle Gap between Components.
    * @param right : Right Gap before arranging Components.
    * @param bottom : Bottom Gap before arranging Components.
    public void setGaps(int left,int top,int middle, int right,int bottom)
    this.leftGap = left;
    this.topGap = top;
    this.middleGap = middle;
    this.rightGap = right;
    this.bottomGap = bottom;
    @Override
    public void addLayoutComponent(String name, Component comp)
    // TODO Auto-generated method stub
    // No need.
    @Override
    public void layoutContainer(Container parent)
    Dimension max = calculateSize(parent);
    Dimension size = parent.getSize();
    int compCount = parent.getComponentCount();
    if ((max.width == 0) || (max.height == 0)) {
    return;
    int rowCount = compCount/ScreenCaptureConstant.GALLERY_TWO_COMPONENT_SCREEN;
    int colCount = 1;
    if(rowCount == 0)
    rowCount = 1;
    if(compCount > ScreenCaptureConstant.GALLERY_MIN_COMPONENT_SCREEN)
    colCount = ScreenCaptureConstant.GALLERY_TWO_COMPONENT_SCREEN;
    int x = leftGap;
    int y = topGap;
    int row = 0;
    int col = 0;
    for(int count=0;count<compCount;count++)
    //Here Set XY-position and Size for all the controls.
    Component c = parent.getComponent(count);
    c.setLocation(x, y);
    c.setSize(max);
    col++;
    if(col >= colCount)
    col = 0;
    row++;
    //Set here other Controls.
    x = (col * (max.width + leftGap)) + middleGap;
    y = (row * (max.height + topGap)) + middleGap;
    @Override
    public Dimension minimumLayoutSize(Container parent)
    Dimension componentDim = new Dimension(0,0);
    int componentCount = parent.getComponentCount();
    //Only one component.
    if(componentCount == ScreenCaptureConstant.GALLERY_MIN_COMPONENT_SCREEN)
    //Considering that device types are of NSpire Device.
    componentDim.height = ScreenCaptureConstant.SINGLE_NSPIRE_COMONENT_HEIGHT + topGap + bottomGap;
    componentDim.width = ScreenCaptureConstant.SINGLE_NSPIRE_COMPONENT_WIDTH + leftGap + rightGap;
    //Two Components.
    else if(componentCount == ScreenCaptureConstant.GALLERY_TWO_COMPONENT_SCREEN)
    componentDim.height = ScreenCaptureConstant.MULTIPLE_NSPIRE_COMONENT_HEIGHT + topGap + bottomGap;
    componentDim.width = (2*ScreenCaptureConstant.MULTIPLE_NSPIRE_COMPONENT_WIDTH) + leftGap + rightGap + middleGap;
    //More than Two Components.
    else if(componentCount > ScreenCaptureConstant.GALLERY_TWO_COMPONENT_SCREEN &&
    componentCount <= ScreenCaptureConstant.GALLERY_MAX_COMPONENT_SCREEN )
    componentDim.height = (2*ScreenCaptureConstant.MULTIPLE_NSPIRE_COMONENT_HEIGHT) + topGap + bottomGap + middleGap;
    componentDim.width = (2*ScreenCaptureConstant.MULTIPLE_NSPIRE_COMPONENT_WIDTH) + leftGap + rightGap + middleGap;
    return componentDim;
    @Override
    public Dimension preferredLayoutSize(Container parent)
    Dimension singleScreenSize = calculateSize(parent);
    int cnt = parent.getComponentCount();
    if(cnt <= 0)
    return new Dimension();
    int cols = 1;
    if(cnt > ScreenCaptureConstant.GALLERY_MIN_COMPONENT_SCREEN)
    cols = ScreenCaptureConstant.GALLERY_MAX_COMPONENT_SCREEN;
    int rows = cnt / cols;
    if (cnt == 0)
    return new Dimension();
    else
    Dimension ret = new Dimension(singleScreenSize);
    ret.width = cols*(ret.width) + leftGap + rightGap + (cols-1)*middleGap;
    ret.height = rows*(ret.height) + topGap + bottomGap + (rows-1)*middleGap;
    return ret;
    @Override
    public void removeLayoutComponent(Component comp)
    // TODO Auto-generated method stub
    * @return
    private Dimension getBestFitSize(Dimension crntSize,Dimension maxsize,int nDeviceType)
    //Calculate here best fit.
    //This will say the best size of the component.
    int minWidth = crntSize.width;
    int minHeight = crntSize.height;
    while(minWidth+4<=maxsize.width && minHeight+3<=maxsize.height)
    minWidth = minWidth + 4;
    minHeight = minHeight + 3;
    return new Dimension(minWidth,minHeight);
    * @param parent : Calculate Each Component Size.
    * @return
    private Dimension calculateSize(Container parent)
    int componentCount = parent.getComponentCount();
    Dimension parSize = parent.getSize();
    Dimension comSize = new Dimension();
    if(componentCount == ScreenCaptureConstant.GALLERY_MIN_COMPONENT_SCREEN)
    //Logic to get the zoom
    //Only For NSpire Device.
    comSize.height = ScreenCaptureConstant.SINGLE_NSPIRE_COMONENT_HEIGHT;
    comSize.width = ScreenCaptureConstant.SINGLE_NSPIRE_COMPONENT_WIDTH;
    parSize.width -= (leftGap + rightGap);
    if((parSize.width > comSize.width) &&
    (parSize.height > comSize.height))
    //Here We Get the size for the One Image.
    return getBestFitSize(comSize,parSize,0);
    else if(componentCount > ScreenCaptureConstant.GALLERY_MIN_COMPONENT_SCREEN)
    //Only Considering for NSpire Devices.
    comSize.height = ScreenCaptureConstant.MULTIPLE_NSPIRE_COMONENT_HEIGHT + middleGap;
    comSize.width = ScreenCaptureConstant.MULTIPLE_NSPIRE_COMPONENT_WIDTH + middleGap;
    //Logic to get the zoom for multiple screens.
    parSize.width -= (leftGap + rightGap + middleGap);
    parSize.width = parSize.width/2 ;
    //Calculate Here the Size of Each Component.
    return new Dimension(parSize.width,getHeightFromWidth(parSize.width,0));
    return comSize;
    private int getHeightFromWidth(int nWidth,int nDeviceType)
    int nHeight = (nWidth*3)/4;
    return nHeight;
    class CompareImage extends Component {
    private static final Logger log = Logger.getLogger("gui.capturedScreen.CompareImageComponent");
    private Image lastGoodScreenImage;
    private Image screenImage;
    private boolean loaded;
    private boolean hasErrored;
    private Rectangle rect;
    * @param lastGoodImage
    * @param screenImage
    * @param loaded
    * @param error
    * @param rect
    public CompareImage(Image lastGoodImage,Image screenImage,boolean loaded, boolean error,Rectangle rect)
    super();
    this.lastGoodScreenImage = lastGoodImage;
    this.screenImage = screenImage;
    this.loaded = loaded;
    this.hasErrored = error;
    this.rect = rect;
    public synchronized void paint(Graphics g)
    String msg = "Image is Coming soon..." + rect.x + "," + rect.y + "," + rect.width + "," + rect.height;
    g.drawString(msg, 20, 20);
    Please help me to identify why this is not working??
    Thank you.
    Ajit.

    Hi,
    I Had created "class CompareViewLayout implements LayoutManager".
    Now you can see its implementation in code. This CompareViewLayout is used in CompareView Panel.
    And In compareScrollPane (JScrollPane) takes CompareView Panel as an argument in constructor.
    And compareScrollPane is added in Container(Top Level Panel) class.
    Now here,
    Whenever preferredLayoutSize() function of the LayoutManager is called, that will set the Components.
    But this functions is several time not called on resize of the frame..... normally this function called on each resize operation.
    In short Anyone Having idea what are the cases when preferredLayoutSize() function of the LayoutManager is not called ??
    And what to take care to avoid it??

Maybe you are looking for