Individual cell heights in JList

hi!
i'm trying to write a cellrenderer for a JList, which can show different cell heights.
i.e. in unselected mode, i only want to show a name of a person; in selected mode, i want do show the name of the person AND some other details in the same cell (like the "add and remove programs"-dialog of Windows XP when you select a program to uninstall (it shows then some information about usage etc.))
if(!isSelected) {
    /* Not selected */
    setPreferredSize(new Dimension(0,25));
    setBackground(Color.BLUE);
} else {
    /* Selected: */
    setPreferredSize(new Dimension(0,45));
    setBackground(Color.RED);                      
}i tried this code in the getListCellRendererComponent(...)-method, but the JList only uses the first size (25) ... i tried to set the JList-propertie fixedCellHeight to -1, but no changes....
does anybody know how i can solve my problem?
thx a lot & greetz
swissManu

thank you for your hints! ... i think i will take some time to develop a Model for my DetailList....
if you like, you can use my improved code.... here it is:
here is the mainpart, the DetailList.java
* Created on 02.12.2004
package detaillist;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Insets;
import java.awt.LayoutManager;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Vector;
import javax.swing.JPanel;
* Die Items einer DetailList k�nnen per Klick "aufgeklappt" werden und zeigen
* anschliessend weitere Deteils zum entsprechenden Item.<br>
* Um eigene DetailListItem's mit eigener Darstellung zu erstellen kann einfach
* eine Klasse welche von DetailListItem ableitet erstellt werden.<br>
* <br>
* hoverSelection:<br>
* Mit setHoverSelection(true) wird der Hover-Modus aktiviert. Der Benutzer muss
* anschliessend nur noch �ber Items mit der Maus fahren um diese aufzuklappen.<br>
* <br>
* multiSelection:<br>
* Per setMultiSelection(true) wird dem Benutzer erm�glicht, mehrere Items auf
* einmal aufzuklappen.<br>
* <br>
* ACHTUNG! hoverSelection & multiSelection k�nnen nicht gleichzeitig aktiviert
*          sein!
* @author Manuel Alabor; adapted from Pierre LE LANNIC (weebib)
* @version 1.1
public class DetailList extends JPanel {
    /* Eigenschaften: */
    private boolean hoverSelection = false;
    private boolean multiSelection = false;
    /* Objekte: */
    private Vector selectedItems;
    private ItemSelectionListener itemListener;
    public DetailList() {
          super(new ListLayout());
        setOpaque(true);
          setBackground(Color.WHITE);
          itemListener = new ItemSelectionListener();
          selectedItems = new Vector();
     * Setzt das markierte Item und klappt das betreffende auf bzw. zu.<br>
     * Wird ein aufgeklapptes Item nochmals angeklickt, wird dieses zugeklappt.<br>
     * <br>
     * Ist multiSelection == true, so k�nnen mehrere Items auf einmal aufge-
     * klappt sein. Falls multiSelection == false, so wird das bereits offene
     * Item geschlossen.
     * @param item
     private synchronized void setSelectedItem(DetailListItem item) {
          if (item == null) return;
          /* Offenes Item bei erneutem Klick schliessen: */
          // Offenes Item schliessen und aus der selectedItems-Liste entfernen.
          for (int i = 0; i < selectedItems.size(); i++) {
              DetailListItem selItem = (DetailListItem)selectedItems.get(i);
              if(item == selItem) {
                  if(item.isExpanded()) {
                      item.setExpanded(false);
                      selectedItems.remove(i);
                      System.out.println(selectedItems.size());
                      return;
          /* Ausgeklappte Items zuklappen wenn ein anderes gew�hlt wurde: */
          // Wenn nicht mehrere offene Items erlaubt sind (!multiSelection),
          // werden hier alle anderen Items zugeklappt (falls vorhanden)
          if(selectedItems.size() > 0 && !multiSelection) {
              for (int i = 0; i < selectedItems.size(); i++) {
                  DetailListItem tmpItem = (DetailListItem)selectedItems.get(i);
                  if(item != tmpItem) {
                      tmpItem.setExpanded(false);
                      selectedItems.remove(i);
          /* Geklicktes Item ausklappen: */
          item.setExpanded(true);
          selectedItems.add(item);
          System.out.println(selectedItems.size());
      * F�gt dieser DetailList ein neues DetailListItem hinzu.<br>
      * Es wird dem neuen Item automatisch der ItemSelectionListener dieser
      * DetailList zugewiesen.
      * @param newItem
     public void addItem(DetailListItem newItem) {
         newItem.addMouseListener(itemListener);
         add(newItem);
          revalidate();
          repaint();
     /* Anonyme Klassen: */
      * Diese anonyme Klasse fungiert als Klick-Listener f�r die DetailListItem's
      * dieser DetailList.
      * @author Manuel Alabor
     private class ItemSelectionListener extends MouseAdapter {
          public void mouseClicked(MouseEvent e) {
               Object o = e.getSource();
               if(!hoverSelection) {
                    if (o instanceof DetailListItem) {
                         setSelectedItem((DetailListItem)o);
         * Erm�glicht einen "Hover"-Effekt welche bewirkt dass ein Item auf-
         * geklappt wird sobald sich der Mauszeiger dar�ber befindet.<br>
         * Ist multiSelection aktiv, wird hier nichts unternommen, auch wenn
         * hoverSelection aktiviert ist.
          public void mouseEntered(MouseEvent e) {
               if(hoverSelection && !multiSelection) {
                  Object o = e.getSource();
                    if (o instanceof DetailListItem) {
                        // Wenn ein Item offen ist, soll dieses nicht zugeklappt
                        // werden wenn der Benutzer erneut mit dem Cursor auf das
                        // Item f�hrt.
                        if(selectedItems.size() == 1) {
                            if(selectedItems.get(0) != o) {
                                setSelectedItem((DetailListItem)o);
                         } else {
                             setSelectedItem((DetailListItem)o);
      * Dieser LayoutManager wird benutzt um alle DetailListItems in einer Listen-
      * Anordnung anzuzeigen.
      * @author Manuel Alabor
     private static class ListLayout implements LayoutManager {
          public void removeLayoutComponent(Component comp) {}
          public void addLayoutComponent(String name, Component comp) {}
          public void layoutContainer(Container target) {
               synchronized (target.getTreeLock()) {
                    Insets insets = target.getInsets();
                    int nmembers = target.getComponentCount();
                    int x = insets.left;
                    int y = insets.top;
                    for (int i = 0; i < nmembers; i++) {
                         Component m = target.getComponent(i);
                         if (m.isVisible()) {
                              Dimension d = m.getPreferredSize();
                              m.setBounds(x, y, target.getWidth(), d.height);
                              y += d.height;
          public Dimension preferredLayoutSize(Container target) {
               synchronized (target.getTreeLock()) {
                    Dimension dim = new Dimension(0, 0);
                    int nmembers = target.getComponentCount();
                    for (int i = 0; i < nmembers; i++) {
                         Component m = target.getComponent(i);
                         if (m.isVisible()) {
                              Dimension d = m.getPreferredSize();
                              dim.height += d.height;
                              dim.width = Math.max(dim.width, d.width);
                    Insets insets = target.getInsets();
                    dim.width += insets.left + insets.right;
                    dim.height += insets.top + insets.bottom;
                    return dim;
          public Dimension minimumLayoutSize(Container target) {
               synchronized (target.getTreeLock()) {
                    Dimension dim = new Dimension(0, 0);
                    int nmembers = target.getComponentCount();
                    for (int i = 0; i < nmembers; i++) {
                         Component m = target.getComponent(i);
                         if (m.isVisible()) {
                              Dimension d = m.getMinimumSize();
                              dim.height += d.height;
                              dim.width = Math.max(dim.width, d.width);
                    Insets insets = target.getInsets();
                    dim.width += insets.left + insets.right;
                    dim.height += insets.top + insets.bottom;
                    return dim;
     /* Getter- & Setter-Methoden: */
    public boolean isHoverSelection() {
        return hoverSelection;
    public void setHoverSelection(boolean hoverSelection) {
        multiSelection = false;
        this.hoverSelection = hoverSelection;
    public boolean isMultiSelection() {
        return hoverSelection;
    public void setMultiSelection(boolean multiSelection) {
        hoverSelection = false;
        this.multiSelection = multiSelection;
}this is the DetailListItem.java ... the prototype for individual items:
* Created on 02.12.2004
package detaillist;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Toolkit;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
* Ein Standart-Item f�r DetailList.<br>
* Um eigene Items zu realisieren kann ganz einfach von dieser Klasse abgleitet
* werden und anschliessend das Item individualisiert werden. (Beispiel siehe
* DetailListAdressItem)
* @author Manuel Alabor
* @version 1.0
* @see detaillist.DetailListAdressItem
public abstract class DetailListItem extends JPanel {
    /* Components: */
    protected JLabel lblTitle;
    protected JPanel details;
    private Component margin;
    /* Eigenschaften: */
    protected boolean expanded = false;
    protected int unexpandedHeight = 18;
     * Standart-Konstruktor mit Angabe f�r den Titel sowie ein Symbol.
     * @param text
     * @param icon
    public DetailListItem(String title, String icon) {
        super(new BorderLayout());
        /* Item anpassen: */
        setOpaque(true);
        /* Titel initialisieren: */
        lblTitle = new JLabel(title);
        if(!icon.equals("")) {
            lblTitle.setIcon(new ImageIcon(Toolkit.getDefaultToolkit().createImage(icon)));
        /* details-Panel initialisieren & vorbereiten: */
        details = new JPanel();
        margin = Box.createHorizontalStrut(10);
        /* Components anordnen: */
        add(lblTitle, BorderLayout.NORTH);
        add(margin, BorderLayout.WEST);
        add(details, BorderLayout.CENTER);
        update();
     * Verk�rzter Konstruktor ohne angabe f�r ein Symbol.
     * @param text
    public DetailListItem(String text) {
        this(text, "");
     * Klappt das Item entweder auf oder zu.
     private void update() {
          margin.setVisible(expanded);
          details.setVisible(expanded);
          if (expanded) {
               setBackground(Color.LIGHT_GRAY);
               setBorder(BorderFactory.createLineBorder(Color.BLACK));
          } else {
               setBackground(Color.WHITE);
               setBorder(BorderFactory.createLineBorder(Color.WHITE));
          this.revalidate();
          this.repaint();
      * Im zugeklappten Zustand sollte per unexpandedHeight-Variabel die H�he des
      * Items definiert werden, da es ansonsten jenachdem zu unsch�nen Effekten
      * kommen kann.<br>
      * F�r ein normales Item betr�gt die "Standarth�he" 18pixel.
    public Dimension getPreferredSize() {
        Dimension dim = super.getPreferredSize();
        /* H�he: */
        // Wenn das Item nicht ausgeklappt ist, unexpandedHeight als h�he
        // nehmen:
        if(!expanded) {
            dim.height = unexpandedHeight;
        return dim;
    /* Getter- & Setter-Methoden: */
    public String getTitle() {
        return lblTitle.getText();
    public void setTitle(String text) {
        lblTitle.setText(text);
    public boolean isExpanded() {
        return expanded;
    public void setExpanded(boolean expanded) {
        this.expanded = expanded;
        update();
}here my first basic sample for a item:
* Created on 02.12.2004
package detaillist;
import java.awt.Font;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import com.jgoodies.forms.factories.Borders;
import com.jgoodies.forms.layout.CellConstraints;
import com.jgoodies.forms.layout.FormLayout;
* Ein DetailListItem mit Texteingabe-Feld
* @author Manuel Alabor
* @version 1.0
public class DetailListTextItem extends DetailListItem {
    /* Components: */
    private JTextArea txtText;
     * Standartkonstruktor.
     * @param text
     * @param name
     * @param adress
     * @param email
     * @param photo
    public DetailListTextItem(String title, String icon, String text) {
        super(title, icon);
        unexpandedHeight = 20;  // H�he in zugeklapptem Modus festlegen
        /* lblTitle anpassen: */
        lblTitle.setFont(new Font("Tahoma",Font.BOLD + Font.ITALIC,11));
        lblTitle.setBorder(Borders.createEmptyBorder("1dlu,1dlu,1dlu,1dlu"));
        /* Werte �bernehmen: */
        txtText = new JTextArea(text);
        /* FormLayout f�r details erstellen: */
        details.setLayout(new FormLayout("d:g", "f:30dlu:g"));
        CellConstraints cc = new CellConstraints();
        /* Components hinzuf�gen: */
        details.setBorder(Borders.DLU2_BORDER);
        details.add(new JScrollPane(txtText), cc.xy(1,1));
}and here a testapp:
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import detaillist.DetailList;
import detaillist.DetailListItem;
import detaillist.DetailListTextItem;
* Created on 02.12.2004
* @author Manuel Alabor
public class DetailListTest {
    public static void main(String[] args) {
        JFrame frame = new JFrame();
        JPanel contentPane = (JPanel)frame.getContentPane();
        contentPane.setLayout(new BorderLayout());
        final DetailList list = new DetailList();
        contentPane.add(new JScrollPane(list), BorderLayout.CENTER);
        JButton btnAdd = new JButton("Add Textitem...");
        btnAdd.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent arg0) {
                 DetailListItem item = new DetailListTextItem("Text-Item", "small_gear.png", "Dies ist ein Testitem");
                 list.addItem(item);
        contentPane.add(btnAdd, BorderLayout.SOUTH);
        JPanel options = new JPanel(new BorderLayout());
        final JCheckBox chkHover = new JCheckBox("HoverSelection");
        final JCheckBox chkMulSel = new JCheckBox("MultiSelection");
        chkHover.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                list.setHoverSelection(chkHover.getModel().isSelected());
                chkMulSel.getModel().setSelected(false);
        options.add(chkHover, BorderLayout.NORTH);
        chkMulSel.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                chkHover.getModel().setSelected(false);
                list.setMultiSelection(chkMulSel.getModel().isSelected());
        options.add(chkMulSel, BorderLayout.SOUTH);
        contentPane.add(options, BorderLayout.NORTH);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setSize(262,250);
        frame.setLocation(200,200);
        frame.show();
}hope you like it :)

Similar Messages

  • JList Cell Height Problem

    I am trying to use a customer cell renderer for a JList. It sort of works, but my cell heights are incorrect because when a cell is selected the JPanel returned from my cell renderer need more space to paint on than an unselected list item.
    Sample code below demontrates the problem - use it as the cell renderer for something and make some selections - you can see that when the text is enlarged when the cell is selected, it is not resized to accommodate the larger text.
    I've tried various combinations of setSize, revalidate etc at various points but nothing helps...
    import java.awt.*;
    import javax.swing.*;
    import javax.swing.event.*;
    public class TestListCellRenderer extends JPanel implements ListCellRenderer {
         JLabel l;
         public TestListCellRenderer() {
              setLayout( new BorderLayout() );
              l = new JLabel( );
              setBorder( BorderFactory.createLineBorder( Color.BLACK ) );
              add( l, BorderLayout.NORTH );
         public Component getListCellRendererComponent(
                   JList list,
                   Object value,
                   int index,
                   boolean isSelected,
                   boolean hasFocus ) {
              if( isSelected == false ) {
                   l.setText( value.toString() );
                   l.setFont( new Font( "Serif", Font.BOLD, 12 ) );
              else {
                   l.setText( value.toString() );
                   l.setFont( new Font( "Serif", Font.BOLD, 18 ) );
              return this;
    }

    I came across this thread when I was having a similar problem. I have found a way to get it to work.
    My problem was this: I have a list of news headlines. When I increased the font size of the items in my list I needed to increase the height of each cell in the list so that the headline wouldn't get cut off top and bottom by the restrictive height of the list cell.
    Solution is to use setFixedCellHeight(int height) from the JList class.
    In my case I find set the fixed cell height in 3 places.
    the constructor - when the list is being created
    the cell renderer method - when the list is being rendered
    in an action listener method - to act when a user changes the size of the font.
    The code excerpt below is a chopped down version of the working code but gives you an idea.
    public class NewsWindow implements ListSelectionListener {
         /** Component which holds the headlines */
         public JList list;
         public NewsWindow(Container parent, WindowProperties properties) {
              DefaultListModel listModel = new DefaultListModel();
              list = new JList(listModel);
              list.setCellRenderer(new HeadlineCellRenderer());
              bounceListCellHeight(); // set the correct list cell height up front
         /** when the font size has changed this method is eventually called via a super class */
         public void fontSizeHasChangedListener() {         
         bounceListCellHeight();
         /** THIS METHOD SETS THE HEIGHT OF THE LIST CELLS */     
         public void bounceListCellHeight() {
              int height = getFontMetrics(getNewsFont()).getHeight(); // get the height of the font
              list.setFixedCellHeight(height + 10); // set the cell height
         * Inner class to render the list.
         private class HeadlineCellRenderer extends JLabel implements ListCellRenderer {
              public HeadlineCellRenderer() {
              setOpaque(true);
              public Component getListCellRendererComponent(JList myList, Object value, int index, boolean isSelected, boolean cellHasFocus) {
              bounceListCellHeight(); // call the method to set the list cell height
              setText(getHeadlineText());
              this.revalidate();
              setFont(getNewsFont());
              return this;
    Hope this is of some help.

  • Tables (Individual Cells) & CSS

    I have a table in my webpage, which has 1 row and 5 columns
    (just 5 cells within the table), when I select the whole table, and
    apply the Style sheet, I get this code, I understand
    why it is doing that, but the reason I provided this, was
    because when I did the first method (applying it to the
    whole table, nothing would show in the browser, just the
    defaulted background etc.., however when I applied it to each
    individual cell, it would show in the browser, any reasons to this?
    Thanks:
    <tr class="navigationBar">
    <td width="20%" height="33"><div
    align="center"><a
    href="index.html">Home</a></div></td>
    <td width="20%" height="33"><div
    align="center"><a
    href="News.html">News</a></div></td>
    <td width="20%" height="33"><div
    align="center"><a
    href="cheats.html">Cheats</a></div></td>
    <td width="20%" height="33"><div
    align="center"><a href="new downloads.html">New
    Downloads</a></div></td>
    <td width="20%" height="33"><div
    align="center"><a href="about us.html">About
    Us</a></div></td>
    </tr>
    However, if I click each individual cell (Ctrl + Click), then
    apply the style sheet, I get this code:
    <tr>
    <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    href="index.html">Home</a></div></td>
    <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    href="News.html">News</a></div></td>
    <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    href="cheats.html">Cheats</a></div></td>
    <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    href="new downloads.html">New
    Downloads</a></div></td>
    <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    href="about us.html">About Us</a></div></td>
    </tr>
    p.s. sorry the code has been copied and pasted in, I could
    not get the 'Attach Code" to work!

    In the first case the class is applied to <tr>, which
    cannot show a
    background image in IE. In the second case, the class is
    applied to each
    individual cell, which can show the background image. In
    fact, in neither
    case did you apply the class to the whole table (i.e., the
    <table> tag).
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.dreamweavermx-templates.com
    - Template Triage!
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    http://www.macromedia.com/support/search/
    - Macromedia (MM) Technotes
    ==================
    "The Kelvinater" <[email protected]> wrote
    in message
    news:[email protected]...
    >I have a table in my webpage, which has 1 row and 5
    columns (just 5 cells
    > within the table), when I select the whole table, and
    apply the Style
    > sheet, I
    > get this code, I understand
    why it is doing that, but the reason I
    > provided this, was because when I did the first method
    (applying it to the
    >
    whole table, nothing would show in the browser, just the
    defaulted
    > background etc.., however when I applied it to each
    individual cell, it
    > would
    > show in the browser, any reasons to this? Thanks:
    >
    >
    <tr class="navigationBar">
    > <td width="20%" height="33"><div
    align="center"><a
    >
    href="index.html">Home</a></div></td>
    > <td width="20%" height="33"><div
    align="center"><a
    >
    href="News.html">News</a></div></td>
    > <td width="20%" height="33"><div
    align="center"><a
    >
    href="cheats.html">Cheats</a></div></td>
    > <td width="20%" height="33"><div
    align="center"><a href="new
    > downloads.html">New
    Downloads</a></div></td>
    > <td width="20%" height="33"><div
    align="center"><a href="about
    > us.html">About Us</a></div></td>
    > </tr>
    >
    > However, if I click each individual cell (Ctrl + Click),
    then apply the
    > style
    > sheet, I get this code:
    >
    > <tr>
    > <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    >
    href="index.html">Home</a></div></td>
    > <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    >
    href="News.html">News</a></div></td>
    > <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    >
    href="cheats.html">Cheats</a></div></td>
    > <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    > href="new downloads.html">New
    Downloads</a></div></td>
    > <td width="20%" height="33"
    class="navigationBar"><div align="center"><a
    > href="about us.html">About
    Us</a></div></td>
    > </tr>
    >
    > p.s. sorry the code has been copied and pasted in, I
    could not get the
    > 'Attach
    > Code" to work!
    >

  • I want to set up my spreadsheet to display 2 digits to the right of the decimal, even if zeros, and not have to do it to each individual cell.

    I want to set up my spreadsheet to display two digits to the right of the decimal point, even if zeros, and not have to do it for each individual cell.

    Select all the cells you want formatted that way (or the entire table if that's what you want)
    Open the cell inspector
    Set the format to "number" with 2 decimal places

  • Making OnLoad work in individual cells in multiple rows

    Dear Raj et al...
    thanks for your help with getting the java applet (JMOL) working in individual cells/rows in report tables.
    I now need some help with getting OnLoad to work in each row.
    I am able to make it work in an HTML region (not in a report table) where I use <body #ONLOAD#> in the HTML region and OnLoad="document.jmol.loadinline(getElementById('P16_text').value)"; in the 'On Load' region in page template.
    However if I use OnLoad="document.jmol#AUTOKEY#.loadinline(getElementById('f01_#ROWNUM#').value)";
    and put body tags in the Report Attributes\Column Formatting\html expression region where I have embeded the applet tags it doesn't work.
    I don't think the #AUTOKEY# and #ROWNUM# are the problem as I also tried explicitly naming the objects:
    OnLoad="document.jmol1.loadinline(getElementById('f01_1').value)";
    and it still didn't work.
    Again any suggestions will be greatly appreciated!
    -Dave

    Actually I take that back...
    "I don't think the #AUTOKEY# and #ROWNUM# are the problem as I also tried explicitly naming the objects:
    OnLoad="document.jmol1.loadinline(getElementById('f01_1').value)"; and it still didn't work."
    The reason this didn't work is that I had two javascript calls in the on load section and I obviously didn't format them properly (the first worked not the second).
    In any case, this worked once it was made the only javascript call in the on load section.
    When I tried to use #AUTOKEY# or #ROWNUM# these were then flagged with an "Invalid Character" error.
    Do you have any suggestions as how to have variable names put in the "OnLoad" statement and will it work for the n rows that are queried?
    Thanks a lot!
    -Dave

  • How do you change the colors of individual cells within a 2D array?

    How do you change the colors of individual cells within a 2D array of numeric indicators?
    I want the VI to check a data value and if it is failing, white out a square at a specific index coordinate.  I have it working with color boxes, but I'm not sure how to use the property node function, to change the color of individual cells, by coordinates.
    I have attached the VI using color boxes. If you run the VI, the box corresponding to the Step control should turn white.
    I want to do the same thing, using numeric indicator boxes inside the array.
    Thanks for any suggestions...
    Attachments:
    Fill DME matrix.vi ‏95 KB

    Get rid of all these sequences! That's just bad form.
    Your code has a few logical problems. Why do you create a boolean array if you later only look at the last element (Yes, the FOR loop does nothing useful, except in the last iteration because your outputs are not indexing. All other iterations are useless, you only get the result of the last array element. My guess is that you want to color the index white if at least one of the numbers is out if range. Right?
    It is an absolute nightmare to manage all your numeric labels. Just read them from a 2D array. Now you can simply find the index of the matched elements and don't have to spend hours editing case structure conditions.
    Attached is a simple example how you would do what I meant (LV7.1). Modify as needed.
    Message Edited by altenbach on 04-04-2006 02:04 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    Fill_2DME_matrixMOD.vi ‏70 KB

  • Individual Cell Referencing

    Hi All,
    This thread actually follows on from another, which you can find here: Multiple tables feeding one table
    I don't believe it is possible to reference specific cells in a table in the manner you have described. You can reference the cells in an individual selected row of a table by using the corresponding field/column name. However, I don't think you can reference individual cells anywhere in the table like you can with Excel spreadsheets for example.
    Judging from the response quoted above, it will be possible to calculate values for Column4, if:
    Column4 = Column2 + Column3.
    Example 1
    --Column1Column2---Column3-----Column4
    Row 1 -
    80--
    85
    95--
    180
    Row 2 -
    100--
    130
    160--
    290
    Row 3 -
    200--
    210
    220--
    430
    Row 4 -
    200--240260--
    zzz
    But it will not be possible to calculate values for Column4 , if:
    Column4 =  a value from another row Column1 + value from row in Column2.
    Example 2
    --Column1Column2---Column3-----Column4
    Row 1 -
    80--
    8595--
    185
    Row 2 -
    100--
    130160--
    330
    Row 3 -
    200--
    210220--
    410
    Row 4 -
    200--240260--
    xyz
    It is highly desirable to be able to reference particular cells and their values in order to be able to manipulate them a little further (as this info is not available at BI Cube level; arrives from different BI queries).
    Is anyone able to confirm please?
    Regards,
    Chet.

    Hi Chet,
    Your understanding is accurate.  As far as I am aware, it is not possible to achieve Example 2 because there is no way of specifiying the row reference for a table cell in a Visual Composer formula.
    Since it is possible to perform cell calculations in BI, I would suggest that you try to define one BI query with all of the required information.  In order to perform cell calculations in the query it must have a fixed layout, i.e. a column structure and a row structure.
    Regards,
    Mustafa.

  • Setting cell editor for individual cell in JTable

    Hi there,
    I want to provide individual cell editor for my JTable. Basically, my JTable shows property names and values. I want to show different cell editors for different properties.
    I followed the advice in this post:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=423318
    but I have a question:
    I looked at the code of DefaultCellEditor. It just has a single editor component (the one provided in the constructor), so all the methods use the same component and certain aspects are customized for the type of component. Again, there can be only one type of component at a time.The problem that I am facing is that I will have different components for different row/column of the same table. So how do I implement some of the methods (for example, getCellEditorValue()), when I have multiple editor components?
    Also, how do I commit changes made by the user?
    I am extremely confused.
    Someone please help!
    Thanks.

    Actually, that's what I am currently doing.
    Here is my cell editor class:
    public class ObjectPropertyEditor extends DefaultCellEditor
           public ObjectPropertyEditor()
              super(new JTextField());
              Vector list = new Vector();
              list.add("Yes");
              list.add("No");
             myCombo = new JComboBox(list);
          public Component getTableCellEditorComponent(JTable table, Object value,
              boolean isSelected, int row, int column)
             String colName = (String)table.getValueAt(row,0);
             if(colName.equalsIgnoreCase("Leaf-Node?")) //if it is the "Leaf" property, return the combo box as the editor
                 return myCombo;
            else  //for all other properties, use JTextField of the super class
                return super.getTableCellEditorComponent(table,value,isSelected,row,column);
        private JComboBox myCombo;
    }The problem I have is that when I select a new item from the combo box, the new selection is not reflected in the tableModel. I don't know how I can achive that. I think I need the functionalities that DefaultCellEditor gives to its delegate when its constructor arguments is a combo box. But how can I get two different sets of functionalities (JTextField and JComboBox) ?
    Please help!
    Thanks.

  • Is it possible to set the cell height in a cell style?

    In the attached screenshot, the cell height is set to exactly 0.125. I put my cursor in the cell, then opened the cell styles panel and created a new cell style based on this cell. But when I apply the cell style to other cells, it does not apply the cell height. There were no overrides or other styles applied to the other cells. I also opened up the cell style definition from the cell styles panel, but don't see anywhere to set the cell height there either. Is there another way to do this that I am missing?

    It is possible - and it's fairly simple.
    To set the row height as part of the cell style, all you have to do is use the cell inset above and below. As long as you set the style as 'At least' then this works perfectly well for having predefined cell styles.
    I have been using this successfully for large financial documents for some time without any hitches. For example I use it to get separation between sections within the tables by having a style with extra space above, and similarly for totals rows at the bottom of the table. It can of course also apply different stroke styles at the same time. Having the style set as 'At Least' also allows for multiple line entries to still have the correct spacing above and below.
    So if you spend a bit of time calculating required heights and setting up your styles, then apply a keyboard shortcut to each style, you can then save a whole lot of time when formatting the document.
    I've just finished nearly 400 pages of financials using this method over the past couple of days!
    This solution may not suit your sitation, but if you have a lot of tables to get through it's got to be worth giving it a try.

  • Adding ToolTip for individual cell in the table

    Hi everybody,
    Its urgent. I want to add ToolTip for individual cells. What I have implemented, it show same ToolTip for each cell. I want different ToolTip for individual cell.
    My cells are not editable, as i need this.
    Pleae help me.
    Thanks in Advance.
    Dawoodzai

    Hi,
    See this demo pasted below-
    import java.awt.*;
    import javax.swing.*;
    public class SimpleTableDemo extends JFrame {
         public SimpleTableDemo() {
              super("SimpleTableDemo");
              Object[][] data = {
                   {"Mary", "Campione", "Snowboarding", new Integer(5), new Boolean(false)},
                   {"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)},
                   {"Kathy", "Walrath", "Chasing toddlers", new Integer(2), new Boolean(false)},
                   {"Sharon", "Zakhour", "Speed reading", new Integer(20), new Boolean(true)},
                   {"Angela", "Lih", "Teaching high school", new Integer(4), new Boolean(false)}
              String[] columnNames = {"First Name", "Last Name", "Sport", "# of Years", "Vegetarian"};
              final JTable table = new MyTable(data, columnNames);
              table.setPreferredScrollableViewportSize(new Dimension(500, 70));
              JScrollPane scrollPane = new JScrollPane(table);
              getContentPane().add(scrollPane, BorderLayout.CENTER);
         public static void main(String[] args) {
              SimpleTableDemo frame = new SimpleTableDemo();
              frame.pack();
              frame.setVisible(true);
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class MyTable extends JTable {
         public MyTable(Object[][] rowData, Object[] columnNames) {
              super(rowData,columnNames);
         public String getToolTipText(MouseEvent e) {
              int r = rowAtPoint(e.getPoint());
              int c = columnAtPoint(e.getPoint());
              return getValueAt(r,c).toString();
    }

  • Table cell height not correct

    I have a table with 21 rows. Every other row is used as a separator between the rows with content. These separator rows don't have anything in them and their height is set to 1 in the properties inspector. I'm assuming these heights and widths are in pixels, however, these rows don't appear to be 1px in design view nor on a live web page.They are more like 15px.
    How can I make these rows 1px in height?

    That site has badly malformed code.
    http://tinyurl.com/36z7sc8
    I'm guessing it's cobbled togather from various bits and pieces including the ChronoForm code?
    Regarding the cell heights, the code of a typical cell is:
    <td width="95" height="1"> </td>
    The code between the <td> tags  (known as a non-breaking space) is a space character (pressing the spacebar on your keyboard generates this code in the HTML).
    Removing the space from the code for each <td> will cause your cells to collapse. You may need to prop them open with a 1px high GIF as Murray suggested.

  • Change individual track height?

    Does anyone know if it's possible to change individual track heights, or am I stuck with global settings?
    I can do it with FCP, it'd be nice if Soundtrack does it as well.
    Thanks to anyone in advance!!

    hmmm... this does not adjust the height of individual tracks - just all tracks in the project.
    you can use 'cmd-6', 'cmd-7', 'cmd-8' and 'cmd-9' to shortcut the 4 different preset track height settings.
    gavin little
    echolab
    dublin, ireland
    http://www.echo-lab.com/
    http://www.imdb.com/name/nm1962022/

  • Block, columns, files or individual cells in numbers?

    Hello,
    There's any way to block from editing an individual cell or file or column?
    Normally I use some cells or columns to use specifyc formulas on them, with  automathic results.
    Not being able to block those, it's really easy to delete the formula.
    I could use a Formular for editing data, and block the full table for showing results, but I would prefer to do it on the smae table as in excel, just having some columns editable and others not blocked with automathic formulas.
    Is this possible somehow?
    Thanks
    Sergi.

    I don't think so, unless maybe your formulas were on a different table on a different sheet and you just referenced them from the data entry table.
    Also, have you looked into Forms? I don't use them much, but I do see that you cannot edit formulas from there.

  • Make individual cells readonly in js grid of the schedule web part

    I need to be able to modify individual cells in the js grid on the schedule web part to make them editable or read only based on certain conditions pertaining to that specific record.  I've figured out how to make an entire record in the grid
    read only by using delegates, but I'm having trouble getting to the specific cell and making it read only.  The code I have for making an entire row read only is below.  I'd like to do something along these lines but for cells, not
    rows...
    PJ.AddGridSatelliteInitializationNotifier
    function (satellite) {
    satellite = PJ._NotifySatelliteInitComplete.arguments[0];
    _myGrid = satellite.GetJsGridControlInstance();
    _myGrid.SetDelegate(SP.JsGrid.DelegateType.GetRecordEditMode, CheckToAllowEdit);
    function CheckToAllowEdit(record) {
    if (record.GetDataValue('TASK_WORK') == 0) {
    //i need to find a way to get the cell in question here and then make it ready only return SP.JsGrid.EditMode.ReadOnly;
    else {
    return SP.JsGrid.EditMode.ReadWrite;

    Hi gmhamm0
    Were you able to get this done for a specific cell ?

  • Arbitrary Individual Cell Selection

    How do I select individual cells arbitrarily in a JTable ?
    Regards,
    Ram

    LOL. Good one.
    If that doesn't work, how about:myTable.changeSelection( row, column, false, false );

Maybe you are looking for