Adding different images to different panels

If I am having a class which is extending Applet not JApplet and in that I am having CardLayout with 4 different panels. If I want to add 4 different images 2 these Panels what is the solution? Can anyone please help?

sorry
myPanel p1, p2, p3, p4;
class myPanel extends Panel
Image image;
public myPanel(Image img)
image = img;
public void paint (Graphics g)
if (image == null)
return;
g.drawImage(image, 0, 0, this);
}

Similar Messages

  • Adding gif image to a panel

    Hi
    i have had a look at the link that you have directed to me but i dont understand which code is neccessary for me. please could you help me with the code to add a GIF background image to a Jpanel.
    Thanks

    hi, no it wasnt this link but the link given was not suitable for my programming i need to add an image to a background using the drawImage() method could you please please please help me.
    Thanks

  • Displaying thumbnail images in another panel when it  mouse clicked

    hi,
    I am using JAI, what i am trying to do is i am decoding the tiff file and creating thumbnail of that images and adding thumbnail images to one panel and enlarged images to another panel using DisplayJAI. Now when i will click i thumbnail images on left panel then that image should be display to another panel on right side. Adding both panel to JSplit panel.
    I have no idia how to do it, i tried to do in different way but not able to do that. I hope anybody can give me the hints about this.
    Thanks

    i am adding thumbnail of all images in left panel and enlarged view of each thumbnail is added in right panel , and what i require that when i click thumbnail in left side it's corresponding enlarged image should be visible, suppose in right panel page no. 1 is visible and when i click thumbnail of 13 page in left panel that should be in viewport of right panel.You should put your right panel inside a JScrollPane and call [scrollRectToVisible() |http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#scrollRectToVisible(java.awt.Rectangle)] from your panel. You can put the rectangles corresponding to enlarged images in a hash map with the keys being some unique attribute of your thumbnails in left panel. That will help in getting the rectangle to make visible, real fast. Or, you can just put the rectangles in some array indexed according to the thumbnails in left panel.
    I also want to hide the left panel, i think it's possible by Frame.Yes it is possible, but you said you have both your panels in a split pane, so maybe you can use its setDividerLocation() function to hide your left panel.
    Thanks!

  • Set Cursor.vi fails after it has been called for 30 different panel refs in LV 7.1.1

    Make sure both attached files (Run LabVIEW_Cursor_TestCase.vi, SimpleVI.vi) are in the same folder. Run LabVIEW_Cursor_TestCase.vi notice that the -3 error code is returned from "Set Cursor.vi" after it has been called with 30 different panel refs. If "Set Cursor.vi" is replaced with "Set Busy.vi" the same error occurs.Is there a workaround for this problem other that setting the cursor image manually in user32.dll? I must be able to open more than 30 panels and set them all to busy. In the test case I used a single VI, simply to demonstrate the error.
    Message Edited by Jerred on 05-04-2007 10:06 AM
    Attachments:
    LabVIEW_Cursor_TestCase.vi ‏68 KB
    SimpleVI.vi ‏13 KB

    This bug is fixed in LabVIEW 8.0 and later.  Unfortunately, I know of no workaround in LabVIEW 7.x.  When I encountered this bug in one of my UIs in LabVIEW 7.x, my "fix" was simply to ignore the error outputs from the cursor VIs, and to live with the fact that I had no custom cursors after 30 windows had been opened.
    -D
    Darren Nattinger, CLA
    LabVIEW Artisan and Nugget Penman

  • Urgent!!!Want to add different panels in different rows..

    i am trying to add different Panels in differnt rows of same column..
    But each time i am getting the default panel which is being retuned by the MyTableCellRenderer class which i have implemented from TableCellRenderer .
    Would you like reply whats wrong in my approach...Can anyone modify my code???
    public class TablePanel extends JPanel
    JTable alertInsertTable;
    JScrollPane alertInsertPane;
    String columnnames[]={"Insert Alert"};
    Object[][] values={
    new JPanel()
    DefaultTableModel tableModel= new DefaultTableModel(values,columnnames);
    TablePanel()
    setLayout(new BorderLayout());
    alertInsertTable= new JTable(tableModel);
    alertInsertPane = new JScrollPane(alertInsertTable);
    alertInsertTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    this.add(alertInsertPane,BorderLayout.CENTER);
    setDataInTable();
    public void setDataInTable()
    int count=0;
    alertInsertTable.setRowHeight(80);
    MyTableCellRenderer ob=new MyTableCellRenderer();
    this.alertInsertTable.getColumn("Insert Alert").setCellRenderer(ob);
    JPanel panel1=new JPanel();
    JPanel panel2=new JPanel();
    panel1.add(new JLabel("HIiiiiiiiiiiiiiii"));
    panel2.add(new JLabel("Hellooooooooooooo"));
    Object[] ob1={panel1};
    Object[] ob2={panel2};
    model.addRow(ob1);
    //its always adding to the Panel with label new JLabel("Oppsssss")
    //which is the panel instance returned by MyTableCellRender
    model.addRow(ob2);
    // this also adding to the Panel with label new JLabel("Oppsssss")
    //which is the panel instance returned by MyTableCellRender
    // ? What code should i write here so that i can add panel1 and panel2
    //which i have created here.
    class MyTableCellRenderer extends JPanel implements TableCellRenderer
    public Component getTableCellRendererComponent(JTable table, Object value,
    boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex)
         JPanel panel = new JPanel();
         panel.add(new JLabel("Oppsssss"));
    return panel;
    }

    Only three exclamation marks; can't be that urgent.And only 1 cross-post...
    Let's continue here:
    http://forum.java.sun.com/thread.jspa?threadID=742590

  • Data communication b/w different panels!!!

    I have two different panels CFtree and CMyTab and I am trying to call a function of CFtree from CMyTab
    //+++++++++++++++++++++++++++++
    //CFtree code...
    // Generating only one object of this class like
    public class CFTree extends JTree implements ActionListener {
    private static CFTree objFeatureTree = null;
    public static CFTree createObject() {
    if (objFeatureTree == null) {
    objFeatureTree = new CFTree();
    return objFeatureTree;
    return objFeatureTree;
    * Get object of CFTree
    * @return CFTree
    public static CFTree getObject() {
    return objFeatureTree;
    public void dummy(){
    System.out.println("Feature tree function called");
    // CMyTab pseudo-code..
    public class CMyTab
    extends JPanel {
    CFTree mFtrTree = CFTree.getObject(); // calling to get current object of CFTree
    // and function acess like
    mFtrTree.dummy();
    As soon as mFtrTree.dummy() is called, following exception is thrown:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    What can be the reason for this? How can I specify in CMyTab that it is going to call a function placed in a different panel CFTree. What are the way to tackle this problem?
    Please comment!
    Thanks,
    rdh

    In the following statement, please replace "getObject" with "createObject":
    CFTree mFtrTree = CFTree.getObject(); // calling to get current object of CFTree

  • Problem updating a control on one panel based on a value change in another control on a different panel

    Hi,
    I am trying to update the value of a control on one panel when the value of another control on a different panel is changed.  The two panels are saved in two different .uir files, so there are two associated .h files generated by CVI.  The problem is that, inside the callback function for the control that is being modified (Ctrl_Id_A on Panel_A), when I call SetCtrlVal(Panel_B, Ctrl_Id_B, Value); 'Panel_B' and 'Ctrl_Id_B' (which have the same numeric values as Panel_A = 1 and Ctrl_Id_A = 2 in their respective .h files) are being interpreted as Panel_A and Ctrl_Id_A.  I never understood how CVI makes this distinction, eg. knowing which of PANEL_A = 1 and PANEL_B = 1 is being referred to, but didn't worry about it since I never needed cross-communication between panels until now.  Any help on how to implement this would be greatly appreciated.  Thanks!
    Solved!
    Go to Solution.

    This is a basic issue on which you can find tons of forum posts
    The online help for the function recitates:
    int SetCtrlVal (int panelHandle, int controlID, ...);
    Parameters
    Input
    Name
    Type
    Description
    panelHandle
    int
    Specifier for a particular panel that is currently in memory. You obtain this
    handle from LoadPanel, NewPanel, or DuplicatePanel.
    controlID
    int
    The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by NewCtrl or DuplicateCtrl.
    value
    New value of the control. The data type of value must match the data type of the control.
    That is, you must not use the panel constant name in the first parameter of SetCtrlVal, use the panel handle instead. The system guarantees that all panel handles are unique throughout the whole application whichever is the number of panels used in every moment.
    int SetCtrlVal (int panelHandle, int controlID, ...);
    Purpose
    Sets the value of a control to a value you specify.
    When you call SetCtrlVal on a list box or a ring control, SetCtrlVal
    sets the current list item to the first item that has the value you
    specify. To set the current list item through a zero-based index, use SetCtrlIndex.
    When you call SetCtrlVal on a text box, SetCtrlVal appends value to the contents of the text box and scrolls the text box to display value. Use ResetTextBox to replace the contents of the text box with value.
    Note   This function updates the displayed value immediately. Use SetCtrlAttribute with ATTR_CTRL_VAL to set the control value without immediately updating the displayed value. For this reason, SetCtrlAttribute with ATTR_CTRL_VAL is generally faster than SetCtrlVal. However, if the control in which you are setting the value is the active control in the panel, SetCtrlAttribute with ATTR_CTRL_VAL displays the value immediately.
    Note   This function is not valid for graph and strip chart controls.
    Parameters
    Input
    Name
    Type
    Description
    panelHandle
    int
    Specifier for a particular panel that is currently in memory. You obtain this
    handle from LoadPanel, NewPanel, or DuplicatePanel.
    controlID
    int
    The defined constant, located in the .uir header file, that you assigned to the control in the User Interface Editor, or the ID returned by NewCtrl or DuplicateCtrl.
    value
    New value of the control. The data type of value must match the data type of the control.
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • Spry Accordion Different Panel Heights

    I'm building a Spry Accordion Widget as a left nav menu with
    25 different panels. Some of my panels contain 10 different links
    and others contain only 1 single link. Therefore I would like to
    adjust the height of each panel individually according to the
    number of links they contain, so I don't end up with huge white
    spaces in panels that contain fewer links. My initial idea, in
    addition to the .AccordionPanelContent class was to add an "id" to
    each panel and control each panels height through CSS. But for some
    reason I haven't been successful that way. It looks like all panels
    tend to take the height of the first panel, regardless of their
    individual set heights. I wonder if I can resolve my problem
    uniquely with CSS, or I do I have to go and change something in the
    SpryAccordion.js file.
    Thanks.

    Hi Donald, I inserted <script type="text/javascript">
    var acc1 = new Spry.Widget.Accordion("Acc1", {
    useFixedPanelHeights: false });
    </script> into my code. It's almost there, but not
    quite. I can see that it is trying to re-ajust the panels' height,
    but for panels that have a larger content it tends to show the
    whole panel's content and then hides the half of it. Also for
    panels with fewer content it doesn't seem to have an effect at all.
    I don't know if I have to fix something in the CSS or place the
    Acc1 ID in a different location within my accordion HTML code.
    Thank you.
    Here's the URL I'm working on if you want to take a look.
    http://64.49.218.100/product_p/00-120-0ll.htm

  • One Components into 2 different panel problems

    Hi,
    I have one component, just call it A, and 2 different
    panels just call it PA and PB.
    I put A into PA and then I put A into PB,
    and display PA & PB into screen together.
    The problem is A is missing in PA but displayed
    into PB. I know this is behavior of AWT/Swing,
    but maybe some of you know how to solve
    this problem without creating two instances of A.
    Thank you in advance...

    You could make something like this:
    public class multicomponent
         Vector activecomponents=new Vector
         //all methods you intend to use on this component this way
         public method(somearg arg)
               for //all c in vector
                   c.method(arg);
          public void addto(Container co)
               comp=new yourcomponent();
               co.add(comp);
               activecomponents.add(comp);
    }You can enhance that by using weak references for the elements in the vector and you will have to think what to do for get methods.

  • CS6 Illustrator panel auto-collapses when expanding a different panel

    Hi,
    Can anyone explain how to stop a panel from auto-collapsing when expanding other group panels?
    For example: if I have 'layers' panel expanded and I click the 'color' panel, the 'layers' panel collapses to icon. (I have disabled 'Auto-Collapse Iconic Panels' but it still doesn't allow me to have 2 different panels expanded at the same time)
    Thanks

    Double click on the green square and the dialoge box will come up. If you double click on the red square it will just make the name of the layer editable in the pallette. I hope this helps.

  • Plz lookin "different panels which can place where ever we need"

    in one jsp how can we create different panels to display where each panel can collapse and can invisible by checking or unchecking it dynamically and each panel can be placed by the user where ever he need it that too the request should not go to the server when user changes the each panels state......
    (any doubts regarding this query are welcome)
    can any one help me out.

    The problem is that this forum does OR logic for its searches.  The most specific you can be is to use only the most unique word you have to use in a normal search.  Otherwise, use a regular web search and specify which site you want to see results
    for.   E.g. in BING or Google you would use the  site:technet.microsoft.com/forums  query term.
    This looks like a very simple case of 'bad engineering'.
    If I am going to have to go out to Google in order to perform a search to get s decent result for a Microsoft database, that really doesn't speak well of Microsoft.
    Sadly however, it really is the case that I get substantially better, more accurate results when using Google then when using Microsoft's TechNet directly - even when the answer is a TechNet forum or knowledgebase article.
    This said, it really doesn't address the question at hand in any way whatsoever.  If you direct your attention to the source question (should be recognizable as it is the big bold letters at the top listed under "Title") the answer being sought
    is regarding finding a way or a person who can "update the product list checkboxes on the left of the Technet search results" - as these, in fact, DO play a role in narrowing out unwanted search results, they are merely being terribly neglected.

  • Reload different panels

    Hello all,
    Like to reload different panels onto the same load panel.
    Code sample below on what I'am trying to achieve
    Each panel size would like to be 45% of window size.
    Have problems of reloading different panels to achieve the size and
    also when resizing the window
    Have 8 dukes to get rid of from:
    http://forum.java.sun.com/thread.jsp?forum=43&thread=431639
    Thanks
    Abraham Khalil
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.*;
    * Want to test reloading panels of very different text sizes inside it<br>
    * The goal is no matter want the label text size is, each label panel should only
    * show a maximum of 45% of the window size. <br>
    * <p>
    * Each button on the right will show a more uglier panel to load
    public class PanelChangeTest extends JFrame implements ActionListener {
       private static final int WIDTH = 640;
       private static final int HEIGHT = 400;
       private static final String BUTTON_PANEL_TEST1 = "Load Normal Panel";
       private static final String BUTTON_PANEL_TEST2 = "Load bit ugly Panel";
       private static final String BUTTON_PANEL_TEST3 = "Load very ugly Panel";
       private static final String[] BUTTON_COMMANDS = {
                                                         BUTTON_PANEL_TEST1,
                                                         BUTTON_PANEL_TEST2,
                                                         BUTTON_PANEL_TEST3
       private JPanel loadPanel = new JPanel();
       private PanelChange[] testPanels = null;
        * Model for each panel. <br>
        * Each panel contain email fields of from, to, subject and cc
       private class PanelFields {
          private String from = null;
          private String to = null;
          private String subject = null;
          private String cc = null;
          public PanelFields(String from, String to, String subject, String cc) {
             this.from = from;
             this.to = to;
             this.subject = subject;
             this.cc = cc;
          public String getFrom() {
             return from;
          public String getTo() {
             return to;
          public String getSubject() {
             return subject;
          public String getCC() {
             return cc;
       } // End PanelFields class
        * View panel class <br>
        * Each panel change class will contain four panels and they are from, to, cc and subject panel. <br>
        * Each of the from, to, cc and subject panel contain two labels, one for description and other for
        * its text value.
        * Want to set each panel size to 45% of window size so it looks even, and if label text is too long
        * to fit in 45% view, it should truncate it..
       private class PanelChange extends JPanel {
          private static final float PERCENT = 1 / 100.0f;
          private static final float EACH_PANEL_SIZE = 45 * PERCENT;
          private JPanel getPanel(String labelForText, String text) {
             JLabel labelLeft = new JLabel(labelForText, JLabel.LEFT);
             JLabel labelRight = new JLabel(text, JLabel.LEFT);
             setBold(labelLeft, true);
             JPanel panel = new JPanel();
             panel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
             panel.add(labelLeft);
             panel.add(labelRight);
             panel.setBorder(BorderFactory.createLineBorder(Color.blue));
             return panel;
          public void recalculate(Dimension parentSize) {
             Dimension eachPanelSize = new Dimension((int) (parentSize.width * EACH_PANEL_SIZE), 12);
             System.out.println("Parent size = (" + parentSize.width + ", " + parentSize.height + ")\n" +
                                "Each panel size is recalculated as (" + eachPanelSize.width + ", " + eachPanelSize.height + ")\n");
             Component[] components = getComponents();       
             for (int eachPanel = 0 ; eachPanel < components.length ; eachPanel++) {
                JComponent panel = (JComponent) components[eachPanel];
                panel.setMaximumSize(eachPanelSize);
                panel.setMinimumSize(eachPanelSize);
                panel.setSize(eachPanelSize);
          public PanelChange(PanelFields panelFields) {
             JPanel fromPanel = getPanel("From: ", panelFields.getFrom());
             JPanel toPanel = getPanel("To: ", panelFields.getTo());        
             JPanel subjectPanel = getPanel("Subject: ", panelFields.getSubject());
             JPanel ccPanel = getPanel("CC: ", panelFields.getCC());
             setLayout(new BorderLayout());
             JPanel panel = new JPanel();
             // Test with panel of GridLayout instead of GridBagLayout to see the difference...     
             panel.setLayout(new GridLayout(2, 2, 5, 5));
             panel.add(fromPanel);
             panel.add(toPanel);
             panel.add(subjectPanel);
             panel.add(ccPanel);
             panel.setLayout(new GridBagLayout());
             constrain(panel, fromPanel,
                       GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST,
                       0, 0, 1, 1, 1.0, 0.0);
             constrain(panel, toPanel,
                       GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST,
                       1, 0, 1, 1, 1.0, 0.0);
             constrain(panel, subjectPanel,
                       GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST,
                       0, 1, 1, 1, 1.0, 0.0);
             constrain(panel, ccPanel,
                       GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST,
                       1, 1, 1, 1, 1.0, 0.0);
             add(panel, BorderLayout.CENTER);
          private int getFontStyle(Component component, boolean makeBold) {
             int style = 0;
             if (component != null) {
                Font f = component.getFont();
                if (f != null) {
                   if (f.isPlain()) style = style | Font.PLAIN;
                   if (f.isItalic()) style = style | Font.ITALIC;
                   if (makeBold) style = style | Font.BOLD;
             return style;
          private void setBold(Component component, boolean makeBold) {
             int style = getFontStyle(component, makeBold);
             Font styleFont = component.getFont().deriveFont(style);
             component.setFont(styleFont);
       } // End PanelChange class
       public void constrain( Container container, Component component, 
                              int fill, int anchor,
                              int gx, int gy, int gw, int gh, double wx, double wy ) {
          GridBagConstraints c = new GridBagConstraints();
          c.fill = fill;
          c.anchor = anchor;
          c.gridx = gx;
          c.gridy = gy;
          c.gridwidth = gw;
          c.gridheight = gh;
          c.weightx = wx;
          c.weighty = wy;
          ( (GridBagLayout) container.getLayout() ).setConstraints( component, c );
          container.add( component );
       public void constrain( Container container, Component component, 
                              int fill, int anchor,
                              int gx, int gy, int gw, int gh,
                              double wx, double wy, Insets inset ) {
          GridBagConstraints c = new GridBagConstraints();
          c.fill = fill;
          c.anchor = anchor;
          c.gridx = gx;
          c.gridy = gy;
          c.gridwidth = gw;
          c.gridheight = gh;
          c.weightx = wx;
          c.weighty = wy;
          c.insets = inset;
          ( (GridBagLayout) container.getLayout() ).setConstraints( component, c );
          container.add( component );
       private void initPanels() {
          PanelFields okPanel = new PanelFields("Simple from...",
                                                "[email protected]; [email protected]",
                                                "Simple subject...",
                                                "[email protected]; [email protected]");
          PanelFields bitUglyPanel = new PanelFields("A bit ugly from................",
                                                     "[email protected]; [email protected]; [email protected]; [email protected]",
                                                     "A bit ungle subject.....................",
                                                     "[email protected]; [email protected]; [email protected]; [email protected]");
          PanelFields veryUglyPanel = new PanelFields("A very very very very very " +
                                                      "very very ugly from................",
                                                      "[email protected]; [email protected]; [email protected]; [email protected], " +
                                                      "[email protected]; [email protected]; [email protected]; [email protected]",
                                                      "A very very very very very very " +
                                                      "very ungle subject.....................",
                                                      "[email protected]; [email protected]; [email protected]; [email protected]; " +
                                                      "[email protected]; [email protected]; [email protected]; [email protected]");
          testPanels = new PanelChange[] {
                                            new PanelChange(okPanel),
                                            new PanelChange(bitUglyPanel),
                                            new PanelChange(veryUglyPanel)
          Container container = getContentPane();
          container.setLayout(new BorderLayout());
          JPanel buttonPanel = new JPanel();
          buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
          JButton button1 = new JButton(BUTTON_PANEL_TEST1);
          button1.setActionCommand(BUTTON_PANEL_TEST1);
          button1.addActionListener(this);
          JButton button2 = new JButton(BUTTON_PANEL_TEST2);
          button2.setActionCommand(BUTTON_PANEL_TEST2);
          button2.addActionListener(this);
          JButton button3 = new JButton(BUTTON_PANEL_TEST3);
          button3.setActionCommand(BUTTON_PANEL_TEST3);
          button3.addActionListener(this);
          buttonPanel.add(button1);
          buttonPanel.add(Box.createHorizontalStrut(5));
          buttonPanel.add(button2);
          buttonPanel.add(Box.createHorizontalStrut(5));
          buttonPanel.add(button3);
          JPanel mainPanel = new JPanel();
          mainPanel.setLayout(new GridBagLayout());
          constrain(mainPanel, loadPanel,
                    GridBagConstraints.BOTH, GridBagConstraints.WEST,
                    0, 0, 1, 1, 1.0, 1.0, new Insets(5, 5, 5, 5));
          constrain(mainPanel, buttonPanel,
                    GridBagConstraints.NONE, GridBagConstraints.CENTER,
                    0, 1, 1, 1, 0.0, 0.0, new Insets(5, 5, 5, 5));
          container.add(mainPanel);
       private void setupLoadPanel(PanelChange panelToLoad) {
          loadPanel.removeAll();
          panelToLoad.recalculate(getSize());
          loadPanel.add(panelToLoad);
          loadPanel.revalidate();     
       public void actionPerformed(ActionEvent e) {
          String actionCommand = e.getActionCommand();
          for (int i = 0 ; i < BUTTON_COMMANDS.length ; i++) {
             if (actionCommand.equals(BUTTON_COMMANDS)) {
    setupLoadPanel(testPanels[i]);
    break;
    public PanelChangeTest() {
    super("Panel change test...");
    Dimension size = new Dimension(WIDTH, HEIGHT);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screenSize.width - size.width) / 2;
    int y = (screenSize.height - size.height) / 2;
    setBounds(x, y, WIDTH, HEIGHT);
    addWindowListener(new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
    System.exit(0);
    FontUIResource standardFont = new FontUIResource("dialogPlain11", Font.PLAIN, 11);
    UIManager.put("Label.font", standardFont);
    UIManager.put("Button.font", standardFont);
    initPanels();
    public static void main(String args[]) {
    new PanelChangeTest().setVisible(true);

    Please use the following code below:
    Somehow it doesn't show the text if it can't fit inside the panel.
    When resize to full screen, it shows the text??
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.plaf.*;
    * Want to test reloading panels of very different text sizes inside it<br>
    * The goal is no matter want the label text size is, each label panel should only
    * show a maximum of 45% of the window size. <br>
    * <p>
    * Each button on the right will show a more uglier panel to load
    public class PanelChangeTest extends JFrame implements ActionListener {
       private static final int WIDTH = 640;
       private static final int HEIGHT = 400;
       private static final String BUTTON_PANEL_TEST1 = "Load Normal Panel";
       private static final String BUTTON_PANEL_TEST2 = "Load bit ugly Panel";
       private static final String BUTTON_PANEL_TEST3 = "Load very ugly Panel";
       private static final String[] BUTTON_COMMANDS = {
                                                         BUTTON_PANEL_TEST1,
                                                         BUTTON_PANEL_TEST2,
                                                         BUTTON_PANEL_TEST3
       private JPanel loadPanel = new JPanel();
       private PanelChange[] testPanels = null;
        * Model for each panel. <br>
        * Each panel contain email fields of from, to, subject and cc
       private class PanelFields {
          private String from = null;
          private String to = null;
          private String subject = null;
          private String cc = null;
          public PanelFields(String from, String to, String subject, String cc) {
             this.from = from;
             this.to = to;
             this.subject = subject;
             this.cc = cc;
          public String getFrom() {
             return from;
          public String getTo() {
             return to;
          public String getSubject() {
             return subject;
          public String getCC() {
             return cc;
       } // End PanelFields class
        * View panel class <br>
        * Each panel change class will contain four panels and they are from, to, cc and subject panel. <br>
        * Each of the from, to, cc and subject panel contain two labels, one for description and other for
        * its text value.
        * Want to set each panel size to 45% of window size so it looks even, and if label text is too long
        * to fit in 45% view, it should truncate it..
       private class PanelChange extends JPanel {
          private static final float PERCENT = 1 / 100.0f;
          private static final float EACH_PANEL_SIZE = 45 * PERCENT;
          public PanelChange(PanelFields panelFields) {
             JPanel fromPanel = getPanel("From: ", panelFields.getFrom());
             JPanel toPanel = getPanel("To: ", panelFields.getTo());        
             JPanel subjectPanel = getPanel("Subject: ", panelFields.getSubject());
             JPanel ccPanel = getPanel("CC: ", panelFields.getCC());
             setLayout(new BorderLayout());
             JPanel panel = new JPanel();
             // Test with panel of GridLayout instead of GridBagLayout to see the difference...     
             panel.setLayout(new GridLayout(2, 2, 5, 5));
             panel.add(fromPanel);
             panel.add(toPanel);
             panel.add(subjectPanel);
             panel.add(ccPanel);
             panel.setLayout(new GridBagLayout());
             constrain(panel, fromPanel,
                       GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST,
                       0, 0, 1, 1, 1.0, 0.0);
             constrain(panel, toPanel,
                       GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST,
                       1, 0, 1, 1, 1.0, 0.0);
             constrain(panel, subjectPanel,
                       GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST,
                       0, 1, 1, 1, 1.0, 0.0);
             constrain(panel, ccPanel,
                       GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST,
                       1, 1, 1, 1, 1.0, 0.0);
             add(panel, BorderLayout.CENTER);
          public void recalculate(Dimension parentSize) {
             Dimension eachPanelSize = new Dimension((int) (parentSize.width * EACH_PANEL_SIZE), 20);
             System.out.println("Parent size = (" + parentSize.width + ", " + parentSize.height + ")\n" +
                                "Each panel size is recalculated as (" + eachPanelSize.width + ", " + eachPanelSize.height + ")\n");
             JPanel mainPanel = (JPanel) getComponent(0);
             Component[] components = mainPanel.getComponents();
             for (int eachPanel = 0 ; eachPanel < components.length ; eachPanel++) {
                JComponent panel = (JComponent) components[eachPanel];
                panel.setMaximumSize(eachPanelSize);
                panel.setMinimumSize(eachPanelSize);
                panel.setPreferredSize(eachPanelSize);
          private JPanel getPanel(String labelForText, String text) {
             JLabel labelLeft = new JLabel(labelForText, JLabel.LEFT);
             JLabel labelRight = new JLabel(text, JLabel.LEFT);
             setBold(labelLeft, true);
             JPanel panel = new JPanel();
             panel.setLayout(new FlowLayout(FlowLayout.LEFT, 5, 0));
             panel.add(labelLeft);
             panel.add(labelRight);
             panel.setBorder(BorderFactory.createLineBorder(Color.blue));
             return panel;
          private int getFontStyle(Component component, boolean makeBold) {
             int style = 0;
             if (component != null) {
                Font f = component.getFont();
                if (f != null) {
                   if (f.isPlain()) style = style | Font.PLAIN;
                   if (f.isItalic()) style = style | Font.ITALIC;
                   if (makeBold) style = style | Font.BOLD;
             return style;
          private void setBold(Component component, boolean makeBold) {
             int style = getFontStyle(component, makeBold);
             Font styleFont = component.getFont().deriveFont(style);
             component.setFont(styleFont);
       } // End PanelChange class
       public void constrain( Container container, Component component, 
                              int fill, int anchor,
                              int gx, int gy, int gw, int gh, double wx, double wy ) {
          GridBagConstraints c = new GridBagConstraints();
          c.fill = fill;
          c.anchor = anchor;
          c.gridx = gx;
          c.gridy = gy;
          c.gridwidth = gw;
          c.gridheight = gh;
          c.weightx = wx;
          c.weighty = wy;
          ( (GridBagLayout) container.getLayout() ).setConstraints( component, c );
          container.add( component );
       public void constrain( Container container, Component component, 
                              int fill, int anchor,
                              int gx, int gy, int gw, int gh,
                              double wx, double wy, Insets inset ) {
          GridBagConstraints c = new GridBagConstraints();
          c.fill = fill;
          c.anchor = anchor;
          c.gridx = gx;
          c.gridy = gy;
          c.gridwidth = gw;
          c.gridheight = gh;
          c.weightx = wx;
          c.weighty = wy;
          c.insets = inset;
          ( (GridBagLayout) container.getLayout() ).setConstraints( component, c );
          container.add( component );
       private void initPanels() {
          PanelFields okPanel = new PanelFields("Simple from...",
                                                "[email protected]; [email protected]",
                                                "Simple subject...",
                                                "[email protected]; [email protected]");
          PanelFields bitUglyPanel = new PanelFields("A bit ugly from................",
                                                     "[email protected]; [email protected]; [email protected]; [email protected]",
                                                     "A bit ungle subject.....................",
                                                     "[email protected]; [email protected]; [email protected]; [email protected]");
          PanelFields veryUglyPanel = new PanelFields("A very very very very very " +
                                                      "very very ugly from................",
                                                      "[email protected]; [email protected]; [email protected]; [email protected], " +
                                                      "[email protected]; [email protected]; [email protected]; [email protected]",
                                                      "A very very very very very very " +
                                                      "very ungle subject.....................",
                                                      "[email protected]; [email protected]; [email protected]; [email protected]; " +
                                                      "[email protected]; [email protected]; [email protected]; [email protected]");
          testPanels = new PanelChange[] {
                                            new PanelChange(okPanel),
                                            new PanelChange(bitUglyPanel),
                                            new PanelChange(veryUglyPanel)
          Container container = getContentPane();
          container.setLayout(new BorderLayout());
          JPanel buttonPanel = new JPanel();
          buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.X_AXIS));
          JButton button1 = new JButton(BUTTON_PANEL_TEST1);
          button1.setActionCommand(BUTTON_PANEL_TEST1);
          button1.addActionListener(this);
          JButton button2 = new JButton(BUTTON_PANEL_TEST2);
          button2.setActionCommand(BUTTON_PANEL_TEST2);
          button2.addActionListener(this);
          JButton button3 = new JButton(BUTTON_PANEL_TEST3);
          button3.setActionCommand(BUTTON_PANEL_TEST3);
          button3.addActionListener(this);
          buttonPanel.add(button1);
          buttonPanel.add(Box.createHorizontalStrut(5));
          buttonPanel.add(button2);
          buttonPanel.add(Box.createHorizontalStrut(5));
          buttonPanel.add(button3);
          JPanel mainPanel = new JPanel();
          mainPanel.setLayout(new GridBagLayout());
          constrain(mainPanel, loadPanel,
                    GridBagConstraints.BOTH, GridBagConstraints.WEST,
                    0, 0, 1, 1, 1.0, 1.0, new Insets(5, 5, 5, 5));
          constrain(mainPanel, buttonPanel,
                    GridBagConstraints.NONE, GridBagConstraints.CENTER,
                    0, 1, 1, 1, 0.0, 0.0, new Insets(5, 5, 5, 5));
          container.add(mainPanel);
       private void setupLoadPanel(PanelChange panelToLoad) {
          loadPanel.removeAll();
          Dimension parentSize = getSize();
          panelToLoad.recalculate(parentSize);     
          loadPanel.add(panelToLoad);
          loadPanel.revalidate();
          loadPanel.repaint(); 
       public void actionPerformed(ActionEvent e) {
          String actionCommand = e.getActionCommand();
          for (int i = 0 ; i < BUTTON_COMMANDS.length ; i++) {
             if (actionCommand.equals(BUTTON_COMMANDS)) {
    setupLoadPanel(testPanels[i]);
    break;
    public PanelChangeTest() {
    super("Panel change test...");
    Dimension size = new Dimension(WIDTH, HEIGHT);
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    int x = (screenSize.width - size.width) / 2;
    int y = (screenSize.height - size.height) / 2;
    setBounds(x, y, WIDTH, HEIGHT);
    addWindowListener(new WindowAdapter() {
    public void windowClosing( WindowEvent e ) {
    System.exit(0);
    FontUIResource standardFont = new FontUIResource("dialogPlain11", Font.PLAIN, 11);
    UIManager.put("Label.font", standardFont);
    UIManager.put("Button.font", standardFont);
    initPanels();
    public static void main(String args[]) {
    new PanelChangeTest().setVisible(true);

  • Event problem on two different panels

    I have an application which has a main JFrame.
    It has two panels north and south
    The one in the south has buttons that listens for events.
    The events are action events. The events on this panel works if I don't include the events for my other panel i.e
    PersonalDataPanel as described below.
    The noth panel uses card layout. Inside this layout has two panels.
    One panel is called PersonalDataPanel.
    Inside PersonalDataPanel are components.
    One is a group of radio buttons that listens for events
    the events are again action events and if one is choosen from the group it is written to a file.
    I have testdriver for this which works.
    My porblem occurs when I include the code for PersonalDataPanel to listen for events and the main JFrame also to listen for events.
    How should I handle this dilemma??

    Why does the JFrame also have to listen for events? If its only button events surely it doesn't need to be involved and could be causing the problem.
    Have you tried using different event handlers for the different panels...?

  • Open a panel/HTML5 window from a different panel

    Is there a way to open a panel from a different panel?
    That is the only way I have found to create an interactive UI.
    I tried this way http://www.davidebarranca.com/2012/10/scriptui-window-in-photoshop-palette-vs-dialog/
    But couldn't really make it work with editable text fields.
    Do anyone got an idea how to make a dialogbox or open a panel from a different one?

    Hello,
    The blog post you're referring to is about scriptUI, which I don't think has anything to do with HTML5 extensions.
    You might find answers here : Re: HTML5 Opening a Modal Dialog from Extension?

  • How can I access data in different panels?

    Hi,
    I'm a beginner in Swing and have a simple(?) question. Unfortunately I didn't find the answer by oneself so I hope you can help me.
    I have three classes. In the GUI.java class I build the JFrame and it's components. All components are added to the frame via panels that a separate classes.
    My problem is: how can I acces the values in PanelB when I call the actionPerfomed in PanelA? Or is that always a bad design? How can I make it better?
    GUI.java
    JFrame frame = new JFrame();
    PanelA panelA = new PanelA();
    PanelB panelB = new PanelB();
    frame.getContentPane().add(panelA);
    frame.getContentPane().add(panelB);PanelA.java
    private class ButtonCalculateAction implements ActionListener {
         public void actionPerformed(ActionEvent e){
              //calculate with valuesX and valuesY from Panel B
    JButton buttonCalculate;
    ...PanelB.java
    JList valuesX;
    JList valuesY;
    JButton addValueX;
    ...

    Here is the code for a Short, Self Contained, Correct (Compilable), Example
    GUI.java
    import java.awt.FlowLayout;
    import javax.swing.JFrame;
    public class GUI {
         public GUI(){
              JFrame frame = new JFrame();
              PanelA panelA = new PanelA();
              PanelB panelB = new PanelB();
              frame.getContentPane().setLayout(new FlowLayout());
              frame.getContentPane().add(panelA);
              frame.getContentPane().add(panelB);
              frame.setSize(400, 200);
              frame.setVisible(true);
         public static void main(String[] args) {
              GUI gui = new GUI();
    }PanelA.javaimport java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    public class PanelA extends JPanel {
         public PanelA(){
              this.setLayout(new FlowLayout());
              this.buttonCalculate = new JButton("Calculate");
              this.buttonCalculate.addActionListener(new ButtonCalculateAction());
              this.add(buttonCalculate);
              this.result = new JTextField("...");
              this.add(result);
         private class ButtonCalculateAction implements ActionListener {
              public void actionPerformed(ActionEvent e){
                   //calculate with values from PanelB. How??
                   //result = ?
         private JButton buttonCalculate;
         private JTextField result;
    }PanelB.java
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.*;
    public class PanelB extends JPanel {
         public PanelB(){
              this.addValueX = new JButton("Add X");
              this.addValueX.addActionListener(new ButtonAddAction());
              this.valuesXList = new DefaultListModel();
              this.valuesX = new JList();
              this.valuesX.setModel(valuesXList);
              this.add(addValueX);
              this.add(valuesX);
         private class ButtonAddAction implements ActionListener {
              public void actionPerformed(ActionEvent e){
                   valuesXList.addElement(47);
         private JList valuesX;
         private DefaultListModel valuesXList;
         private JButton addValueX;
    }

Maybe you are looking for