Help! Using a custom renderer to display an image

I have a JTable where I want to set the renderer of one column to a custom renderer. And I want this renderer to show either a play button image, or a stop button image, depending on the status, which is a Boolean value. However, the image won't show up when I run the application. Here's the code from the renderer...
public class StatusRenderer extends DefaultTableCellRenderer {
private ImageIcon playIcon = new ImageIcon("C:/play.jpg");
private ImageIcon stopIcon = new ImageIcon("C:/stop.jpg");
public StatusRenderer() {
setHorizontalAlignment(JLabel.CENTER);
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int col) {
Boolean b = (Boolean) value;
setIcon(b.booleanValue() ? playIcon : stopIcon);
return this;
The application runs, but no icon shows up in the table cell. I'd really appreciate any help on this. Thanks.

look at http://www2.gol.com/users/tame/swing/examples/JTableExamples1.html
for some great table examples (they may need minor mods to work on 1.3/1.4)
Basically I think you need something more like:
public class StatusRenderer extends JLabel
  implements DefaultTableCellRenderer
    public StatusRenderer() {
        super();
        setHorizontalAlignment(JLabel.CENTER);
    public Component getTableCellRendererComponent(JTable table,
                                       Object value, boolean sSelected,
                                       boolean hasFocus, int row,
                                       int col)
        Boolean b = (Boolean) value;
        setIcon(b.booleanValue() ? playIcon : stopIcon);
        return this;
}Don't forget to add the renderer to the column you want it in !

Similar Messages

  • I recently upgraded my Mac to Yosemite and I can't use the custom function (grayed out) in Image Trace Illustrator CS6 (physical version). Anyone else having this issue?

    I recently upgraded my Mac to Yosemite and I can't use the custom function (grayed out) in Image Trace Illustrator CS6 (physical version). Anyone else having this issue?

    Custom will show automatically as soon as you just edit some options. So just go ahead, you don't need to select "custom"

  • Need Helping using VBA custom code to query AS400 database

    Hi
    I am trying to connect the AS400 using the custom page programmability in etester. I am able to make the connection for SQL queries but when i try to do the same for a SPROC, I am not able to do it successfully. Any help is very much appreciated.
    Thanks
    Subu

    The easiest thing to open the ODBC interface and create a DSN entry for your AS400. (You will need the appropriate drivers loaded on the windows machine) Once you have done that, you can use the Microsoft Active-x data objects to connect, query, read and write data.

  • Using an advanced action to display an image (or button) on each slide.

    I have an advanced action that evaluates certain criteria. The advance action is called from several different slides within the presentation. Is there some way that I can get it to display a set image if the criteria is met? It seems like I would have to write a new, slightly different advanced action on each slide to "show" the image on each slide.
    Is there some way to share an image (or button) so that the advanced action can make it appear, no matter what slide you are on?
    Let me know if I need to provide further clarification. Thanks!

    Technically your advanced actions are only allowed to show or hide images from the slide where they are actually executed.  So an advanced action executed on slide 3 for example, will not be able to show or hide an image on slide 5.
    However, what you can do is place the image on one of the earlier slides in the project and then set it to be timed for Rest of Project.  This allows you to SHOW or HIDE the image from any slide later in the project where your Advanced Action is executed.

  • Problem with JTree custom renderer when editing

    I have a JTree which uses a custom renderer to display my own icons for different types of nodes. The problem I am having is when I setEditable to true and then attept to edit a node the icon switches back to the default icon, as soon as I am done editing it goes back.
    What I am doing wrong?

    Here is my rendererer
    public class DeviceTreeRenderer extends DefaultTreeCellRenderer implements GuiConstants {
       public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
          JLabel returnValue = (JLabel)super.getTreeCellRendererComponent(tree, value, selected, expanded, leaf, row, hasFocus);
          if (value != null) {
             returnValue.setToolTipText(value.toString());
          if (value instanceof Device) {
             returnValue.setIcon(TREE_DEVICE);
             if (!((Device)value).isAlive()) {
                returnValue.setEnabled(false);
          else if (value instanceof GuiPanelGroup) {
             if (expanded) {
                returnValue.setIcon(TREE_PANEL_GROUP_OPEN);
             else {
                returnValue.setIcon(TREE_PANEL_GROUP_CLOSED);
          else if (value instanceof GuiPanel && ((GuiPanel)value).isDirty()) {
             returnValue.setIcon(TREE_PANEL_DIRTY);
          return returnValue;
    }Here is my editor:
    public class WwpJTreeCellEditor extends DefaultTreeCellEditor implements GuiConstants {
          private WwpJTree tree;
           * Creates a new WwpJTreeCellEditor.
           * @param tree The WwpJTree to associate with this editor.
          public WwpJTreeCellEditor(WwpJTree tree) {
             super(tree, (DefaultTreeCellRenderer)tree.getCellRenderer());
             this.tree = tree;
           * Overrides the default isCellEditable so that we check the isEditable() method
           * of the WwpJTreeNodes.
           * @param e An EventObject.
          public boolean isCellEditable(EventObject e) {
             boolean returnValue = super.isCellEditable(e);
             if (returnValue) {
                WwpJTreeNode node = this.tree.getSelectedNode();
                if (node == null || !node.isEditable() || node.isDragging()) {
                   returnValue = false;
             return returnValue;
       }In my JTree I make these calls:
    super.setCellRenderer(new DeviceTreeRenderer());
    super.setCellEditor(new WwpJTreeCellEditor(this));
    super.setEditable(true);

  • Custom renderer in datagrid, needs to know if data changed

    Hi,
    I am hoping someone can help me out please.
    I have a datagrid that uses a custom renderer that is
    subclassed from a TextInput. When the user changes the data in a
    cell, I need to color the cell. This is so that on a potentially
    big grid, the user can easily see which cells he has made changes
    to.
    It is easy enough to set the color of the itemrenderer by
    using setStyle() inside the overridden set data() method of the
    custom renderer, but that is only a fraction of the solution. Since
    Flex instantiates and destroys custom renderers at will depending
    on if it is scrolled into view by the datagrid, keeping the state
    of whether a value has changed inside the custom rendererer is not
    an option.
    So the only choice I have is to call back from the custom
    renderer into the container that hosts the datagrid. As the
    itemEditEnd event is handled in that container, a list of cells
    that have had their data changed can be stored. The custom renderer
    then needs to call back into the container with its cell
    coordinates and ask if the data has changed, and if it has, set its
    color.
    How can a custom renderer know its cell position as x,y
    coordinates? I see that TextInput implements IListItemRenderer
    interface and has properties x and y, but putting a trace on these
    gives me nonsensical numbers that seem to have no relation to the
    cell coordinates.
    The other thing I need to do is have the custom renderer call
    back into the container that hosts the datagrid to know whether
    data has changed. Is outerDocument the reference? Or is there a
    proper way of doing this?
    Thanks for the help you can give.

    Here is a simplified version of how we track the cell by cell
    changes in a datagrid. It does require you to identify the fields
    that will be editable and maintaining the original data for each
    column in the data source.
    Our production version is much more complex than this but it
    will give you the idea.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application
    xmlns:mx="
    http://www.adobe.com/2006/mxml"
    layout="absolute"
    creationComplete="initApp()"
    viewSourceURL="srcview/index.html">
    <mx:Script>
    <![CDATA[
    import mx.binding.utils.BindingUtils;
    import mx.collections.ArrayCollection;
    import mx.core.Application;
    import flash.events.*;
    import mx.events.DataGridEvent;
    import mx.controls.TextInput;
    [Bindable] public var editAC : ArrayCollection = new
    ArrayCollection();
    [Bindable]
    public var somedata:XML = <datum><item>
    <col0>0</col0>
    <col1></col1>
    <col2></col2>
    <col3>2</col3>
    <col4></col4>
    <col5></col5>
    <col6></col6>
    <col0Orig>0</col0Orig>
    <col1Orig></col1Orig>
    <col2Orig></col2Orig>
    <col3Orig>2</col3Orig>
    <col4Orig></col4Orig>
    <col5Orig></col5Orig>
    <col6Orig></col6Orig>
    </item>
    <item>
    <col0></col0>
    <col1></col1>
    <col2></col2>
    <col3></col3>
    <col4></col4>
    <col5></col5>
    <col6></col6>
    <col0Orig></col0Orig>
    <col1Orig></col1Orig>
    <col2Orig></col2Orig>
    <col3Orig></col3Orig>
    <col4Orig></col4Orig>
    <col5Orig></col5Orig>
    <col6Orig></col6Orig>
    </item>
    <item>
    <col0></col0>
    <col1></col1>
    <col2></col2>
    <col3></col3>
    <col4></col4>
    <col5></col5>
    <col6></col6>
    <col0Orig></col0Orig>
    <col1Orig></col1Orig>
    <col2Orig></col2Orig>
    <col3Orig></col3Orig>
    <col4Orig></col4Orig>
    <col5Orig></col5Orig>
    <col6Orig></col6Orig>
    </item>
    <item>
    <col0></col0>
    <col1></col1>
    <col2></col2>
    <col3></col3>
    <col4></col4>
    <col5></col5>
    <col6></col6>
    <col0Orig></col0Orig>
    <col1Orig></col1Orig>
    <col2Orig></col2Orig>
    <col3Orig></col3Orig>
    <col4Orig></col4Orig>
    <col5Orig></col5Orig>
    <col6Orig></col6Orig>
    </item>
    <item>
    <col0></col0>
    <col1></col1>
    <col2></col2>
    <col3></col3>
    <col4></col4>
    <col5></col5>
    <col6></col6>
    <col0Orig></col0Orig>
    <col1Orig></col1Orig>
    <col2Orig></col2Orig>
    <col3Orig></col3Orig>
    <col4Orig></col4Orig>
    <col5Orig></col5Orig>
    <col6Orig></col6Orig>
    </item>
    <item>
    <col0></col0>
    <col1></col1>
    <col2></col2>
    <col3></col3>
    <col4></col4>
    <col5></col5>
    <col6></col6>
    <col0Orig></col0Orig>
    <col1Orig></col1Orig>
    <col2Orig></col2Orig>
    <col3Orig></col3Orig>
    <col4Orig></col4Orig>
    <col5Orig></col5Orig>
    <col6Orig></col6Orig>
    </item>
    </datum>
    private function initApp():void {
    var dgcols:Array = grid1.columns;
    for (var i:int=1;i<12;i++) {
    var dgc:DataGridColumn = new DataGridColumn();
    if(i < 6) {
    dgc.width=60;
    dgc.editable=true;
    dgc.dataField="col" + i.toString() ;
    dgc.rendererIsEditor=true;
    var ir :DGItemRenderer = new DGItemRenderer();
    dgc.itemRenderer = ir;
    else {
    dgc.width=0;
    dgc.visible = false
    dgc.dataField="col" + i.toString() + "orig" ;
    dgcols.push(dgc);
    grid1.columns = dgcols;
    ]]>
    </mx:Script>
    <mx:DataGrid x="31" y="27" width="200" height="150"
    id="grid1" dataProvider="{somedata.children()}"
    horizontalScrollPolicy="on" rowHeight="25"
    editable="true">
    <mx:columns>
    <mx:DataGridColumn headerText="Column 0"
    dataField="col0" width="30" editable="false"/>
    </mx:columns>
    </mx:DataGrid>
    </mx:Application>
    <?xml version="1.0" encoding="utf-8"?>
    <mx:TextInput xmlns:mx="
    http://www.adobe.com/2006/mxml"
    creationComplete="init()"
    implements="mx.controls.listClasses.IDropInListItemRenderer,
    mx.core.IFactory"
    >
    <mx:Script>
    <![CDATA[
    import mx.collections.ArrayCollection;
    import mx.controls.dataGridClasses.DataGridListData;
    public function newInstance():* {
    var ir : DGItemRenderer = new DGItemRenderer();
    return ir;
    override public function set data(value:Object):void
    super.data = value;
    if (value != null) {
    var colName : String= DataGridListData(listData).dataField;
    var valOrig : String = data[colName + "Orig"];
    var val : String = data[colName];
    if(valOrig != val)
    this.setStyle("backgroundColor",0xA7FF3F);
    else
    this.setStyle("backgroundColor", "#ffffff");
    ]]>
    </mx:Script>
    </mx:TextInput>

  • Need help in displaying an Image in a JLabel

    Hi everyone,
    I am using a JLabel to display images on a particular screen. I am facing some problem while doing so..
    On my screen there are images of some garments. When the users select colors from a particular list, i should color this garment images and load it on the screen again with the colors. I have a floodfill class for filling the colors in the images. The problem I am facing is I am able to color the image properly with my floodfill class but when displaying the image on the same jlabel, the image gets distorted somehow.
    Everytime I color the image, I create an ImageIcon of the image and use the seticon method from the JLabel class. First I set the icon to null and then set it to the imageicon created. here is the code I use.
    If 'image' is the the image i have to load
    ImageIcon imgicon = new ImageIcon(image);
    jlabel.setIcon(null);
    jlabel.setIcon(imgicon);I am setting the icon to null because I have not found any other method to clear the previous image from the jlabel.
    Can anyone who has worked on images before and faced a similar situation help me with this?? Is there some other container I can use besides the JLabel to display the images perhaps?
    Thanks in advance.....
    Bharat

    And the thing is when I first go into that screen with the selected colors it is displaying the images perfectly.
    It is only giving problems when I pick different colors on the screenit really sounds like the problem is in your floodfill class.
    I have no idea what's in floodfill, but if you were e.g. using a JPanel and paintComponent,
    you would need to have as the first line in paintComponent()
    super.paintComponent(..);
    to clear the previous painting.
    if not, you would be just drawing over the top of the previous paintComponent(), and if the calculation of the
    painting area is not 100% exact, you may get the odd pixel not painted-over, meaning those pixels will display
    the old color.

  • Custom renderer on standard component

    I try to implement a custom renderer to a standard component (<h:outputText>), but
    my Tomcat failed to start the webcontainer.
    here are my files:
    faces-config.xml
    <render-kit>
    <renderer>
    <renderer-type>MyRenderer</renderer-type>
    <renderer-class>renderkit.MyRenderer</renderer-class>
    </renderer>
    <supported-component-class>
    <component-class>javax.faces.Text</component-class>
    </supported-component-class>
    </render-kit>
    ...renderkit.MyRenderer.java
    package renderkit;
    import java.io.IOException;
    import javax.faces.component.UIComponent;
    import javax.faces.component.UIOutput;
    import javax.faces.context.FacesContext;
    import javax.faces.context.ResponseWriter;
    import javax.faces.render.Renderer;
    public class MyRenderer extends Renderer {
         public void decode(FacesContext context, UIComponent component) {
              System.out.println("decode");
              if ((context == null) || (component == null)) {
                   throw new NullPointerException();
         public void encodeBegin(FacesContext context, UIComponent component)
              throws IOException {
              System.out.println("encodeBegin");
              if ((context == null) || (component == null)) {
                   throw new NullPointerException();
         public void encodeChildren(FacesContext context, UIComponent component)
              throws IOException {
              System.out.println("encodeChildren");
              if ((context == null) || (component == null)) {
                   throw new NullPointerException();
         public void encodeEnd(FacesContext context, UIComponent component)
              throws IOException {
              System.out.println("encodeEnd");
              UIOutput comp = (UIOutput) component;
              ResponseWriter writer = context.getResponseWriter();
              StringBuffer sb = null;
              writer.startElement("<test>", comp);
              writer.write(comp.getValue().toString());
              writer.endElement("</test>");
    }

    <h:outputText> will use a rendererType of "javax.faces.Text"; to use a custom renderer on a standard component, you must not only write a renderer and register it, but also add a custom tag that uses that renderer type. Alternatively, you could use the "binding" attribute to set the renderer type like:
      <h:outputText binding="#{someBean.customText}" .../>
    public class SomeBean
      public SomeBean()
       HtmlOutputText customText = new HtmlOutputText();
        customText.setRendererType("MyRenderer");
        setCustomText(customText);
      public HtmlOutputText getCustomText()
        return _customText;
    public void setCustomText(HtmlOutputText customText)
       _customText = customText;
    private HtmlOutputText _customText;
    }-- Adam Winer (EG member)

  • Problem Displaying an Image in a JScrollPane

    Hi All,
    I've placed a Toolbar at the bottom of a JFrame and above the toolbar I placed a JTabbedPane. In one of the tabs I want to display a full sized image.The size of the image that I want to display using a scroll pane is 595x842 pixels. Now the problem is that when I display the image in the scroll pane the bottom toolbar is overlapped with the scrollpane. I don't want to resize the image as it is spoiling the image quality.I used the below code
    JPanel imagepagepanel=new JPanel()
        protected void paintComponent(Graphics g)
              js=new JScrollPane();
              Point p = js.getViewport().getViewPosition();
              g.drawImage(demoicon.getImage(), p.x, p.y, null);
    mytabbedpane.addTab("View Image",js); //add the scrollpane to the tabI even tried using a label to display the image in the tabbedpane and I've got the same overlapping problem.
    I am able to embed the default browser in my application using JDIC API and the image display is fine in the browser without overlapping the bottom toolbar. But I don't want to use a web browser to display the image.
    It would be of great help if anyone could suggest a solution to the overlapping problem. I want the scroll pane to work similar to a web browser while displaying a large sized image.
    Thanks in advance.

    Override the paintComponent method to just draw the
    image at 0, 0, w, h.
    The rest is not needed, to say the least.Here's an easier way
    import javax.imageio.ImageIO;
    import javax.swing.*;
    import java.awt.*;
    import java.io.File;
    import java.io.IOException;
    public class ImageInTabbedScrollTest extends JFrame {
        public ImageInTabbedScrollTest() {
            buildGUI();
        private void buildGUI() {
            JPanel mainPanel = (JPanel) getContentPane();
            mainPanel.setLayout(new BorderLayout());
            JTabbedPane tabbedPane = new JTabbedPane();
            try {
                Image image = ImageIO.read(new File("images/terrain.jpg"));
                ImageIcon icon = new ImageIcon(image);
                JLabel label = new JLabel(icon);
                JPanel panel = new JPanel(new GridLayout(0,1,5,5));
                panel.add(label);
                JScrollPane jsp = new JScrollPane(panel);
                tabbedPane.addTab("Image",jsp);
                JPanel anotherPanel = new JPanel();
                JLabel label2 = new JLabel("Second Panel");
                anotherPanel.add(label2);
                 label2.setFont(new Font("San Serif",Font.BOLD, 40));
                tabbedPane.add("Label",anotherPanel);
                mainPanel.add(tabbedPane, BorderLayout.CENTER);
                JToolBar tBar = new JToolBar();
                tBar.add(new Button("OK"));
                tBar.add(new Button("Maybe"));
                tBar.add(new Button("No"));
                mainPanel.add(tBar, BorderLayout.SOUTH);
                  } catch (IOException e) {
                e.printStackTrace();
        public static void main(String[] args) {
            Runnable runnable = new Runnable() {
                public void run() {
                    ImageInTabbedScrollTest testFrame = new ImageInTabbedScrollTest();
                    testFrame.setSize(new Dimension(600,600));
                    testFrame.setLocationRelativeTo(null);
                    testFrame.setDefaultCloseOperation(EXIT_ON_CLOSE);
                    testFrame.setVisible(true);
            SwingUtilities.invokeLater(runnable);
    }

  • '...' not appearing in obscured table cell when using custom renderer.

    Hello all -
    I am using a custom JPanel as a cell renderer in a JTable to display two icons per cell. Unfortunately, I am running into a problem that occurs when resizing a column such that the width of the column is less than the size of the cell content. Normally, when resizing a cell in this manner, it will start to cut off the text within the cell and add '...' to signify that some material is obscured. However, using my cell renderer, the text simply cuts off with no indication whatsoever there is more content that is being hidden. I have tried looking through the JComponent code to find a function to overload but I haven't had much luck. Does anyone have any suggestions?
    For a simple example, compile and run the following code and try resizing the two columns. You should be able to notice the difference.
    Thanks,
    - Alex
    import java.awt.*;
    import java.awt.image.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TwoIcons extends JFrame {
         public static void main(String[] args){
              createIcons();
              SwingUtilities.invokeLater
                   new Runnable()
                        public void run() {
                             new TwoIcons();
         public TwoIcons(){
              super("Test");
              DefaultTableModel tm = new DefaultTableModel(
                   new Object[][]{
                        {new IconPair("cross", "cross"), "just a string"},
                        {new IconPair("circle", "cross"),"just another string"},
                        {new IconPair("String", "circle"),"yet another string"}
                   }, new String[]{"Two Icons","String"}){
                   public Class getColumnClass(int columnIndex){
                        if(columnIndex==0){
                             return IconPair.class;
                        else
                             return super.getColumnClass(columnIndex);
              JTable table = new JTable(tm);
              final Color bg = table.getBackground();
              table.setDefaultRenderer(IconPair.class, new TableCellRenderer(){
                        RendererPanel renderer = new RendererPanel(bg);
                        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                             renderer.setIcons((IconPair)value);
                             return  renderer;
              JScrollPane scp = new JScrollPane(table);
              add(scp);
              setSize(400,100);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              pack();
              setVisible(true);
         class RendererPanel extends JPanel{
              JLabel icon1, icon2;
              RendererPanel(Color bg){
                   setLayout(new BoxLayout(this,BoxLayout.LINE_AXIS) );
                   icon1=new JLabel();
                   icon2=new JLabel();
                   add(icon1);
                   add(icon2);
                   setBackground(bg);
              public void setIcons(IconPair value) {
                   icon1.setIcon(value.i1);
                   icon1.setToolTipText("Icon 1");
                   icon2.setIcon(value.i2);
                   icon2.setToolTipText("Icon 2");
                   //uncomment next 2 lines if you want text as well
                   icon1.setText(value.s1);
                   icon2.setText(value.s2);
         class IconPair {
              public Icon i1,i2;
              public String s1,s2;
              IconPair(String s1, String s2){
                   this.i1=(Icon)icons.get(s1);
                   this.i2=(Icon)icons.get(s2);
                   this.s1=s1;
                   this.s2=s2;
         static Map icons = new HashMap();
         public static  void createIcons(){
              Image img = new BufferedImage(10,10, BufferedImage.TYPE_INT_ARGB);
              Graphics2D g2=(Graphics2D)(img.getGraphics());
              g2.setColor(Color.BLUE);
              g2.drawLine(0,0,10,10);
              g2.drawLine(0,10,10,0);
              icons.put("cross",new ImageIcon(img));
              img = new BufferedImage(10,10, BufferedImage.TYPE_INT_ARGB);
              g2=(Graphics2D)(img.getGraphics());
              g2.setColor(Color.ORANGE);
              g2.drawOval(1,1,8,8);
              icons.put("circle",new ImageIcon(img));
    }

    Things aren't resizable in your layout for the custom renderer. Here's your code working as you want (I think)
    import java.awt.*;
    import java.awt.image.*;
    import java.util.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class TwoIcons extends JFrame {
         public static void main(String[] args){
              createIcons();
              SwingUtilities.invokeLater
                   new Runnable()
                        public void run() {
                             new TwoIcons();
         public TwoIcons(){
              super("Test");
              DefaultTableModel tm = new DefaultTableModel(
                   new Object[][]{
                        {new IconPair("cross", "cross"), "just a string"},
                        {new IconPair("circle", "cross"),"just another string"},
                        {new IconPair("String", "circle"),"yet another string"}
                   }, new String[]{"Two Icons","String"}){
                   public Class getColumnClass(int columnIndex){
                        if(columnIndex==0){
                             return IconPair.class;
                        else
                             return super.getColumnClass(columnIndex);
              JTable table = new JTable(tm);
              final Color bg = table.getBackground();
              table.setDefaultRenderer(IconPair.class, new TableCellRenderer(){
                        RendererPanel renderer = new RendererPanel(bg);
                        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                             renderer.setIcons((IconPair)value);
                             return  renderer;
              JScrollPane scp = new JScrollPane(table);
              getContentPane().add(scp);
              setSize(400,100);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              pack();
              setVisible(true);
         class RendererPanel extends JPanel{
              JLabel icon1, icon2;
              RendererPanel(Color bg){
                   setLayout(new BoxLayout(this,BoxLayout.LINE_AXIS) );
                   icon1=new JLabel();
                   icon2=new JLabel();
                   add(icon1);
                   add(icon2);
                   icon1.setMinimumSize(new Dimension(0, 0));
                   icon2.setMinimumSize(new Dimension(0, 0));
                   icon1.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
                   icon2.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
                   setBackground(bg);
              public void setIcons(IconPair value) {
                   icon1.setIcon(value.i1);
                   icon1.setToolTipText("Icon 1");
                   icon2.setIcon(value.i2);
                   icon2.setToolTipText("Icon 2");
                   //uncomment next 2 lines if you want text as well
                   icon1.setText(value.s1);
                   icon2.setText(value.s2);
         class IconPair {
              public Icon i1,i2;
              public String s1,s2;
              IconPair(String s1, String s2){
                   this.i1=(Icon)icons.get(s1);
                   this.i2=(Icon)icons.get(s2);
                   this.s1=s1;
                   this.s2=s2;
         static Map icons = new HashMap();
         public static  void createIcons(){
              Image img = new BufferedImage(10,10, BufferedImage.TYPE_INT_ARGB);
              Graphics2D g2=(Graphics2D)(img.getGraphics());
              g2.setColor(Color.BLUE);
              g2.drawLine(0,0,10,10);
              g2.drawLine(0,10,10,0);
              icons.put("cross",new ImageIcon(img));
              img = new BufferedImage(10,10, BufferedImage.TYPE_INT_ARGB);
              g2=(Graphics2D)(img.getGraphics());
              g2.setColor(Color.ORANGE);
              g2.drawOval(1,1,8,8);
              icons.put("circle",new ImageIcon(img));
    }Note that the ... is a function of the JLabel when it is too small to render its text.

  • Help: Jbo Exception non blocking when using table cell renderer?

    Hi,
    JClient 9.5.2.
    When using Table Cell Renderer on an table cell attribute that is defined mandatory and activating the insert button, the (oracle.jbo.AttrValException) JBO-27014 exception is caught but it is not blocking and a new row is still inserted.
    The JClient component demo, table attribute list, has the same behaviour.
    You can add multiple rows even if not all required attributes have been documented.
    Can a Swing specialist help me on this one?
    Example of Table Cell Renderer:
    public class TableBasicStatusRenderer extends DefaultTableCellRenderer
    public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus,
    int row, int column)
    JLabel lb = new JLabel((String) StaticData.getStatusName(value)); // retrieves label from Map
    return lb;
    Regards
    Frederic

    Hi,
    I found something interesting, it could be a WORKAROUND!
    I noticed that in another detail panel with table layout the JBO exception was blocking and adding another row before completing the row was NOT possible.
    In the create method of the entity object of the displayed View Object I iterate over the detail row iterator to retrieve a maximum value.
    By the end of the method the pointer is positionned after the last row.
    So I added to the detail panel that doesn't block following code:
    In create method of detail Entity Object Impl (only one entity object involved for this View)
    // Retrieve master EntityObjectImpl from association:
    PostalTariffImpl postalTariffImpl = getPostalTariffAssoc();
    // Retrieve detail default row iterator
    RowIterator ri = postalTariffImpl.getPostalDetailGroupAssoc();
    // Position pointer after last row
    ri.last();
    ri.next();
    Question: Why does this solve the problem?
    Regards
    Frederic
    PS Les mysteres de l'informatique!

  • Help displaying an image using the canvas!!!!!!!!

    Hey guys
    I don't know whether I am not grasping some concepts well.I have been going mad trying to get the code working
    Here is the code
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    import java.io.*;
    * @author Administrator
    * @version
    public class MyMIDlet extends javax.microedition.midlet.MIDlet implements CommandListener{
    private Display display;
    private MyCanvas canvas;
    private Command exitcommand = new Command("Exit",Command.SCREEN,1);
    private Image source;
    public MyMIDlet() {
    protected void startApp() throws MIDletStateChangeException{
    if (display == null){
    initMIDlet();
    protected void pauseApp() {
    protected void destroyApp(boolean unconditional)throws MIDletStateChangeException {
    exitMIDlet();
    public void commandAction(Command c, Displayable d) {
    if (c == exitcommand){
    exitMIDlet();
    protected void initMIDlet() {
    display = Display.getDisplay(this);
    canvas = new MyCanvas(this);
    System.err.println("Canvas instiated succesfully");
    canvas.addCommand(exitcommand);
    canvas.setCommandListener(this);
    display.setCurrent(canvas);
    public void exitMIDlet() {
    notifyDestroyed();
    import javax.microedition.lcdui.*;
    import javax.microedition.midlet.*;
    import java.io.*;
    public class MyCanvas extends Canvas implements Runnable {
    private MIDlet midlet;
    private Image offscreen;
    private Image currentimage;
    private Graphics g;
    //MID profile application
    /** Creates a new instance of MyCanvas */
    public MyCanvas(MIDlet midlet) {
    this.midlet = midlet;
    try{
    currentimage = Image.createImage("/bird0.png");
    }catch(IOException e){
    System.err.println(e.getMessage());
    if (currentimage!= null){
    System.err.println("Image create successfully");
    }else{
    System.err.println("Image not created");
    try{
    Thread t = new Thread(this);
    t.start();
    }catch(Execption e){}
    protected void paint(Graphics g){
    Graphics saved = g;
    int x = getWidth();
    int y = getHeight();
    g.setColor(255,255,255);
    g.drawImage(currentimage,x,y,g.TOP|g.VCENTER);
    public void run() {
    repaint();
    I know for a fact that the Canvas class 's paint method is called by the system and not the application. This poses a problem for me because I am not sure how to pass the image to the piant method, so that it can be painted.
    When I run the program(using J2ME wtk04), this is the outcome.
    Image created succesfully
    Canvas instiatiated successfully
    null
    Here are my questions
    1) when is the paint method precisely called by the system?after a reference to the canvas class is created?
    2) is it wise to create the image when instiating the canvas class?( initially created the image using a separate thread)-when sould the image be created?
    3)how to let the application know when to use the image when painting the display area?
    I am just trying the logistics here. It is very crucial to me to understand the bolts of this as the core f my project fouses on the man machine interface development.(For the project, the cilent application is quering for the map using HTTP)
    I use a png file of size 161 bytes. Is that too big for testing purposes.
    I would all the help that I can get. thanks in advance

    1) when is the paint method precisely called by the system?after a reference to the canvas class is created?
    After the canvas is set as the current display, and after that, after the repaint() is called.
    2) is it wise to create the image when instiating the canvas class?( initially created the image using a separate thread)-when sould the image be created?
    It's better to create the image in the very begining of the program e.g. in the midlet initialization. You can call the created image as often as you like later on
    3)how to let the application know when to use the image when painting the display area?
    you have to tell it :))
    you can use if-then, switch, or anything else
    and you can use clipping too

  • Hello find my mac displays offline when I'm using the actual mac I want to find at the time, can anyone help?, Hello find my mac displays offline when I'm using the actual mac I want to find at the time, can anyone help?

    Hello find my mac displays offline when I'm using the actual mac I want to find at the time, can anyone help?, Hello find my mac displays offline when I'm using the actual mac I want to find at the time, can anyone help?

    Welcome to the Apple community.
    Is your Mac connected to the network via ethernet. Mac's thatareI connected via ethernet cannot be located using "find my phone".

  • Displaying ALV output in whole screen when using with custom container

    I have created a custom container and displaying output of a table in the ALV format using call method grid->set_table_for_first_display. But the output does not display in the entire screen. I want the output to cover the whole screen depending on user screen resolution. The code is given below for reference.
    create object grid
        exporting
        i_parent = g_custom_container.
        call method grid->set_table_for_first_display
          exporting
            IS_VARIANT = ld_variant
            I_SAVE    = 'A'
            is_layout = layout_alv_grid
          changing
            it_outtab                     = final_display_itab
            it_fieldcatalog               = itab_fieldcatalog

    Hello,
    DATA: go_splitter        TYPE REF TO cl_gui_splitter_container,
              go_container     TYPE REF TO cl_gui_container,
              go_grid             TYPE REF TO cl_gui_alv_grid.
        CREATE OBJECT go_splitter
             EXPORTING
               parent    = cl_gui_container=>default_screen
               rows       = 1
               columns  = 1
               metric     = '0001'.
        go_container = go_splitter->get_container( row = 1 column = 1 ).
        CREATE OBJECT go_grid
             EXPORTING
             i_parent = go_container.
    Regards,
    Ernst

  • I have been using GRAB to capture screen displays.  It has just stopped working since the last OSX Upgrade.  Can anyone, please help restore functionality?

    I have been using GRAB to capture screen displays.  It has just stopped working since the last OSX Upgrade.  Can anyone, please help restore functionality?

    Thanks for that.  I did as suggested but when I tried again, it still did not work.  Another  com.apple.Grab.plist appeared in the Library.
    I now have the following files in Library
    file://localhost/Users/peterpatel/Library/Preferences/com.apple.Grab.LSSharedFil eList.plist
    file://localhost/Users/peterpatel/Library/Preferences/com.apple.Grab.LSSharedFil eList.plist.lockfile
    file://localhost/Users/peterpatel/Library/Preferences/
    file://localhost/Users/peterpatel/Library/Preferences/com.apple.Grab.plist.lockf ile
    What do you suggest I do now?

Maybe you are looking for