TreeCellRenderer width update

It seems to be a recurrent issues here according to the numerous thread I read. But I did not find any answer.
I have a JTree and a cell renderer extending the DefaultTreeCellRenderer. This custom renderer customizes some colors (background, text...) and sets the node font to bold when selected. As the label content is wider the node name ends with trailling dots ('...').
I know that I can solve the problem if I invoke model.nodeChanged(theSelectedNode) but my custom tree has to work fine with any TreeModel and not only DefaultTreeModel subclasses (well actually I would prefer). Moreover I know the node content didn't change therefore it's useless to reload it from the model.
I tried to compute the new label width (and set the preferred size) with a:
int width = SwingUtilities.computeStringWidth(getFontMetrics(getFont()), getText())
               + getIcon().getIconWidth()
               + getIconTextGap();The label is wider than previously but still to short. Does I do something wrong or miss something ?
Does anyone can help me ? Thank you.
Joot

BufferedImage bi = new BufferedImage(bufi.getWidth()*scalingFactor, bufi.getHeight()*scalingFactor, BufferedImage.TYPE_INT_RGB);Also this line overrides the previous 2 lines setting translation and scale: tx.setToScale(scalingFactor, scalingFactor);So there's no need for them.
And why are you writing the jpeg twice using JPEGImageEncoder and ImageIO?

Similar Messages

  • How to set column widths in tables for selected table only, not globally throughout document?

    I've been utilizing the below script (thank you so much Ramkumar. P!) to set column widths throughout a sizable InDesign book with tables on every page and it is truly a time saver. At this point in time, I have three versions of it because there are different column widths throughout the book. Is it possible to augment the script to run only on a selected text frame (containing a table)? If so, would someone be kind enough to share the augmented script with me? I've been trying to figure out this seemingly simple change through trial and error with no success as yet. I realize this is a totally newbie request and I'm entirely at the mercy of the kindness of the Javascript gods that contribute within this forum. Seeing that in a different post related to this script, one such guru responded to a request as simple as "Where do I put the scripts in InDesign" gave me enough courage to ask for some help! Thank you in advance to anyone willing to provide a solution.
      var myDoc = app.activeDocument;
         var myWidths = [100, 100, 150, 150];
         for(var T=0; T < myDoc.textFrames.length; T++){
             for(var i=0; i < myDoc.textFrames[T].tables.length; i++){
                 for(var j=0; j < myWidths.length; j++){
                     myDoc.textFrames[T].tables[i].columns[j].width = myWidths[j];
         alert("Table width updated successfully...");

    Hello all
    I have the same problem in that I'm not a scripting person, but was able to get the above script working without problem, and it does set irregular table column widths perfectly, so thanks to Ramkumar. P for that.
    BUT, it changes the column width for ALL tables in the document, whereas I would like to just target the selected table.
    Any ideas as to how I might amend this script to achieve this?
    Thx, Christian

  • Mapping of JTable Rows and columns and paint it to the JPanel

    Hi,
    I am using JTable and graphics object to draw the JTable on JPanel. But due to some lack of measurement I am not able to draw table cells correctly.
    Apart from this on changing the fontSize I have to redraw it according to the requirement. But when the data size increases it draws absurdly.
    I am using jTable.getCellRect() api to get the row width and height. Please help to redraw a JTable cell row and height on JPanel.
    I am also attaching a sample code with this mail.
    Thanks,
    Ajay
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.*;
    import java.awt.Dimension;
    import java.awt.GridLayout;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.table.*;
    import java.util.*;
    import java.awt.*;
    public class SimpleTableDemo extends JPanel {
        private boolean DEBUG = false;
           private int spacing = 6;
           private Map columnSizes = new HashMap();
           String[] columnNames = {"First Name",
                                    "Last Name",
                                    "Sport",
                                    "# of Years",
                                    "Vegetarian"};
            Object[][] data = {
             {"Kathy", "Smith",
              "SnowboardingXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", new Integer(5), new Boolean(false)},
             {"John", "Doe",
              "Rowing", new Integer(3), new Boolean(true)},
             {"Sue", "Black",
              "Knitting", new Integer(2), new Boolean(false)},
             {"Jane", "White",
              "Speed reading", new Integer(20), new Boolean(true)},
             {"Joe", "Brown",
              "Pool", new Integer(10), new Boolean(false)}
            final JTable table = new JTable(data, columnNames);
              Panel1 panel;
        public SimpleTableDemo() {
            super(new GridLayout(3,0));
            table.setPreferredScrollableViewportSize(new Dimension(500, 70));
            //table.setFillsViewportHeight(true);
            if (DEBUG) {
                table.addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e) {
                        printDebugData(table);
            //Create the scroll pane and add the table to it.
            JScrollPane scrollPane = new JScrollPane(table);
            //Add the scroll pane to this panel.
            add(scrollPane);
            panel = new Panel1();
            Rectangle rect = table.getCellRect(0,0,true);
              panel.setX(table.getWidth());
              panel.setY(0);
            panel.setWidth(rect.width);
              panel.setHeight(rect.height);
            panel.setStr(table.getModel().getValueAt(0,0).toString());
              panel.setModel(table);
              add(panel);
            final JComboBox jNumberComboBoxSize = new JComboBox();
              jNumberComboBoxSize.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "11", "12", "14", "16", "18", "20", "24", "30", "36", "48", "72" }));
            jNumberComboBoxSize.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                   jNumberComboBoxSizeActionPerformed(jNumberComboBoxSize);
              JPanel panel2 = new JPanel();
              panel2.add(jNumberComboBoxSize);
              add(panel2);
              adjustColumns();
         private void jNumberComboBoxSizeActionPerformed(JComboBox jNumberComboBoxSize)
            int fontSize = Integer.parseInt(jNumberComboBoxSize.getSelectedItem().toString());
              table.setRowHeight(fontSize);
              table.setFont(new Font("Serif", Font.BOLD, fontSize));
              Rectangle rect = table.getCellRect(0,0,true);
              panel.setX(0);
              panel.setY(0);
           // panel.setWidth(rect.width);
              panel.setHeight(rect.height);
            panel.setStr(table.getModel().getValueAt(0,0).toString());
              panel.setModel(table);
              panel.repaint();
              table.revalidate();
        private void printDebugData(JTable table) {
            int numRows = table.getRowCount();
            int numCols = table.getColumnCount();
            javax.swing.table.TableModel model = table.getModel();
            System.out.println("Value of data: ");
            for (int i=0; i < numRows; i++) {
                System.out.print("    row " + i + ":");
                for (int j=0; j < numCols; j++) {
                    System.out.print("  " + model.getValueAt(i, j));
                System.out.println();
            System.out.println("--------------------------");
          *  Adjust the widths of all the columns in the table
         public void adjustColumns()
              TableColumnModel tcm = table.getColumnModel();
              for (int i = 0; i < tcm.getColumnCount(); i++)
                   adjustColumn(i);
          *  Adjust the width of the specified column in the table
         public void adjustColumn(final int column)
              TableColumn tableColumn = table.getColumnModel().getColumn(column);
              if (! tableColumn.getResizable()) return;
              int columnHeaderWidth = getColumnHeaderWidth( column );
              int columnDataWidth   = getColumnDataWidth( column );
              int preferredWidth    = Math.max(columnHeaderWidth, columnDataWidth);
            panel.setWidth(preferredWidth);
              updateTableColumn(column, preferredWidth);
          *  Calculated the width based on the column name
         private int getColumnHeaderWidth(int column)
              TableColumn tableColumn = table.getColumnModel().getColumn(column);
              Object value = tableColumn.getHeaderValue();
              TableCellRenderer renderer = tableColumn.getHeaderRenderer();
              if (renderer == null)
                   renderer = table.getTableHeader().getDefaultRenderer();
              Component c = renderer.getTableCellRendererComponent(table, value, false, false, -1, column);
              return c.getPreferredSize().width;
          *  Calculate the width based on the widest cell renderer for the
          *  given column.
         private int getColumnDataWidth(int column)
              int preferredWidth = 0;
              int maxWidth = table.getColumnModel().getColumn(column).getMaxWidth();
              for (int row = 0; row < table.getRowCount(); row++)
                  preferredWidth = Math.max(preferredWidth, getCellDataWidth(row, column));
                   //  We've exceeded the maximum width, no need to check other rows
                   if (preferredWidth >= maxWidth)
                       break;
              return preferredWidth;
          *  Get the preferred width for the specified cell
         private int getCellDataWidth(int row, int column)
              //  Inovke the renderer for the cell to calculate the preferred width
              TableCellRenderer cellRenderer = table.getCellRenderer(row, column);
              Component c = table.prepareRenderer(cellRenderer, row, column);
              int width = c.getPreferredSize().width + table.getIntercellSpacing().width;
              return width;
          *  Update the TableColumn with the newly calculated width
         private void updateTableColumn(int column, int width)
              final TableColumn tableColumn = table.getColumnModel().getColumn(column);
              if (! tableColumn.getResizable()) return;
              width += spacing;
              //  Don't shrink the column width
              width = Math.max(width, tableColumn.getPreferredWidth());
              columnSizes.put(tableColumn, new Integer(tableColumn.getWidth()));
              table.getTableHeader().setResizingColumn(tableColumn);
              tableColumn.setWidth(width);
         * Create the GUI and show it.  For thread safety,
         * this method should be invoked from the
         * event-dispatching thread.
        private static void createAndShowGUI() {
            //Create and set up the window.
            JFrame frame = new JFrame("SimpleTableDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            SimpleTableDemo newContentPane = new SimpleTableDemo();
            newContentPane.setOpaque(true); //content panes must be opaque
            frame.setContentPane(newContentPane);
            //Display the window.
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    class Panel1 extends JPanel
        int x;
         int y;
         int width;
         int height;
         String str;
         JTable model;
        public void setModel(JTable model)
           this.model = model;
         public void setX(int x)
              this.x = x;
        public void setY(int y)
              this.y = y;
         public void setWidth(int w)
              this.width = w;
        public void setHeight(int h)
              this.height = h;
         public void setStr(String s)
              this.str = s;
        public void paint(Graphics g)
             super.paint(g);
              int initX= 0;
              for(int row=0;row < 5; ++row)
                   initX = x;
                   for (int col=0;col < 5;++col)
                        g.drawRect(x,y,width,height);
                        g.drawString(model.getModel().getValueAt(row,col).toString(),x + 10,y + 10);
                        x = x + width;
                x = initX;
                   y = y + height;
    };

    an easy way would be to use setSize()

  • Images are no longer scaling with (img {max-width: 100%; }) in css as of update 34.0.5 in firefox, this still works great in IE and chrome.

    My website worked great until firefox update 34.0.5. Now the images will not scale to fit the box anymore. I am using flexbox so that the site scales to fit the size of the browser. In css I set img {max-width:100%;} and this would make the jpg files automatically size to fit the box they were in, but not anymore as Mozilla has really screwed this up with update 34.0.5. My site still works great with IE and Chrome but 70% of my web traffic is using firefox so I really would like this to work in firefox.
    Any help is greatly appreciated!

    I had the same problem, and this worked for me:
    img {max-width:100%; width:100%;}

  • Changing scaleX/scaleY on parent scales the children but doesn't update  height/width property ?

    have created a custom component - MyImage - that has two children including a Bitmap as well as a Sprite.
    My display object hierarchy is as follows -
    mx:Canvas
      view:MyImage
         mx:Bitmap
         my:Sprite
    If I change the MyImage.scaleX, scaleY property, the children scale as I would expect them to.
    However when I try to place the children in the center using placeAgain() on getting a resize event:
        public function placeAgain():void
            if (image==null) return;
            var pCanvas:Canvas = this.parent as Canvas;
            if (image.width <= pCanvas.width)
                pCanvas.horizontalScrollPolicy="off";
                image.x = (pCanvas.width -image.width)/2;
            else
                pCanvas.horizontalScrollPolicy="on";
                image.x=0;
            if (image.height <= pCanvas.height)
                pCanvas.verticalScrollPolicy="off";
                image.y = (pCanvas.height -image.height)/2;
            else
                pCanvas.verticalScrollPolicy="on";
                image.y=0;
            alignKids();
    I find the image.height & width have not changed despite the image getting scaled!
    Isn't the child supposed to have its bounds changed after scaling its
    parent ? Especially after the child has actually been scaled correctly ?
    Why are bounds of the child stuck at the same value as before scaling? I
    am not caching the Bitmap, have not turned on caching of bitmaps.

    If I'm not mistaken, the bounds are updated with the scale. You rare not referencing the bounds, your referencing the width and height properties, which is a bit different. What happens if you use the getBounds function to get your dimensions?

  • SmartView VBA - Cannot set "Update Column Width" setting

    Hi Folks,
    I'm in the process of updating a series of v9 Essbase VBA API-driven workbooks to SmartView 11.1.2.1 and have hit a problem - I'm new to the SV VBA commands, and I'm hoping this is something obvious that I'm missing.
    One of the functions that is key to ensuring data retrieval does not change the layout of the spreadsheets is the "Adjust Column Widths" setting, which in the Essbase VBA API could be managed using the EssVSetSheetOption function, but neither HypSetGlobalOption nor HypSetSheetOption appear to have any such capability. The only option I'm left with is to run retrieves followed by some reformatting of column widths, which seems rather ineligant to me.
    Any ideas?
    Many thanks,
    Dave

    looking in the .bas file (and what should be included in your project I find HSV_ADJUSTCOLUMNWIDTH in the definitions for Enumeration of options index to be used for HypGetOption/HypSetOption
    Note, I'm looking at the 11.1.2.2 version, your mileage may vary depending on your version

  • How to define maximum field width on an updatable report

    I have an updatable report.
    From a user's perspective, this is a form in my app. How can I define the maximum number of characters the user can enter into a field?
    I tried entering the following into the report column's element attributes, but none of these worked:
    width=10px
    width:10px
    max-width=10px
    max-width:10px
    I don't know why the Tabular Form Element section allows to define Element Width and Number of Rows, but not the maximum width.
    Thanks
    Boris

    Hi Boris,
    If your updateable report is created by using a wizard than its not.
    You could use the apex_item.text api which allows for setting the max field width.
    Jos

  • Calendar component width after updating to Update 1

    Hi.
    Since updating to Creator 2 update1 I have found that the calendar component appears to be calculating its width differently.
    Previously it appeared to include the calendar popup button when working out its own width.
    Now it seems to only include the textfield area. This means that the popup button now is outside its boundaries.
    The effect of this is that when putting the calendar in a grid, any components to its right (also in the grid) overlap the button part of the calendar.
    Has anyone else seen similar behaviour, and is there any workaround ?
    Regards,
    Ian

    Edwin, can you please, oh pretty please change the
    Calendar component to use SimpleDateFormat instead of
    DateFormat?I don't remember where DateFormat is used, but a SimpleDateFormat extends DateFormat so you may be able to use SimpleDateFormat. Having had to fix various bugs with the built-in calendar, I think that it needs a redesign. So instead you may want to look at the prototype popup calendar that is will be included in the AJAX V3 complib. I hope that one will suit your needs. I'd like to hear your feedback on the new component.
    -Edwin

  • Hbox in view stack does not update width

    Hi there,   I'm working on flash builder and I have four hboxes nested inside a view stack. I dynamically populate each hbox with images grabbed from the database. For some reason only the visible hbox correctly updates its' width while the other 3 hbox takes on the width of this one so I end up with all four hbox having the same width. This is a problem when I have lots of images in one than the other and some of them gets cut off.
    The hboxes do not have scroll bars as the viewstack has a mouse easing scroller function attached to it - the hbox scrolls according to the position of the mouse.
    Am I doing something wrong here?
    <mx:Canvas height="110"
                       width="663"
                       visible.loginState = "false"
                       x="10"
                       y="577" horizontalScrollPolicy="off" verticalScrollPolicy="off" id="viewStackContainer">
                <mx:ViewStack id="myViewStack" creationPolicy="all"
                              borderStyle="none">
                    <!-- Books Library -->
                    <mx:HBox horizontalAlign="left" verticalScrollPolicy="off" horizontalScrollPolicy="off" verticalAlign="middle" horizontalGap="0" id="books" />
                    <!-- EBooks Library -->
                    <mx:HBox horizontalAlign="left" verticalScrollPolicy="off" horizontalScrollPolicy="off" verticalAlign="middle" horizontalGap="0" id="ebooks" />
                    <!-- Recordings Library -->
                    <mx:HBox horizontalAlign="left" verticalScrollPolicy="off" horizontalScrollPolicy="off" verticalAlign="middle" horizontalGap="0" id="recordings" />
                    <!-- Readings Library -->
                    <mx:HBox horizontalAlign="left" verticalScrollPolicy="off" horizontalScrollPolicy="off" verticalAlign="middle" horizontalGap="0" id="readings" />
                </mx:ViewStack>
            </mx:Canvas>

    Hi thanks for your reply. As the hbox gets populated i need it to resize itself. Once each hbox has been populated with the images I attach a function to the viewstack which allows me to scroll the hbox with mouse position - so it scrolls horizontally depending on where the mouse is in relation to the viewstack. So as you can see I need by this point for each hbox to have resized in order to correctly calculate my scrolling function.  The bizarre thing is the selected Index hbox displays all the images but the rest of the hboxes takes on the same width as this one and this is a problem because some of my other hbox contains more images.  As a test I set the selected Index of the viewStack to be the third Hbox, then I restarted the application and now all the hbox takes on the wdith of this one.   I am creating a library of thumbnails which is dynamically driven. It's not possible for me to predetermine the width of each. Do you have any suggestions for this?

  • Macbook pro retina 15 after update OS X 10.9.3 to 10.9.4 can't connect wifi with Channel Width 40 HMz

    macbook pro retina 15 after update OS X 10.9.3 to 10.9.4 can't connect wifi with Channel Width 40 HMz

    That's odd. I assume this is the 5 GHz band, right?
    Have you tried changing the router to do auto 20/40?
    Have you tried deleting and reconnecting to the wifi network?

  • [svn:osmf:] 15262: Updated unit test for MediaPlayers new default width/ height.

    Revision: 15262
    Revision: 15262
    Author:   [email protected]
    Date:     2010-04-07 13:54:32 -0700 (Wed, 07 Apr 2010)
    Log Message:
    Updated unit test for MediaPlayers new default width/height. FM-300.
    Ticket Links:
        http://bugs.adobe.com/jira/browse/FM-300
    Modified Paths:
        osmf/trunk/framework/OSMFTest/org/osmf/media/TestMediaPlayer.as

    To Neoreborn:
    If I understand right, Shale only provides some mock core JSF objects and extends JUnit so that you can do junit test to your java classes.
    What I concern is to test Pages(JSP) rather than java classes. I want to assert component attribute values within all lifecycle including rendered HTML script. Currently, there isn't any good tools to do this kind of JSP Unit test, am I right?

  • Updating the width of a report

    Post Author: abdoing
    CA Forum: General
    hi,
    i'm working now with crystal reports professional edition v10, and i have a probleme that i can't update in design the width  of my report
    (its fixed to 20 cm) so i'm searching a way to grow it and think you.

    Post Author: pvierheilig
    CA Forum: General
    I believe you want to adjust the 'Page Setup' options / Print options from the File menu.  Selecting a printer from the list that is already installed on your computer will allow page dimensions for only what the printer is able to print.  Hope that helps.

  • 14.2 updates changes width of Swatches palette

    Hi, as soon as I updated ps cc to 14.2 the swatches palette, when docked does not behave correctly: all swatches are placed as you have resized the palette, placing them in wrong order. Undocking the palette reposition the swatches correctly.
    I've made sure the docked palette is not scaled, in fact even on brand new, reset "essential" preset interface displays the issue even with default palette.
    Scaling the docked palettes does not fix the problem.
    Here's an example with the DEFAULT interface on a fresh installation
    first one is the unlocked palette, works as expected
    second one is the docked palette (wich is on the default Essentials UI!)
    My guess is that the minimum docked palette width has increased by some pixels with the update. This may look like a minor issue, but it skrewed up all my custom palettes

    The panel is not "broken", but its minimum width has increased due to the inclusion of the new longer phrase "Smart Object" in the Layers panel options filter list.
    Specifically, for the English-language interface (on Windows using a non-4K monitor and standard font sizes), CC 14.1.x and CS6 had the same smaller Layers panel minimum width of 224px, as compared to the new wider minimum of 242px in CC 14.2:
    Even for a particular version of Photoshop, things that change the length of words, such as user-interface language, and the size of the letters or symbols, such as the typeface and size of the fonts used for the user-interface, would affect minimum panel width.  In other words, I suspect German users have a wider minimum Layers panel width, and Chinese users have a narrower minimum Layers panel width, and users with Retina or 4K displays also have different sizes for things due to the much higher resolution.

  • CS5 Device Central Stage.width/Stage.height update problem when change the device profile.

    When creating FL 3.0/3.1 app   and testing it at the CS5 Device Central if you change the profile of the active device(select different phone with different screen size) Stage.width/Stage.height could't change. Always stays the same as the first device's Stage.width and height. Even if you add addListener with Delegate nothing happends. Also it effects to Screen Oriantation. It looks like a problem or is this a bug?

    Having the same problem, though I can't get it to connect even once. I just started researching the problem tonight - no solution yet...
    I'm on Windows 7 Pro 64-bit, Production Premium CS 5.5.
    I've got no other internet issues, Adobe update works fine.
    Please - Anybody have an idea how to troubleshoot this problem?
    Thank you.

  • RE:  width of TreeCellRenderer

    Hi All,
    I've finally got a JTextPane to appear as nodes in my JTree by implementing a TreeCellRenderer. I add my text, set the styles and add them to the JTextPane which is then added to a JPanel which is returned by getTreeCellRendererComponent.
    My JTree is inside a JScrollPane and the problem that I have now is that the text in the JTextPane completely ignores the size of my JScrollPane and the words no longer wrap.
    How would do I set up my TreeCellRenderer so that it is aware of the width of the JScrollPane and when someone resizes the JScrollPane, all the text wraps appropriately ?
    I am a bit of a newbie when it comes to Java so code postings and/or URLs help enormously !
    Thanks !

    I believe the problem is that the width of the JTree is calculated at a later point. When you create your JTextPane, the scroll pane knows nothing about the size of the JTree.
    ... but this is a hypothesis only. You should post some of your own code, so that we could peek into the specific details.

Maybe you are looking for

  • HT4314 I don't but I have created 2 game center accounts with one apple ID and I want to remove the new account which I made so need help how to remove it

    I don't know how but I created it and want to remove now but I didn't got any option for removing account. I have unfriend all my friends which where connected to my new account and I have clicked the public profile and kept it off but I didn't find

  • Can't boot P35 NEO2-FR. (LEDs: R-R-G-G)

    Hi all, I'm new at this forum. Today I changed a CPU and updated BIOS to v1.6 I was able to boot my board without any problems. Then I realized that CPU voltage showed different values, so I thought I should clear CMOS. What I've done is, remove CMOS

  • Use of document function in XSL

    We have an existing XSL document which uses a separate XML document for mapping of enumerated values. So in the XSL document, we have a line in our XSL as follows: <xsl:variable name="enum-doc" select="document('enumerations.xml')"/> Followed by a lo

  • BPM 7.2, analytics, multilingual support

    Good day! We are creating reports by using new BI content and we have a questions about multilingual support. As we can see the task definition name of a BPM task is the physical name of the task (I mean it is the name of the file task_name.task). Of

  • SQL Profiler's equivalent in Oracle.

    Hi All, We are using Oracle 10g as backend for our application. We would like to see which database objects (stored procedures, functions, triggers etc) are getting called at the Oracle database server when various users connect to the application an