forum  

Re: [Forum] problem with MatteBorder.

List for Users of Carlsbad Cubes' Technologies and Products
Sun, 26 Feb 2006 10:05:32 -0800

Hello Mrs/Mr nobody,

I had no problem whatsoever running your xml-file. Border shows up and responds to changes of the insets (like, substituting all 4 with 8).

Be sure to get the correct xml file rendered and (if you are using Eclipse) refresh the project the files are in. Sometimes this causes strange "cache effects" I encountered as well...

I add a small test program which may ease the development. Place it in the swixml-source path at the correct place and the swixml-test.xml in your classpath as well.

Yours,

Frank Meissner

List for Users of Carlsbad Cubes' Technologies and Products schrieb:
If I run the gridbag example that is on the website (xml see below), I dont
get the red MatteBorder (in JDK 1.4 and JDK 1.5).
I compiled SwiXML in debug mode and even added a print statement in the
BorderConverter class, just before the border is actually created.

      System.out.println("Invoking createxxxxBorder method");
      border = (Border) method.invoke( null, args );
(on line 149 of the BorderConverter class (swixml #144) ).

The print line shows up, no exceptions show up, but I still dont see any
border. My OS is windows XP.


<?xml version="1.0" encoding="UTF-8"?>
<frame name="frame" size="500,300" title="Simple Complaint Dialog"
background="FFCCEE" layout="BorderLayout">
        <panel name="pnl" background="3399CC" border="MatteBorder(4,4,4,4,red)"
constraints="BorderLayout.CENTER" layout="GridBagLayout">
                <button name="btn1" text="Wonderful">
                        <gridbagconstraints id="gbc_1" insets="2,2,2,2" gridx="0" 
gridy="0"
ipadx="15" ipady="15" weightx="1" weighty="1"/>
                </button>
                <button name="btn2" text="World">
                        <gridbagconstraints use="gbc_1" gridx="1"/>
                </button>
                <button name="btn3" text="of">

                        <gridbagconstraints insets="2,2,2,2" gridx="0" gridy="1" 
ipadx="0"
ipady="0" weightx="1.0" weighty="1.0"/>
                </button>
                <button name="btn4" text="Swing">
                        <gridbagconstraints insets="2,2,2,2" gridx="1" gridy="1" 
ipadx="0"
ipady="0" weightx="1.0" weighty="1.0"/>
                </button>
        </panel>
</frame>


_______________________________________________
Forum mailing list
Forum@carlsbadcubes.com
http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com


<frame size="100,200" DefaultCloseOperation="JFrame.EXIT_ON_CLOSE" title="Control">
  <panel layout="GridLayout(3,1)">
    <button action="openAction" icon="toolbarButtonGraphics/general/Open24.gif"/>
    <button action="refreshAction" icon="toolbarButtonGraphics/general/Refresh24.gif"/>
    <button action="stopAction" icon="toolbarButtonGraphics/general/Stop24.gif"/>
  </panel>
</frame>
package org.swixml;

import javax.swing.Action;
import javax.swing.AbstractAction;
import javax.swing.JFileChooser;
import java.awt.Container;
import java.io.File;
import java.awt.event.ActionEvent;
import java.awt.Point;
import javax.swing.JFrame;
import javax.swing.JPanel;



/**
 * Displays a small control panel and tries to render the given arguments as Swixml file.
 *
 * @author <a href="mailto:[EMAIL PROTECTED]">Frank Meissner</a>
 * @version 1.0
 */
public class SwixmlTest extends SwingEngine {
      
  protected File currentDir;
  protected File currentFile;

  /**
   * Action to open new Swixml files.
   *
   */
  public Action openAction = new AbstractAction() {
      /* (non-Javadoc)
       * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
       */
      public void actionPerformed(ActionEvent e) {
        JFileChooser jfc;
        if (currentDir == null) {
          jfc = new JFileChooser();
        } else {
          jfc = new JFileChooser(currentDir);
        }
        int answer = jfc.showOpenDialog(controlPanel);
        if (answer == JFileChooser.APPROVE_OPTION) {
          currentDir = jfc.getCurrentDirectory();
          currentFile = jfc.getSelectedFile();
          refreshAction.actionPerformed(e);
        }
      }
    };
  /**
   * Action to refresh the currently displayed Swixml file.
   *
   */
  public Action refreshAction = new AbstractAction() {
      Container myContainer = null;
      /* (non-Javadoc)
       * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
       */
      public void actionPerformed(ActionEvent e) {
        SwingEngine se = new SwingEngine();
        try {
          Point location = null;
          if (myContainer != null) {
            location = myContainer.getLocation();
            myContainer.setVisible(false);
          }
          myContainer = showContainer(se.render(currentFile));
          if (location != null) {
            myContainer.setLocation(location);
          }
          if (myContainer instanceof JFrame) {
            JFrame frame = (JFrame) myContainer;
            frame.setTitle(currentFile.getName());
          }
        } catch (Exception e1) {
          e1.printStackTrace(System.err);
        }
      }
    };
  /**
   * Action to exit the program.
   *
   */
  public Action stopAction = new AbstractAction() {
      /* (non-Javadoc)
       * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
       */
      public void actionPerformed(ActionEvent e) {
        System.exit(0);
      }
    };
  protected Container controlPanel;

  public void renderContainer() throws Exception {
  }
  /**
   * Renders only the control panel.
   *
   */
  public SwixmlTest() {
    try {
      // try to render the control panel and encapsulate exceptions
      controlPanel = render("swixml-test.xml");
      controlPanel.setVisible(true);
    } catch (Exception e) {
      e.printStackTrace(System.err);
    }
  }
  /**
   * Renders the control panel
   *
   * @param resourceName a <code>String</code> value
   * @exception Exception if an error occurs
   */
  public SwixmlTest(String resourceName) throws Exception {
    this();
    Container container = new SwingEngine().render(resourceName);
    showContainer(container);
  }
  public SwixmlTest(File xmlFile) throws Exception {
    this();
    currentFile = xmlFile;
    refreshAction.actionPerformed(null);
  }

  Container showContainer(Container container) {
    Container result;
    if (container instanceof JPanel) {
      JFrame frame = new JFrame();
      setAppFrame(frame);
      frame.getContentPane().add(container);
      frame.setSize(container.getSize());
      frame.setVisible(true);
      result = frame;
    } else {
      container.setVisible(true);
      result = container;
    }
    return result;
  }

  public static void main(String[] args) throws Exception {
    if (args.length > 0) {
      for (int i = 0; i < args.length; i++) {
        File f = new File(args[i]);
        if (f.exists()) {
          new SwixmlTest(f);
        } else {
          new SwixmlTest(args[i]);
        }
      }
    }
  }

}
_______________________________________________
Forum mailing list
Forum@carlsbadcubes.com
http://carlsbadcubes.com/mailman/listinfo/forum_carlsbadcubes.com