IMAGEICON help

anybody know how to set image icon as a background to put inside a panel..ANybody could give help

do not know but maybe this might help yuo can overide the panels paintComponent( Graphics g) method allowing to draw an image every time the componenet is painted. It could serve as a background image? Done like so. Remember to keep the super.paintComponent(g) its important.
public void paintComponent (Graphics g)
super.paintComponent(g);
g.drawImage(img,0,0,this);

Similar Messages

  • ImageIcon -- help please!!

    Hi,
    I have a JTree that uses a cell renderer, and the cell renderer reads an Image.gif .
    However, when I run the appletm I get a this:
    java.security.AccessControlException: access denied (java.io.FilePermission menu_tee_minus.gif read)
    Please help!
    Sangita

    Sangita --
    It sounds like the image file is just being opened
    as a regular file -- maybe something in your
    directory?
    Applets are not normally allowed to open files or
    run programs on the local machine (to prevent damage
    to the local machine by a malicious applet).
    One thing you can do is put the image file in the same
    directory as the applet class file (or a subdirectory
    of that directory) and use a URL to refer to it.
    There's an example here:
    java.sun.com/docs/books/tutorial/uiswing/components/applet.html#images
    And more info here:
    java.sun.com/docs/books/tutorial/uiswing/misc/icon.html
    especially the section on "Specifying the Image Source"
    and the bit about jar files just above.
    With the image file in the same directory as your
    applet class file, you might do something like:
    URL baseURL = getCodeBase();
    ImageIcon img = new ImageIcon(getURL(baseURL, "Image.gif"));
    Another thing you can do is supply the image and the
    applet together in a jar file -- then both get read
    from the server in the same operation. Use the same code as above in the applet, but in the applet tag in
    the web page, include an "archive" option that points
    to the jar file. E.g.
    <applet code="YourApplet.class"
    archive="YourAppletBundle.jar">
    plus whatever other options you need. The archive
    can be a URL or a path instead of just a file name.
    There's more on the applet tag at:
    www.w3.org/TR/REC-html40/struct/objects.html
    They say the applet tag is obsolete, and we should use
    "object" instead ;-).
    -- Pat

  • Imageicon help need, please!!!!

    Hi,
    I want to make a simple java Slide show program. I have 24 images and I was wondering how (EASILY or Automatically) to make an imageIcon object for each one, insteastead of declaring individual objects one by one. Here is how I know it, but I don't like it.
    ImageIcon slide0 = new ImageIcon("images/slide0.jpg");
    Image image0 = slide0.getImage();
    ImageIcon slide1 = new ImageIcon("images/slide1.jpg");
    Image image1 = slide1.getImage();
    ImageIcon slide2 = new ImageIcon("images/slide2.jpg");
    Image image2 = slide2.getImage();
    ImageIcon slide24 = new ImageIcon("images/slide24.jpg");
    Image image24 = slide24.getImage();So, how do i do this (maybe an array of ImageIcon), but how do I deal with the file names?
    Thank for any helpful input.
    Peace.

    I see one of two ways to do this fairly easily. If the File names are all different then you could have an array of Strings that represents the file name. If they all have a common path, then perhaps you could use a String constant that represents the path and just concatenate the two in your loop.
    Your current situation however lends itself well to simply having a String constant for your path and for your partial file name (without the extension) and then just add the numeric part to the file name and the extension by String concatenation within the loop. You should be able to figure this out, I'll bet. Good luck.

  • Help on 2 error messages / code request please

    Why am I getting this error message about an abstract when I'm not declearing one.
    error messages I'm getting below -----------
    .\LkList.java:26: Method LinkedList getList() requires a method body. Otherwise declare it as abstract.
    public LinkedList getList();
    DCalc.java:10: class LkList is an abstract class. It can't be instantiated.
    LkList Expression =new LkList(exp);
    code below ------------------------------
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.util.*;
    class JCal extends JFrame implements KeyListener
         JLabel answer, expression;
         JButton b1, b2, b4, b5, b6, b7, b8, b9, b10, b11, b12, b13, b14, b15, b16, b17, b18, b19,
              b20, b21, b22, b23, b24, b25, b26, b27;
         JMenuBar menuBar;
         JMenu menu;
         JMenuItem menuItem, menuItem1;
         LkList equation;
         String exp="";
         String ans="";
         double memory=0;
         public JCal()
         {     super("Nicks Swing Calculator");
    //------------------------- labels ---------------------------------------------
              answer = new JLabel(" 0 "); //Answer Lable
              answer.setBounds (20, 20, 220, 30);
              answer.setBorder (BorderFactory.createLoweredBevelBorder());
              answer.setBackground (Color.pink);
    answer.setHorizontalAlignment (SwingConstants.RIGHT);
              expression = new JLabel(" 0 "); // Expression Lable
              expression.setBounds (20, 55, 220, 30);
              expression.setBorder (BorderFactory.createLoweredBevelBorder());
              expression.setBackground (Color.white);
    //------------------------- menu -------------------------------------------------
              menuBar = new JMenuBar();
              setJMenuBar (menuBar);
              menu = new JMenu ("File");
              menuItem = new JMenuItem (" Help", new ImageIcon("help.gif"));
              menuItem1 = new JMenuItem (" Splash Page");
              menuItem.addActionListener(new ActionListener() // Help menu
              {     public void actionPerformed(ActionEvent e)
                   {     new JHelp();
    menuItem1.addActionListener(new ActionListener() // Splash Page
              {     public void actionPerformed(ActionEvent e)
                   {     new JSplash();
    //------------------------ buttons ------------------------------------------------
              JButton b1 = new JButton (new ImageIcon ("mc.gif")); // MR button
              b1.setBounds(20, 100, 55, 50);
              JButton b2 = new JButton (new ImageIcon ("mr.gif")); // MC button
              b2.setBounds(75, 100, 55, 50);
    JButton b3 = new JButton (new ImageIcon ("ms.gif")); // MS button
              b3.setBounds(130, 100, 55, 50);
    JButton b4 = new JButton (new ImageIcon ("mplus.gif")); // M+ button
              b4.setBounds(185, 100, 55, 50);
              JButton b5 = new JButton (new ImageIcon ("seven.gif")); // 7 button
              b5.setBounds(20, 170, 55, 50);
              JButton b6 = new JButton (new ImageIcon ("eight.gif")); // 8 button
              b6.setBounds(75, 170, 55, 50);
              JButton b7 = new JButton (new ImageIcon ("nine.gif")); // 9 button
              b7.setBounds(130, 170, 55, 50);
    JButton b8 = new JButton (new ImageIcon ("div.gif")); // divide button
              b8.setBounds(185, 170, 55, 50);
              JButton b9 = new JButton (new ImageIcon ("four.gif")); // 4 button
              b9.setBounds(20, 220, 55, 50);
              JButton b10 = new JButton (new ImageIcon ("five.gif")); // 5 button
              b10.setBounds(75, 220, 55, 50);
              JButton b11 = new JButton (new ImageIcon ("six.gif")); // 6 button
              b11.setBounds(130, 220, 55, 50);
              JButton b12 = new JButton (new ImageIcon ("times.gif")); // times button
              b12.setBounds(185, 220, 55, 50);
    JButton b13 = new JButton (new ImageIcon ("one.gif")); // 1 button
              b13.setBounds(20, 270, 55, 50);
              JButton b14 = new JButton (new ImageIcon ("two.gif")); // 2 button
              b14.setBounds(75, 270, 55, 50);
              JButton b15 = new JButton (new ImageIcon ("three.gif")); // 3 button
              b15.setBounds(130, 270, 55, 50);
              JButton b16 = new JButton (new ImageIcon ("minus.gif")); // minus button
              b16.setBounds(185, 270, 55, 50);
              JButton b17 = new JButton (new ImageIcon ("zero.gif")); // 0 button
              b17.setBounds(20, 320, 55, 50);
              JButton b18 = new JButton (new ImageIcon ("neg.gif")); // negitive button
              b18.setBounds(75, 320, 55, 50);
              JButton b19 = new JButton (new ImageIcon ("dot.gif")); // decimal button
              b19.setBounds(130, 320, 55, 50);
              JButton b20 = new JButton (new ImageIcon ("add.gif")); // addition button
              b20.setBounds(185, 320, 55, 50);
              JButton b21 = new JButton (new ImageIcon ("left.gif")); // left bracket button
              b21.setBounds(20, 375, 110, 35);
              JButton b22 = new JButton (new ImageIcon ("right.gif")); // right bracket button
              b22.setBounds(130, 375, 110, 35);
              JButton b23 = new JButton (new ImageIcon ("equals.gif")); // equals button
              b23.setBounds(20, 415, 220, 35);
    JButton b24 = new JButton (new ImageIcon ("clear.gif")); // clear button
              b24.setBounds(20, 460, 55, 50);
              JButton b25 = new JButton (new ImageIcon ("ce.gif")); // ce button
              b25.setBounds(75, 460, 55, 50);
              JButton b26 = new JButton (new ImageIcon ("sqrt.gif")); // sqrt button
              b26.setBounds(130, 460, 55, 50);
              JButton b27 = new JButton (new ImageIcon ("percent.gif")); // % button
              b27.setBounds(185, 460, 55, 50);
              //------------------- adding everything on the pane -------------------
              Container contentPane = getContentPane();
              contentPane.setLayout(null);
              // the default layout is BorderLayout
              contentPane.add(b1); // adds buttons
              contentPane.add(b2);
              contentPane.add(b3);
              contentPane.add(b4);
              contentPane.add(b5);
              contentPane.add(b6);
              contentPane.add(b7);
              contentPane.add(b8);
              contentPane.add(b9);
              contentPane.add(b10);
              contentPane.add(b11);
              contentPane.add(b12);
              contentPane.add(b13);
              contentPane.add(b14);
              contentPane.add(b15);
              contentPane.add(b16);
              contentPane.add(b17);
              contentPane.add(b18);
              contentPane.add(b19);
              contentPane.add(b20);
              contentPane.add(b21);
              contentPane.add(b22);
              contentPane.add(b23);
              contentPane.add(b24);
              contentPane.add(b25);
              contentPane.add(b26);
              contentPane.add(b27);
              contentPane.add(answer); // adds answer label
              contentPane.add(expression); // adds expression lable
              menuBar.add(menu); // adds menu
              menu.add(menuItem); // adds menu item "Help"
              menu.add(menuItem1); // adds menu item "Splash Page"
    //------------ button functions ---------------------------------------
              b1.addActionListener(new ActionListener()          // MR
              {     public void actionPerformed(ActionEvent e)
                   {     String TempMemory="";
                        answer.setText(TempMemory.valueOf(memory)); }});
              b2.addActionListener(new ActionListener()          //Mc
              {     public void actionPerformed(ActionEvent e)
                   {     memory=0; }});
              b3.addActionListener(new ActionListener()          //M-
              {     public void actionPerformed(ActionEvent e)
                   {     Double DblTemp=new Double(answer.getText());
                        double dblTemp=DblTemp.doubleValue();
                        memory=memory-dblTemp; }});
              b4.addActionListener(new ActionListener()          //M+
              {     public void actionPerformed(ActionEvent e)
                   {     Double DblTemp=new Double(answer.getText());
                        double dblTemp=DblTemp.doubleValue();
                        memory=memory+dblTemp; }});
    b5.addActionListener(new ActionListener() // Seven
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"7";
                        expression.setText(exp); }});
              b5.addKeyListener(this);
              b6.addActionListener(new ActionListener() // Eight
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"8";
                        expression.setText(exp); }});
              b6.addKeyListener(this);
              b7.addActionListener(new ActionListener() // Nine
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"9";
                        expression.setText(exp); }});
              b7.addKeyListener(this);
              b8.addActionListener(new ActionListener()          // Divide
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"/";
                        expression.setText(exp); }});
              b8.addKeyListener(this);
              b9.addActionListener(new ActionListener() // Four
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"4";
                        expression.setText(exp); }});
              b9.addKeyListener(this);
              b10.addActionListener(new ActionListener() // Five
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"5";
                        expression.setText(exp); }});
              b10.addKeyListener(this);
              b11.addActionListener(new ActionListener() // Six
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"6";
                        expression.setText(exp); }});
              b11.addKeyListener(this);
              b12.addActionListener(new ActionListener()     // Times
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"*";
                        expression.setText(exp); }});
              b12.addKeyListener(this);
              b13.addActionListener(new ActionListener() // One
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"1";
                        expression.setText(exp); }});
              b13.addKeyListener(this);
              b14.addActionListener(new ActionListener() // Two
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"2";
                        expression.setText(exp); }});
              b14.addKeyListener(this);
              b15.addActionListener(new ActionListener() // Three
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"3";
                        expression.setText(exp); }});
              b15.addKeyListener(this);
              b16.addActionListener(new ActionListener()          // Minus
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"-";
                        expression.setText(exp); }});
              b16.addKeyListener(this);
              b17.addActionListener(new ActionListener() // Zero
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"0";
                        expression.setText(exp); }});
              b17.addKeyListener(this);
              b18.addActionListener(new ActionListener() // negative
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"-";
                        expression.setText(exp); }});
              b18.addKeyListener(this);
              b19.addActionListener(new ActionListener()          // Decimal
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+".";
                        expression.setText(exp); }});
              b19.addKeyListener(this);
              b20.addActionListener(new ActionListener()          // Addition
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"+";
                        expression.setText(exp); }});
              b20.addKeyListener(this);
              b21.addActionListener(new ActionListener()     // Left Bracket
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+"(";
                        expression.setText(exp); }});
              b21.addKeyListener(this);
              b22.addActionListener(new ActionListener()          // Right Bracket
              {     public void actionPerformed(ActionEvent e)
                   {     exp=exp+")";
                        expression.setText(exp); }});
              b22.addKeyListener(this);
              b23.addActionListener(new ActionListener() // Equals
              {     public void actionPerformed(ActionEvent e)
                   {     LkList equation = new LkList();
                        equation.ProcessExpress();
                        ans=equation.getAns();
                        answer.setText(ans);
                        exp="";
                        ans="";     }});
              b23.addKeyListener(this);
              b24.addActionListener(new ActionListener()          // Clear
              {     public void actionPerformed(ActionEvent e)
                   {     exp="";
                        ans="";
                        expression.setText(exp);
                        answer.setText(ans); }});
              b25.addActionListener(new ActionListener()          // Clear Entry
              {     public void actionPerformed(ActionEvent e)
                   {     exp="";
                        ans="";
                        expression.setText(exp);
                        answer.setText(ans); }});
              addWindowListener( new WindowAdapter()
                        {     public void windowClosing(WindowEvent e)
                             {     System.exit(0);
              this.setBounds(10, 10, 270, 600);
              this.show();
         public static void main(String[] args)
         {     new JCal();
    public void keyReleased(KeyEvent evt){}
         public void keyTyped(KeyEvent evt) {}
         public void keyPressed(KeyEvent evt)
         {     char x=evt.getKeyChar();
              switch(x)
              {     case '0': exp=exp+"0";
                        expression.setText(exp);
                        break;
                   case '1': exp=exp+"1";
                        expression.setText(exp);
                        break;
                   case '2': exp=exp+"2";
                        expression.setText(exp);
                        break;
                   case '3': exp=exp+"3";
                        expression.setText(exp);
                        break;
                   case '4': exp=exp+"4";
                        expression.setText(exp);
                        break;
                   case '5': exp=exp+"5";
                        expression.setText(exp);
                        break;
                   case '6': exp=exp+"6";
                        expression.setText(exp);
                        break;
                   case '7': exp=exp+"7";
                        expression.setText(exp);
                        break;
                   case '8': exp=exp+"8";
                        expression.setText(exp);
                        break;
                   case '9': exp=exp+"9";
                        expression.setText(exp);
                        break;
                   case '+': exp=exp+"+";
                        expression.setText(exp);
                        break;
                   case '-': exp=exp+"-";
                        expression.setText(exp);
                        break;
                   case '*': exp=exp+"*";
                        expression.setText(exp);
                        break;
                   case '/': exp=exp+"/";
                        expression.setText(exp);
                        break;
                   case '.': exp=exp+".";
                        expression.setText(exp);
                        break;
                   case '(': exp=exp+"(";
                        expression.setText(exp);
                        break;
                   case ')': exp=exp+")";
                        expression.setText(exp);
                        break;
                   default: break;
    // ================================= equation =============================
    class Equation
    {     private double nbr1;
         private double nbr2;
         private char op;
         private double answer;
         private String StrNum1="";
         private String StrNum2="";
         private String StrOper="";
         private String StrAns="";
         //Constructor
         Equation(String number1, String number2, String operator)
         {     StrNum1 = number1;
              StrNum2 = number2;
              StrOper = operator;
              convert();
         public double getNum1() {return nbr1;}
         public double getNum2() {return nbr2;}
         public char getOp() {return op;}
         private void convert()
         {     Double temp=new Double(StrNum1);
              nbr1=temp.doubleValue();
              temp=new Double(StrNum2);
              nbr2=temp.doubleValue();
              op=StrOper.charAt(0);
         private void convertAnswer()
         {     StrAns=StrAns.valueOf(answer);
         public String toString()
         {     return StrAns;
         public void calculate()
         {     switch (op)
              {     case '+': answer=nbr1+nbr2;
                        break;
                   case '-': answer=nbr1-nbr2;
                        break;
                   case '*': answer=nbr1*nbr2;
                        break;
                   case '/': answer=nbr1/nbr2;
                        break;
              convertAnswer();
    // =============================== linked list ================================
    class LkList
    {  char[] operator = {'+','-','*','/','(',')'}; // operators used
    LinkedList Express = new LinkedList(); // Linked list of expression
    String StrExp = null;
    String oper = ""; // operator
    String number1 = ""; // first number used in expression
    String number2 = ""; // second number used in expression
    String answer = ""; // answer of expression
    Exp TempExp; // Temporary expression
    String Temp;
    // Constructor
    LkList (String e)
    { StrExp = e;
         formList (); // expression turn into liked list nodes
         trimList (); // remove spaces from linked list expression
    public String toString()
         { return Express.toString();
    public LinkedList getList();
         { return Express;
    public String getAns()
         { return Express.get(0).toString();
    public void ProcessExpress() // removing brackets
         {  removeBrack();
    private void formList()
    {  int j = 0;
    boolean lastOper = true;
         for (j = 0 ; j < Express.length(); j++ )
    {  if (!(belongTo(operator, StrExp.charAt (j))))
              {  Temp = Temp + StrExp.charAt (j);
         lastOperator = false;
         if (belongTo(operator, StrExp.charAt (j)))
         {   if ((StrExp.charAt (j) =='-') && (lastOperator))
              {   Temp = "-";
         lastoperator = false;
              else
              {   Express.add (Temp);
              Temp = "";
                   Temp = Temp + StrExp.charAt (j);
                   Express.add (Temp);
                   Temp = "";
                   if (StrExp.charAt (j) == ')')
                   {  lastOperator = false;
                   else
                   {   lastOperator = true;
         Express.add (Temp);
         Temp = "";
    private void trimlist ()
    {   int sp = 0;
    while ((sp !=-1))
    {  sp = Express.indexOf ("");
         if (sp !=-1)
         {  Express.remove (sp);
    private static boolean belongTo (char[] ar, char c)
    {  for (int k = 0; k < ar.length; k++)
         {  if (c == ar[k]) return true;
    return false;
    private boolean findBrack ()
    {  if (Express.contains (")"))
    {  return true;
    return false;
    private void removePoints (int pt1, int pt2 )
    {  int range = (pt2 - pt1);
    for (int j = pt2; j >= pt1; j--)
    {  Express.remove (j);
    private void processOperator (String Oper)
    {  int point =-1;
         while (Express.contains (Oper))
         {  point = Express.indexOf (Oper);
         oper = Express.get(point).toString();
              number1 = Express.get(point-1).toString();
              number2 = Express.get(point+1).toString();
              TempExp = new Exp (number1, number2, oper);
              TempExp.calculate();
              answer = Temp.toString();
              Express.add(point-1, point+1);
              removePoints (point-1, point+1);
    point =-1;
    private void removeBrack()
    {  int opBrack = 0;
    int clBrack = 1;
         int j = 0;
         String Temp = "";
         while (findBrack())
         {  clBrack = Express.indexOf (")");
         j = clBrack;
              do
              {  Temp = Express.get(j).toString();
              if (Temp.charAT(0) =='(')
              {   opBrack = j;
                   j--;
              while (opBrack < 0);
              number1 = Express.get(opBrack +1).toString();
    number2 = Express.get(clBrack -1).toString();
              oper = Express.get(opBrack+2).toString();
              TempExp = new Exp (number1, number2, oper)
              TempExp.calculate();
              answer = TempExp.toString();
              Express.add(clBrack+1, answer);
              removePoints(opBrack, clBrack);
              opBrack=-1;
              clBrack=0;
    private void removeDivide()                         
         {     processOperator("/");                    
              remMult();                         
         private void removeTimes()                         
         {     processOperator("*");                         
              remAdd();                         
         private void removeAdd()                         
         {     processOperator("+");                         
              remSub();                         
         private void removeSub()                         
         {     processOperator("-");
    // ================================= help menu ============================
    class JHelp extends JFrame
    {     JTextArea textarea;
         public JHelp()
         {     super ("Help");
              Container contentPane = getContentPane();
         /*     JPanel textPan1 = new JPanel (new BorderLayout());
              textarea = new JTextArea ("How to use Nicks Calculator");
              textarea.setWrapStyleWord(false);
              JScrollPane textAreaPane1 = new JScrollPane (textarea);
              textPan1.add (textarea, BorderLayout.CENTER);
              contentPane.add(textPan1);
              textarea.setEnabled(false); */
              JLabel lab=new JLabel(new ImageIcon("helpmenu.jpg"));
              contentPane.add(lab, BorderLayout.CENTER);
              setBounds(400,200,400,400);
              this.show();
    // ================================ Splash Page =============================
    class JSplash extends JFrame
    {     public JSplash()
    {   super ("Splash Page");
              Container contentPane=getContentPane();
              JLabel lab=new JLabel(new ImageIcon("nick.jpg"));
              contentPane.add(lab, BorderLayout.CENTER);
              setBounds(400,200,250,320);
              this.show();

    Spot the difference:
    public LinkedList getList();
    public LinkedList getList()
    Notice the semi-colon. Thats the problem

  • JInternal Frames

    Hi all, I am currently writing a program which should allow me to add, delete, search and edit database records. What i would like to do is to click one of the six buttons on the toolbar and it to lauch a form within an internal frame. I have had a go but a cannot make the frame viewable. If you could help me i would be very grateful. Cheers x
    package worldfactfile;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import com.borland.jbcl.layout.*;
    public class mainScreen extends JFrame implements ActionListener{
      JPanel contentPane, panel;
      private JDesktopPane theDesktop;
      private JButton button1, button2, button3, button4, button5, button6;
      BorderLayout borderLayout1 = new BorderLayout();
      XYLayout xYLayout1 = new XYLayout();
      JLabel jLabel1 = new JLabel();
      //Construct the frame
      public mainScreen() {
        enableEvents(AWTEvent.WINDOW_EVENT_MASK);
        try {
          jbInit();
        catch(Exception e) {
          e.printStackTrace();
      //Component initialization
      private void jbInit() throws Exception {
        ImageIcon image1 = new ImageIcon("add.gif");
        ImageIcon image2 = new ImageIcon("edit.gif");
        ImageIcon image3 = new ImageIcon("delete.gif");
        ImageIcon image4 = new ImageIcon("search.gif");
        ImageIcon image5 = new ImageIcon("help.gif");
        ImageIcon image6 = new ImageIcon("exit.gif");
        button1 = new JButton(image1);
        button2 = new JButton(image2);
        button3 = new JButton(image3);
        button4 = new JButton(image4);
        button5 = new JButton(image5);
        button6 = new JButton(image6);
        button1.addActionListener(this);
        button6.addActionListener(this);
        JToolBar bar = new JToolBar();
        bar.add(button1);
        bar.add(button2);
        bar.add(button3);
        bar.add(button4);
        bar.add(button5);
        bar.add(button6);
        contentPane = (JPanel) this.getContentPane();
        contentPane.setLayout(borderLayout1);
        theDesktop = new JDesktopPane();
        contentPane.add("Center", theDesktop);
        contentPane.add("South", bar);
        this.getContentPane().setBackground(SystemColor.controlText);
        this.setSize(new Dimension(950, 750));
        this.setTitle("World Fact File");
        panel = new JPanel() {
                     public void paintComponent(Graphics g)     {
                             ImageIcon img = new ImageIcon("globe2.gif");
                             g.drawImage(img.getImage(), -20, -50, null);
                             super.paintComponent(g);
             panel.setOpaque(false);
        contentPane.add(panel);
      public void actionPerformed(ActionEvent e){
        if(e.getSource() == button6){
          System.exit(0);
        if(e.getSource() == button1){
          JInternalFrame iFrame = new JInternalFrame("My Frame, mine i said", true, true, true, true);
          JLabel lb1 = new JLabel("Hey ho...");
          iFrame.getContentPane().add(lb1);
          iFrame.setSize(new Dimension(200,50));
          iFrame.setVisible(true);
          theDesktop.add(iFrame);
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
    }

    here is ur code, i've modifyed some places. its working now.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class mainScreen extends JFrame implements ActionListener{
      JPanel contentPane, panel;
      JDesktopPane theDesktop;
      JButton button1, button2, button3, button4, button5, button6;
      BorderLayout borderLayout1 = new BorderLayout();
      //XYLayout xYLayout1 = new XYLayout();
      JLabel jLabel1 = new JLabel();
      //Construct the frame
      public mainScreen() {
        button1 = new JButton("One");
        button2 = new JButton("Two");
        button3 = new JButton("Three");
        button4 = new JButton("Four");
        button5 = new JButton("Five");
        button6 = new JButton("Six");
        button1.addActionListener(this);
        button6.addActionListener(this);
        JToolBar bar = new JToolBar();
        bar.add(button1);
        bar.add(button2);
        bar.add(button3);
        bar.add(button4);
        bar.add(button5);
        bar.add(button6);
        //contentPane = (JPanel) this.getContentPane();
        panel = new JPanel();
        panel.setLayout(borderLayout1);
        theDesktop = new JDesktopPane();
        panel.add("Center", theDesktop);
        panel.add("South", bar);
        getContentPane().add(panel);
        setSize(new Dimension(950, 750));
        setTitle("World Fact File");
        setVisible(true);
      public void actionPerformed(ActionEvent e){
        if(e.getSource() == button6){
          System.exit(0);
        if(e.getSource() == button1){
          JInternalFrame iFrame = new JInternalFrame("My Frame, mine i said", true, true, true, true);
          JLabel lb1 = new JLabel("Hey ho...");
          iFrame.getContentPane().add(lb1);
          iFrame.setSize(new Dimension(200,50));
          iFrame.setVisible(true);
          theDesktop.add(iFrame);
      protected void processWindowEvent(WindowEvent e) {
        super.processWindowEvent(e);
        if (e.getID() == WindowEvent.WINDOW_CLOSING) {
          System.exit(0);
      public static void main(String a[]){
           mainScreen ms = new mainScreen();
    }

  • What went wrong? (swing-mdi-screen resolution)

    Hello,
    I have completed my java application which I relied heavily on swing components and awt lay out managers. It is an MDI and I had developed it using border/flow/grid layout managers under a 1024*768 resolution.
    Today I ran it on a different machine that has 800*600 resolution and I was very sorry to see that the JFrame components such as buttons, textboxes don't fit in one window.(You just cant see some of the components) Did I do something wrong that caused this problem? Otherwise is this expected behaviour? However the main window's size fits the screen size. So the components should have displayed smaller to fit in the screen, but that is not the case now. What to do now?
    I appreciate your help&feedback on this.
    metin

    Thanks KPSeal,
    Here is the method that builds one of the JInternalFrame's. It may be abit confusing since it is complex. Unfortunately I won't have time to fix it since I have to return the project today. Better not to tell about the resolution issue to my professor ;) This method is a small fraction of my thesis. Looks just fine with 1024*768. Very very bad with 800*600
    private void buildAsymmetricPanel()
    Font boldFont = new Font("SansSerif",Font.BOLD,13);
    Font liteFont = new Font("SansSerif",Font.BOLD,11);
    Border etched = BorderFactory.createEtchedBorder();
    Border asym_titled = BorderFactory.createTitledBorder(etched, " Type of operator ");
    Border option_titled = BorderFactory.createTitledBorder(etched, " Parameters of this function can be determined as follows ");
    Border comp_titled = BorderFactory.createTitledBorder(etched, " Computation based on Penalty/Reward pair ");
    Border parameter_titled = BorderFactory.createTitledBorder(etched, " Parameter definition ");
    JLabel temp = new JLabel(); //to adjust other labels position
    //Asymmetric Panel
    JPanel asymPanel = new JPanel();
    //Asymmetric operators
    group2 = new ButtonGroup();
    group2_value1 = new JRadioButton("Mandatory/Desired",false);
    group2_value2 = new JRadioButton("Sufficient/Desired",false);
    group2.add(group2_value1);
    group2.add(group2_value2);
    JPanel asym_panel_center = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JPanel asym_panel_center1 = new JPanel(new FlowLayout(FlowLayout.CENTER, 60, 8));
    JPanel asym_panel_center2 = new JPanel(new FlowLayout(FlowLayout.CENTER, 25, 8));
    JPanel asym_panel_center3 = new JPanel(new BorderLayout());
    JPanel asym_panel_center3_north = new JPanel(new FlowLayout(FlowLayout.CENTER, 88, 8));
    JPanel asym_panel_center3_south = new JPanel(new FlowLayout(FlowLayout.CENTER));
    JPanel asym_panel_center4 = new JPanel(new FlowLayout(FlowLayout.CENTER, 77, 8));
    asym_panel_center1.add(group2_value1);
    asym_panel_center1.add(group2_value2);
    asym_panel_center1.setBorder(asym_titled);
    String text1 = new String("(a) By direct assignment of values in the parameter definition fields.");
    String text2 = new String("(b) By computation based on Penalty/Reward Pair");
    String text3 = new String("(b) By computation based on ");
    JLabel jtext1 = new JLabel(text1);
    jtext1.setForeground(Color.black);
    JLabel jtext2 = new JLabel(text2);
    jtext2.setForeground(Color.black);
    JLabel jtext3 = new JLabel(text3);
    jtext3.setForeground(Color.black);
    JPanel panel_text1 = new JPanel();
    JPanel panel_text2 = new JPanel();
    JPanel panel_text3 = new JPanel();
    panel_text1.add(jtext1);
    panel_text2.add(jtext2);
    panel_text3.add(jtext3);
    asym_ansyButton = new JButton("AnSy");
    asym_ansyButton.addActionListener(this);
    panel_text3.add(asym_ansyButton);
    JPanel asym_panel_center1_center = new JPanel(new BorderLayout());
    asym_panel_center1_center.add(panel_text1,"North");
    asym_panel_center1_center.add(panel_text2,"Center");
    asym_panel_center1_center.add(panel_text3,"South");
    asym_panel_center2.add(asym_panel_center1_center);
    asym_panel_center2.setBorder(option_titled);
    JPanel asym_panel_center3_1 = new JPanel(new BorderLayout());
    JPanel asym_panel_center3_2 = new JPanel(new BorderLayout());
    JLabel penalty = new JLabel ("Penalty [%]", temp.CENTER);
    penalty.setForeground(Color.black);
    asym_panel_center3_1.add (penalty,"North");
    penalty_field.setHorizontalAlignment(penalty_field.CENTER);
    asym_panel_center3_1.add(penalty_field,"Center");
    JLabel reward = new JLabel ("Reward [%]", temp.CENTER);
    reward.setForeground(Color.black);
    asym_panel_center3_2.add (reward, "North");
    reward_field.setHorizontalAlignment(reward_field.CENTER);
    asym_panel_center3_2.add(reward_field,"Center");
    asym_panel_center3_north.add(asym_panel_center3_1);
    asym_panel_center3_north.add(asym_panel_center3_2);
    penrewButton = new JButton("Compute");
    penrewButton.addActionListener(this);
    asym_panel_center3_south.add(penrewButton);
    asym_panel_center3.add(asym_panel_center3_north,"North");
    asym_panel_center3.add(asym_panel_center3_south,"South");
    asym_panel_center3.setBorder(comp_titled);
    JPanel asym_panel_center4_final = new JPanel();
    asym_panel_center4_final.setLayout(new BorderLayout());
    JPanel asym_panel_center4_north = new JPanel();
    JPanel asym_panel_center4_south = new JPanel();
    asym_panel_center4_north.setLayout(new FlowLayout(FlowLayout.LEFT));
    asym_panel_center4_south.setLayout(new FlowLayout(FlowLayout.CENTER));
    JPanel asym_panel_center4_north1 = new JPanel(new BorderLayout());
    JPanel asym_panel_center4_north2 = new JPanel(new BorderLayout());
    JLabel mandsuf = new JLabel("Mandotary/Sufficient",temp.CENTER);
    mandsuf.setForeground(Color.black);
    mandsuf.setFont(new Font("SansSerif",Font.PLAIN,9));
    asym_panel_center4_north1.add(mandsuf,"North");
    asym_panel_center4_north1.add(msinput,"Center");
    JLabel desinput = new JLabel("Desired",temp.CENTER);
    desinput.setForeground(Color.black);
    asym_panel_center4_north2.add(desinput,"North");
    dinput.setBackground(Color.lightGray);
    dinput.setEditable(false);
    asym_panel_center4_north2.add(dinput,"South");
    asym_panel_center4_north.add(asym_panel_center4_north1);
    asym_panel_center4_south.add(asym_panel_center4_north2);
    JLabel weight1 = new JLabel("W1",temp.CENTER);
    weight1.setForeground(Color.black);
    JPanel panel_weight1 = new JPanel(new BorderLayout());
    panel_weight1.add(weight1,"North");
    asym_weight1_field.addKeyListener(this);
    panel_weight1.add(asym_weight1_field,"Center");
    asym_panel_center4_north.add(panel_weight1);
    JLabel weight2 = new JLabel("W2",temp.CENTER);
    weight2.setForeground(Color.black);
    JPanel panel_weight2 = new JPanel(new BorderLayout());
    panel_weight2.add(weight2,"North");
    asym_weight2_field.addKeyListener(this);
    panel_weight2.add(asym_weight2_field,"Center");
    asym_panel_center4_north.add(panel_weight2);
    JLabel weight3 = new JLabel("q",temp.CENTER);
    weight3.setForeground(Color.black);
    JPanel panel_weight3 = new JPanel(new BorderLayout());
    panel_weight3.add(weight3,"North");
    asym_q_field.addKeyListener(this);
    panel_weight3.add(asym_q_field,"Center");
    asym_panel_center4_south.add(panel_weight3);
    JLabel weight4 = new JLabel("r",temp.CENTER);
    weight4.setForeground(Color.black);
    JPanel panel_weight4 = new JPanel(new BorderLayout());
    panel_weight4.add(weight4,"North");
    asym_r_field.addKeyListener(this);
    panel_weight4.add(asym_r_field,"Center");
    asym_panel_center4_south.add(panel_weight4);
    asym_q_field.setHorizontalAlignment(asym_q_field.CENTER);
    asym_r_field.setHorizontalAlignment(asym_r_field.CENTER);
    asym_weight1_field.setHorizontalAlignment(asym_weight1_field.CENTER);
    asym_weight2_field.setHorizontalAlignment(asym_weight2_field.CENTER);
    asym_panel_center4_final.add(asym_panel_center4_north,"North");
    asym_panel_center4_final.add(asym_panel_center4_south,"South");
    asym_panel_center4.add(asym_panel_center4_final);
    asym_panel_center4.setBorder(parameter_titled);
    asym_panel_center.add(asym_panel_center1);
    asym_panel_center.add(asym_panel_center2);
    asym_panel_center.add(asym_panel_center3);
    asym_panel_center.add(asym_panel_center4);
    asym_panel_center.setBorder(etched);
    JPanel asym_panel_north = new JPanel();
    asym_panel_north.setFont(boldFont);
    asym_panel_north.setBorder(etched);
    asym_panel_north.setLayout(new FlowLayout(FlowLayout.LEFT));
    asym_panel_north.add (new JLabel ("Block: ", temp.CENTER));
    nodeName_asym = new JTextField(40);
    nodeName_asym.setEditable(false);
    nodeName_asym.setBackground(Color.lightGray);
    asym_panel_north.add(nodeName_asym);
    JPanel asym_panel_south = new JPanel(new FlowLayout(FlowLayout.CENTER));
    asym_panel_south.setBorder(etched);
    asym_saveButton = new JButton("Save");
    asym_saveButton.addActionListener(this);
    asym_panel_south.add(asym_saveButton);
    asym_deleteButton = new JButton("Delete");
    asym_deleteButton.addActionListener(this);
    asym_panel_south.add(asym_deleteButton);
    //Help Button
    ImageIcon helpImage = new ImageIcon("help.gif");
    asym_helpButton = new JButton(helpImage);
    asym_helpButton.addActionListener(this);
    asym_panel_south.add(asym_helpButton);
    asymPanel.setLayout(new BorderLayout());
    asymPanel.add(asym_panel_north, "North");
    asymPanel.add(asym_panel_center,"Center");
    asymPanel.add(asym_panel_south,"South");
    tabbedPane.add("Asymmetric Operator",asymPanel);

  • Developing a browser in java

    Hi All,
    i want to know whether i can develop a browser using java swings..If so where i can get more details on this...
    can anyone help me..
    Thanks..
    ramya

    I Have developed one such basic application employing JEditorPane. The Code is as follows
    ReadServerFile.java
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class ReadServerFile extends JFrame {
         private JTextField enter;
         private JButton go;
         private JEditorPane contents;
         JToolBar jtb;
         JScrollPane jsp;
         JButton jbLoad,jbUnload,jbDesc,jbFind,jbSave,jbPrint,jbGet,jbGetNext,jbGetBulk,jbSet,jbBrow,jbTrap,jbGraph,jbTable,jbDebug,jbClear,jbStop,jbHelp,jbExit;
         public ReadServerFile() {
              super("Simple web browser");
              getContentPane().setLayout(null);
              int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS;
              int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS;
              Container c = getContentPane();
              enter = new JTextField("Enter file url");
              enter.addActionListener( new ActionListener(){
                        public void actionPerformed(ActionEvent e){
                             getThePage(e.getActionCommand());
              enter.setBounds(25,50,500,30);
              c.add(enter);
              //c.add(enter,BorderLayout.NORTH);
              go = new JButton("Go");
              go.setBounds(550,50,75,30);
              c.add(go);
              contents = new JEditorPane();
              contents.setEditable(false);
              contents.addHyperlinkListener( new HyperlinkListener() {
                        public void hyperlinkUpdate(HyperlinkEvent e){
                             if(e.getEventType() == HyperlinkEvent.EventType.ACTIVATED)
                             getThePage(e.getURL().toString());
              //c.add(new JScrollPane(contents), BorderLayout.CENTER);
              jsp = new JScrollPane(contents,v,h);
              //contents.setBounds(25,100,650,400);
              jsp.setBounds(25,100,700,450);
              c.add(jsp);
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              setBounds(0,0,screenSize.width,screenSize.height);
                   jtb = new JToolBar(0);
                        jbLoad      = addToolButton(jbLoad,new ImageIcon("load.jpg"),"Load MIB Module");
                        jbUnload      = addToolButton(jbUnload,new ImageIcon("unload.jpg"),"UnLoad MIB Modules");
                        jbDesc          = addToolButton(jbDesc,new ImageIcon("describe.jpg"),"Description");
                        jbFind          = addToolButton(jbFind,new ImageIcon("find.jpg"),"Find MIB Node");
                        jbSave = addToolButton(jbSave,new ImageIcon("saveresult.jpg"),"Save MIB browser results");
                        jbPrint          = addToolButton(jbPrint,new ImageIcon("printresult.jpg"),"Print MIB browser results");
                        jbGet          = addToolButton(jbGet,new ImageIcon("get.jpg"),"Get SNMP variable");
                        jbGetNext     = addToolButton(jbGetNext,new ImageIcon("getnext.jpg"),"Get Next SNMP variable");
                        jbGetBulk = addToolButton(jbGetBulk,new ImageIcon("getbulk.jpg"),"GetBulk SNMP data");
                        jbSet          = addToolButton(jbSet,new ImageIcon("set.jpg"),"Set SNMP variable");
                        jbBrow          = addToolButton(jbBrow,new ImageIcon("settings.jpg"),"MIB browser settings");
                        jbTrap          = addToolButton(jbTrap,new ImageIcon("trap.jpg"),"Trap viewer");
                        jbGraph          = addToolButton(jbGraph,new ImageIcon("graph.jpg"),"View real time graph");
                        jbTable          = addToolButton(jbTable,new ImageIcon("table.jpg"),"View SNMP table data");
                        jbDebug          = addToolButton(jbDebug,new ImageIcon("debug.jpg"),"Debug");
                        jbClear          = addToolButton(jbClear,new ImageIcon("clear.jpg"),"Clear results display");
                        jbStop          = addToolButton(jbStop,new ImageIcon("stop.jpg"),"Stop");
                        jbHelp          = addToolButton(jbHelp,new ImageIcon("help.jpg"),"Help");
                        jbExit      = addToolButton(jbExit,new ImageIcon("exit.jpg"),"Exit");
    jtb.setBounds(10,10,400,60);
    c.add(jtb);
              //setSize(400,300);
              show();
         } // end of constructor
              private void getThePage(String location){
              setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
              try{
                   contents.setPage(location);
                   enter.setText(location);
              catch(IOException io) {
                   JOptionPane.showMessageDialog(this,"Error retrieving specified url","Bad url",JOptionPane.ERROR_MESSAGE);
              setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
              } // end of getThePage
              public JButton addToolButton(JButton name,ImageIcon image,String tooltip)
                        name=new JButton(image);
                        name.setBorderPainted(false);
                        name.setFocusPainted(false);
              // name.addMouseListener(this);
                        name.setToolTipText(tooltip);
              name.setMargin(new Insets(0, 1, 0, 1));
              name.getAccessibleContext().setAccessibleName(tooltip);
              name.setActionCommand(tooltip);
                        jtb.add(name);
                        return name;
              public static void main(String args[]) {
              ReadServerFile app = new ReadServerFile();
              app.addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e)
              { System.exit(0);} } );
         } // end of Main
    } // end of this class
    For any other details contact me at [email protected]

  • Bad Layout

    Could anyone give me some tips as to how to lay this out properly, I have looked through and tried different things but nothing seems to work for me.
    Here is a screen shot of my layout as it stands:
    http://www.borninblood.co.uk/badlayout.gif
    And here is my code.
         //START OF IMPORTS
         import javax.swing.*;
         import java.awt.*;
         //END OF IMPORTS
    public class EAD // Electronic Appointments Diary
         //Everything will need to be split up into different classes.
         public static void main(String args[])
         //VARIABLE DECLARATION AREA
         JFrame mainFrame;
         Container mainContainer;
         JButton viewToday, viewAppointments, viewCalender, makeAppointment, exit, upgrade, help;
         JLabel title, welcome, welcomeInfo;
         int numberOfAppointments = 0;
         Font welcomeFont;
         Panel titlePanel, middlePanel, buttonsPanel, buttonsPanel2;
         //END OF VARIABLE DECLARATION AREA     
         //START OF MAIN PROGRAM
         mainFrame = new JFrame();
         mainFrame.setSize(900, 600);
         mainFrame.setTitle("Appointment Keeper 5000");
         mainFrame.setLocation(50, 100);
         mainContainer = mainFrame.getContentPane();
         mainContainer.setLayout(new FlowLayout());
         title = new JLabel(new ImageIcon("title.gif"));
         titlePanel = new Panel();
         titlePanel.add(title);
         mainContainer.add(titlePanel);     
         welcome = new JLabel("Welcome to Appointmatron 5000x");
         welcomeInfo = new JLabel("You have " + numberOfAppointments + " appointment(s) today.");
         welcomeFont = new Font("Serif", Font.BOLD, 32);
        welcomeInfo.setFont(welcomeFont);
        welcome.setFont(welcomeFont);
        middlePanel = new Panel();
        middlePanel.setLayout(new FlowLayout());
        middlePanel.add(welcome);
        middlePanel.add(welcomeInfo);
         mainContainer.add(middlePanel);     
         buttonsPanel = new Panel();
         buttonsPanel2 = new Panel();
         viewToday= new JButton("View Todays Appointments",new ImageIcon("todays.gif"));
         buttonsPanel.add(viewToday);
         viewCalender= new JButton("View Calender",new ImageIcon("calendar.gif"));
         buttonsPanel.add(viewCalender);
         viewAppointments= new JButton("View Appointments",new ImageIcon("todays.gif"));
         buttonsPanel.add(viewAppointments);
         makeAppointment= new JButton("Make Appointment",new ImageIcon("todays.gif"));
         buttonsPanel.add(makeAppointment);
         upgrade= new JButton("Upgrade",new ImageIcon("todays.gif"));
         buttonsPanel2.add(upgrade);
         exit= new JButton("Exit / Quit",new ImageIcon("exit.gif"));
         buttonsPanel2.add(exit);
         help= new JButton("Help",new ImageIcon("help.gif"));
         buttonsPanel2.add(help);
         buttonsPanel.setLayout(new GridLayout(0,4,5,5));
         buttonsPanel2.setLayout(new GridLayout(0,3,5,5));
         mainContainer.add(buttonsPanel);
         mainContainer.add(buttonsPanel2);
         mainFrame.setVisible(true);
         //END OF MAIN PROGRAM
    }I want the buttons to first off, fit the size of the screen I am using, and secondly be at the bottom of the screen.
    And I want the welcome text to appear on two different lines and thus fit on the screen.
    Any help would be greatly appreciated.

    Really bad comments, by the way. Someone's bound to comment on this:
    public class EAD // Electronic Appointments DiaryYou should name the class ElectronicAppointmentsDiary!

  • Bay Layout

    Could anyone give me some tips as to how to lay this out properly, I have looked through and tried different things but nothing seems to work for me.
    Here is a screen shot of my layout as it stands:
    http://www.borninblood.co.uk/badlayout.gif
    And here is my code.
         //START OF IMPORTS
         import javax.swing.*;
         import java.awt.*;
         //END OF IMPORTS
    public class EAD // Electronic Appointments Diary
         //Everything will need to be split up into different classes.
         public static void main(String args[])
         //VARIABLE DECLARATION AREA
         JFrame mainFrame;
         Container mainContainer;
         JButton viewToday, viewAppointments, viewCalender, makeAppointment, exit, upgrade, help;
         JLabel title, welcome, welcomeInfo;
         int numberOfAppointments = 0;
         Font welcomeFont;
         Panel titlePanel, middlePanel, buttonsPanel, buttonsPanel2;
         //END OF VARIABLE DECLARATION AREA     
         //START OF MAIN PROGRAM
         mainFrame = new JFrame();
         mainFrame.setSize(900, 600);
         mainFrame.setTitle("Appointment Keeper 5000");
         mainFrame.setLocation(50, 100);
         mainContainer = mainFrame.getContentPane();
         mainContainer.setLayout(new FlowLayout());
         title = new JLabel(new ImageIcon("title.gif"));
         titlePanel = new Panel();
         titlePanel.add(title);
         mainContainer.add(titlePanel);     
         welcome = new JLabel("Welcome to Appointmatron 5000x");
         welcomeInfo = new JLabel("You have " + numberOfAppointments + " appointment(s) today.");
         welcomeFont = new Font("Serif", Font.BOLD, 32);
        welcomeInfo.setFont(welcomeFont);
        welcome.setFont(welcomeFont);
        middlePanel = new Panel();
        middlePanel.setLayout(new FlowLayout());
        middlePanel.add(welcome);
        middlePanel.add(welcomeInfo);
         mainContainer.add(middlePanel);     
         buttonsPanel = new Panel();
         buttonsPanel2 = new Panel();
         viewToday= new JButton("View Todays Appointments",new ImageIcon("todays.gif"));
         buttonsPanel.add(viewToday);
         viewCalender= new JButton("View Calender",new ImageIcon("calendar.gif"));
         buttonsPanel.add(viewCalender);
         viewAppointments= new JButton("View Appointments",new ImageIcon("todays.gif"));
         buttonsPanel.add(viewAppointments);
         makeAppointment= new JButton("Make Appointment",new ImageIcon("todays.gif"));
         buttonsPanel.add(makeAppointment);
         upgrade= new JButton("Upgrade",new ImageIcon("todays.gif"));
         buttonsPanel2.add(upgrade);
         exit= new JButton("Exit / Quit",new ImageIcon("exit.gif"));
         buttonsPanel2.add(exit);
         help= new JButton("Help",new ImageIcon("help.gif"));
         buttonsPanel2.add(help);
         buttonsPanel.setLayout(new GridLayout(0,4,5,5));
         buttonsPanel2.setLayout(new GridLayout(0,3,5,5));
         mainContainer.add(buttonsPanel);
         mainContainer.add(buttonsPanel2);
         mainFrame.setVisible(true);
         //END OF MAIN PROGRAM
    I want the buttons to first off, fit the size of the screen I am using, and secondly be at the bottom of the screen.
    And I want the welcome text to appear on two different lines and thus fit on the screen.
    Any help would be greatly appreciated.

    There are many different ways to layout your window, but here's a couple thoughts.
    Use a BorderLayout for the main content pane. Add your large icon label to the NORTH of the content pane. Then create 2 subpanels - one for the CENTER where the two text labels will go, then one for the SOUTH for the buttons.
    For the center subpanel, I would probably use a vertical BoxLayout or maybe a Gridlayout in order to get the two text labels on two separate 'lines'.
    For the button panel, it looks like you desire 2 rows of buttons, so you will need 2 subpanels within the main button panel. I would use BoxLayout for each of the subpanels. Because you used a GridLayout, all of your buttons are sized to be the same size as the largest of the buttons, which causes it to be too wide. BoxLayout will let each button go to its preferred size, which should make it smaller and more likely to fit. You will need to use the Box.createHorizontalGlue and Box.createHorizontalStrut methods to space your buttons.
    You could also throw away all the nested panels, and just use a single panel with a GridBagLayout. GridBagLayout is very powerful, but often confusing and frustrating for first time users, so I'd recommended sticking with the nested panel approach you started with, just use some different layout managers.

  • Need help importing animated gif by ImageIcon in Japplet

    Hello. Im new to Java, but I want to import this animated gif with Java in a Japplet using ImageIcon, but it does not work and I would really appreciate if anyone could help me with this.
    import java.applet.*;                                   
    import java.awt.*;   
    import java.net.*;
         public class Bilder extends Japplet{                               
         public ImageIcon(java.net."http://pixelninja.se/kappawin.gif");
      Image[] bild = new Image[1];                            
      int nr=0;                                                
      public void init(){                                     
        setBackground(Color.black);                         
        bild[0] = getImage(getCodeBase(),"4a.gif");     
      public void paint(Graphics g){
        g.drawImage(bild[0],50,50,212,282,this);
    }

    You cant do animated gifs this way.
    Also you should remember that you cannot load images in to an applet if it is hosted somewere else than the host that hosts the applet.
    Esiast way to display an image icon with a animated gif will be creating a Image Label and adding it to the applet.
    Ex:-
    public class MyImageApplet extends JApplet{
       public void init(){
          getConentPane().setLayout(new BorderLayout());
           URL imageURL = getClass().getResource("/myImage.gif"); 
          // Above image file should be in the code base or in the archive file of the applet
          getConentPane().add(new JLabel(new ImageIcon(imageURL)));
    }

  • HELP! - ImageIcons disappear

    First, I'm using 1.4 on Windows NT. Periodically the
    ImageIcons on my toolbar buttons disappear. Most of
    the time everything is fine, but sometimes the images
    just disappear. If I drag another window over my toolbar,
    the images get redrawn most of the time, but its not
    a guarantee. From what I have seen on this Forum, other
    folks have also encountered this problem, but I have
    yet to hear of a solution other than to ignore it. If anyone
    has any kind of solution, I would appreciate hearing from
    you.

    As a workaround you can set the following property when you run your java program:
    -Dsun.java2d.noddraw=true
    This is a known bug (4664818).
    Hope that helps...

  • Help please with a Static Initializer for ImageIcons inside Jar Files

    At the moment I'm playing around displaying XML using A JTree
    I am subclassing DefaultMutableTreeNode, and want it to have some default Icons set up....
    Sort of like this:
    public class XNode extends DefaultMutableTreeNode
        public static final ImageIcon icon;
       public static ImageIcon getIcon()
            return XNode.icon;
    }The only thing is that for the life of me after trying various things and searching these forums and google:
    I can't work out how to write the static Initializer for the ImageIcon.
    The ImageIcon will need to be created using a URL, cos it will be inside my jar file.....
    the usual...
               URL url = this.getClass().getResource("/images/Exit16.gif");
               ImageIcon Icon = new ImageIcon( url );but I wanted these Icons to be class members..............
    Could someone help?
    }

    DrClap " I don't understand why you put Class.forName in there either"
    A: Because I don't really know what I'm doing.
    I will try that suggestion.
    At present I have this:
         static ImageIcon loadIcon;
         static
              try
                loadIcon = new ImageIcon( Class.forName("cis.editor.xml.nodes.AlNode").getResource("/images/Exit16.gif"));
              catch( ClassNotFoundException cnfe )
                   System.out.println("ClassNotFound: " + cnfe.getMessage() );
         public static final ImageIcon defaultIcon = loadIcon;
         static
              try
                loadIcon = new ImageIcon( Class.forName("cis.editor.xml.nodes.AlNode").getResource("/images/tree_folder_major.gif"));
              catch( ClassNotFoundException cnfe )
                   System.out.println("ClassNotFound: " + cnfe.getMessage() );
         public static final ImageIcon commentIcon = loadIcon;
    //.......... ANd so OnWhy? Because do far it was the only way I could get it to compile.
    And It works..
    However it's a real abortion.. codewise.
    I need to load about 16 Icons that the various subclasses can 'use'
    DefaultTreeCellRenderer - must do somethng similar because it has a bunch of Icons to "Pick from",
    Only How is that done 'properly' ?

  • ImageIcons... JPanels.... JLabels... help?

    Hello all.
    I am a noobie at this stuff (just to let y'all kno) and I'm having a hard time drawing/painting an ImageIcon on a JPanel. I'm not really sure, but I think it has something to do with the fact that the Graphics class is abstract (so obviously I can't make an instance of it) and therefore I can't pass a graphics object in a parameter without getting a NullPointerException or compiler error saying "g" has not been initialised.
    here's part of the code:
    ImageIcon image = new ImageIcon("C:\\marble.JPEG", "a marble");
              JLabel background = new JLabel(image);
              container.add(background, BorderLayout.CENTER);
    Any help would be greatly appreciated. :-)

    the method you need is
    setIcon()
    here's the earlier code, modified for the image to show after clicking the button
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class Testing extends JFrame
      public Testing()
        setSize(600,400);//needs a size, otherwise frame will be very small (label is empty)
        setLocation(300,100);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel p = new JPanel();
        final JLabel lbl = new JLabel();
        p.add(lbl);
        getContentPane().add(p,BorderLayout.CENTER);
        JButton btn = new JButton("Show Image");
        getContentPane().add(btn,BorderLayout.SOUTH);
        btn.addActionListener(new ActionListener(){
          public void actionPerformed(ActionEvent ae){
            lbl.setIcon(new ImageIcon("C:\\Test.jpg","a marble"));
            pack();//will change the size of the frame, comment out and experiment
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • ImageIcon problem *Please HELP*

    Hello
    I am having problems adding an Image to this code I have tried everything I know but to no avail. Could u please give me some pointers as to what I am doing wrong.
    Thank you Michael
    The code:
    {color:#003300}package calculator;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class calculator extends JFrame {
    {color}
    {color:#003300}
    public calculator(){
    Container con = getContentPane();
    setSize(800, 600);
    con.setLayout(new GridLayout(5, 1));
    final JTextField value1, value2, sum;
    {color}
    {color:#003300}
    {color:#ff0000}ImageIcon img = new ImageIcon("images/calculator.jpg");
    JButton button = new JButton();
    button.setIcon(img);
    con.add(button);{color}
    value1 = new JTextField();
    value2 = new JTextField();
    sum = new JTextField();
    sum.setEditable(false);
    con.add(button);
    con.add(value1);
    con.add(value2);
    con.add(sum);
    JButton button1 = new JButton("Test 1");
    button1.setText("Equals");
    button1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
    int val1 = Integer.parseInt(value1.getText());
    int val2 = Integer.parseInt(value2.getText());
    int val3 = val1 + val2;
    String val4 = Integer.toString(val3);
    sum.setText(val4);
    con.add(button1);
    pack();
    setVisible(true);
    }{color}

    Hello thank you for replying to my post I reposted the code in the correct way. I have tried running your code that you have provided but the image would still not show up on the screen. Is there any advice or problems that you can see with my code ? Any help is greatly appreciated.
    Thank you Michael
    /* Author Michael
    package calculator;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    class calculator extends JFrame {
        private static final String CALC_IMAGE_STRING = "images/calculator.jpg";
        public calculator(){
        Container con = getContentPane();
        setSize(800, 600);
        con.setLayout(new GridLayout(5, 1));
        final JTextField value1, value2, sum;
        ImageIcon img = new ImageIcon(CALC_IMAGE_STRING);
        JButton button = new JButton(img);
        System.out.println("The File is located at " + CALC_IMAGE_STRING);
        System.out.println("image height: " + img.getIconHeight());
        con.add(button);
        value1 = new JTextField();
        value2 = new JTextField();
        sum = new JTextField();
        sum.setEditable(false);
        con.add(button);
        con.add(value1);
        con.add(value2);
        con.add(sum);
        JButton button1 = new JButton("Test 1");
        button1.setText("Equals");
        button1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent e)
            int val1 = Integer.parseInt(value1.getText());
            int val2 = Integer.parseInt(value2.getText());
            int val3 = val1 + val2;
            String val4 = Integer.toString(val3);
            sum.setText(val4);
        con.add(button1);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        pack();
        setVisible(true);
    }

  • JMenu & ImageIcon, Please Help me !!

    There is a jframe with a jmenubar.
    there is a jmenu in that jmenubar.
    I have created a imageicon from an image.
    I have written.
    JMenu.setIcon (new ImageIcon (String fileName));
    But this icon isn't covering the whole menu. When i click on menu then some back screen visible near its boundary..
    I want to fix this icon over full jmenu.
    how can i do so.. pls help me .. it is very urgent...

    NOOOOOOOOOOOOOOOOOOOOOOOOOO..
    It is not working.... sir........
    I am frustrated with this........
    i have written........
    * AAA.java
    * Created on April 15, 2003, 1:53 PM
    * @author Administrator
    public class AAA extends javax.swing.JFrame
    /** Creates new form AAA */
    public AAA ()
    initComponents ();
    /** This method is called from within the constructor to
    * initialize the form.
    * WARNING: Do NOT modify this code. The content of this method is
    * always regenerated by the Form Editor.
    private void initComponents()
    jMenuBar1 = new javax.swing.JMenuBar();
    jMenu1 = new javax.swing.JMenu();
    addWindowListener(new java.awt.event.WindowAdapter()
    public void windowClosing(java.awt.event.WindowEvent evt)
    exitForm(evt);
    jMenu1.setBorder(null);
    jMenu1.setIcon(new javax.swing.ImageIcon("C:\\Documents and Settings\\Administrator\\Desktop\\accept.gif"));
    jMenu1.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jMenuBar1.add(jMenu1);
    setJMenuBar(jMenuBar1);
    pack();
    java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    setSize(new java.awt.Dimension(400, 300));
    setLocation((screenSize.width-400)/2,(screenSize.height-300)/2);
    /** Exit the Application */
    private void exitForm (java.awt.event.WindowEvent evt)
    System.exit (0);
    * @param args the command line arguments
    public static void main (String args[])
    new AAA ().show ();
    // Variables declaration - do not modify
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenuBar jMenuBar1;
    // End of variables declaration
    BUT it doesn't work.. still the icon is not covering the full jMenu... we i click on JMenu .. the boundry is seen with different color.
    It looks so bad.. Pls tell me how to do it....
    However thanks for it..
    waiting..
    "anjeev Dhiman"

Maybe you are looking for

  • R61 hard drive can i install bigger hard drive

    got this r61 #8935-a47 from my niece and i'm messing around with it,   the hard drive is a 80 gb 5400 rpm can i throw a 160 gb 7200 rpm in it  i have here the only difference that i see is the 7200 is 800 mA and the 5400 is 700 mA the 7200 # is p42t

  • DB Adapter : How to limit number parent records in select query.

    Hi All, I am querying a master-detail tables from a database. I want to limit the number of parent records to 15. Ex: Resources is parent table. It has two child tables "Skills" & "PersonalDetails". Resources table has 1 to many relationship with abo

  • Oracle Spatial LRS point X and Y.

    I’m having some problems with LRS points. Two tables: A and b. Table A contains valid LRS linestrings; table B (non spatial) is a list of points with stated eastings and northings columns that exist in close proximity to the linestrings. Points are a

  • Trying to download Windows support software?

    Im trying to run windows 7 through bootcamp, but everytime i get to the part where you download the Windows support software it takes forever idk if it has frozen or if the file is just that big...  Any other suggestions??

  • PSE12 on Windows 8.1

    I bought Sony Vaio Flip with Win 8.1.  I installed PSE12 & imported 10+ years of photos.  After many hours tagging and face recognition, catalog would not back up.  Tried to Reconnect - failed due to "corrupt database".  Now I cannot reconnect, backu