How to determine the maximum size of JFrame?

I am using JDK1.2 to develop an application. I have
a problem to handle the maximum size of of JFrame.
If the user clicks the maximum icon or double-clicks
the title bar from the JFrame, the JFrame becomes
maximum. How can I determine the state of maximization? I need to bring different views if the
JFrame is maximum or minimum. I knew JDK1.4 can
handle this problem. Or using JNI, either. Does
anyone know other ways to handle this?
Thanks,
Peter

So that you won't have to wait forever:
Sorry, pal, the only way is JNI. I researched this earlier for 1.2, but can't find it right now in the database. They finally added it to 1.4.
Good luck.

Similar Messages

  • How to determine the proper size for Oracle 8i Data Base Objects

    Hi,
    I'm working on an Oracle 8i Data base. I'd like to know how to determine the proper size for the Data Base objects such as tables, datafiles, tablespaces...
    Thanks.

    Start with the docs.
    http://download-west.oracle.com/docs/cd/A87860_01/doc/server.817/a76956/schema.htm#949
    Best Regards
    Krystian Zieja / mob

  • How to determine the field size

    I am going to make a multiplatform application that hopefully
    will run on linux and windows 2000.If the os is 2000, then I will use
    vb.net/aspx else I'll use java servlets. I make the connection
    to the web server ( through HTTP) not directly to database server.
    So, the resultset will be stored in the String object. The columns
    will be separated by delimeter. Our problem is how to determine
    the size and type of the fields of mssql,oracle and postgres database
    so that we can include it in the String object.
    Ex.
    String sResultSet=new String();
    ResultSet rs=statement.executeQuery(sSQL);
    while(rs.next()){
    sResultset=sResultSet + rs.getString(field1) + "||" + rs.getString(field2) + "||";
    vertical bars acts as delimeter
    supposedly this is the code:
    sResultset=sResultSet + rs.getString(field1) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||" + rs.getString(field2) +"_" + rs.getFieldType() + "_"+
    rs.getFieldSize() + "||";
    supposedly this is the code if rs.getFieldType() and rs.getFieldSize() methods are existing
    Anyone can give me an idea how to get the field type and field size of the database?
    thanks in advance

    Yes, but I dont know how to do it.
    Can you give me an example of using it.
    Thanks in advance

  • How to determine the database size corresponding to the nber records in DSO

    Hi Colleagues,
    I would like to determine the database size corresponding to my new BI project.
    I know the number of records uploaded in the DSO from the source system for the intialization phase.
    How can I deduct the database size / disk size corresponding to the number of record uploaded ?
    Thanks,

    Hi Ram,
    I am with SAP BI Release SAPKW70019
    I do not have the option Single Table analysis -
    I have in DB02 or ST04 the following options.
    *- Space*
    -- space overview
    ->database
    --overview
    ->users
    --overview
    --detailed analysis
    -> tablespaces
    --overview
    --detailed analysis
    -> segments
    --overview
    --Detailed analysis
    --Detailed Analysis Aggregated
    -> Additional Functions
    --Collector Logs
    --BW Analysis
    Where should I go through ?
    Thanks

  • How to determine the maximum allowable length of a filename for Window ?

    Hi all,
    Could I know how to determine the allowable file length (the length of the absolute path) for a file in Window environment?
    Due to some reason, I generated a zip file with a very long filename ( > 170) and put in a folder(the length of the folder path around 90). The length of the absolute path is around 260.
    I used FileOutputStream with the ZipOutputStream to write out the zip file. Everything is working fine while i generating the zip file.
    However, while i try to extract some files from the zip file i just created, i encountered the error
    java.util.zip.ZipException The filename is too long.
    I am using the class ZipFile to extract the files from the zip file like the following
    String absPath = "A very long filepath which exceed 260";
    ZipFile zipF = new ZipFile(absPath);  //<-- here is the root causeIs it possible to pre-determine the maximum allowable filepath length prior i generate the zip file ? This is weird since i got no error while i created the zip file, but have problem in extracting the zip file ......
    Thanks

    Assuming you could determine the max, what would you do about it? I'd say you should just assume it will be successful, but accommodate (handle) the possible exception gracefully. Either way you're going to have to handle it as an "exception", whether you "catch" an actual "Exception" object and deal with that, or manually deal with the length exceeding the max.

  • How to determine the maximum prefix of two CharSequences efficiently?

    I have the following problem. I need a unicode friendly mechanism for determining the maximum prefix of 2 CharacterSequences. I've come up with the following code which appears to do the job, but which requires up to ([number of codepoints in smaller sequence] * 2) + 1 memory allocations. These memory allocations are rather irksome since I plan on calling this method extremely many times. The code I came up with looks like:
    private static int getLengthOfMaxCommonPrefix(CharSequence str1, CharSequence str2, Collator collator) {
        if ((str1 == null) || (str2 == null)) { return 0; }
        if (Character.codePointCount(str1, 0, str1.length()) > Character.codePointCount(str2, 0, str2.length())) {
          CharSequence tmp = str1;
          str1 = str2;
          str2 = tmp;
        // @todo get rid of memory allocation
        char[] charArray = new char[4];
        int i = 0;
        for (int size = Character.codePointCount(str1, 0, str1.length()); i < size; i++) {
          Character.toChars(Character.codePointAt(str1, i), charArray, 0);
          Character.toChars(Character.codePointAt(str2, i), charArray, 2);
           // @todo get rid of memory allocation
          String char1Str = new String(charArray, 0, 2);
          // @todo get rid of memory allocation
          String char2Str = new String(charArray, 2, 2);
          if (collator.compare(char1Str, char2Str) != 0) {
            return i;
        return i;
      }Am I overlooking an API that would allow me have this same functionality without memory allocations? If not, would it be reasonable to request that the Java Collator API be updated to have:
    Collator.compare(int codepoint1, int codepoint2)which would eliminate the need for these memory allocations. The only reason I would suggest this change is that more than a few pieces of my other code involving unicode has the same problem. Also, when looking over the API it seems that
    static Character.toString(char c)exists, but the following method doesn't:
    static Character.toString(int codepoint)which would at least minimize some of the ugliness in the above code and be in keeping with the other APIs under Character.
    Edited by: APBrusseau on Feb 10, 2008 11:23 PM
    Edited by: APBrusseau on Feb 10, 2008 11:24 PM
    Edited by: APBrusseau on Feb 10, 2008 11:29 PM
    Edited by: APBrusseau on Feb 10, 2008 11:45 PM
    Edited by: APBrusseau on Feb 10, 2008 11:46 PM
    Edited by: APBrusseau on Feb 10, 2008 11:48 PM

    But still, surely just walking character by character through the strings and comparing them (using your collator) will do?
        char[] c1 = new char[1];
        char[] c2 = new char[1];
        // swap longest/shortest string, etc.
        // for each char {
            c1[0] = cs1.charAt(n);
            c2[0] = cs2.charAt(n);
            s1 = new String(c1);
            s2 = new String(c2);
            // use collator to compare
        // }The only thing I don't know is whether there are collators which look at sequences of characters. For example, I think in Unicode, you can have an 'a' followed by a 'add an accent to the previous character' character, which would obviously impact on the collation order.
    In which case, something like
        // for n = 1 .. length of shortest {
            int result = collator.compare(cs1.subSequence(0, n).toString(), cs2.subSequence(0, n).toString());
            if (result != 0) {
                return result;
        // equal to length of shortest string. Make decision based on length.This might be efficient, or not, depending on the implementation of CharSequence. String, for example, has a very efficient subSequence() method.

  • Tablespace allocation type system  how oracle determines the extent size

    HI
    It may be silly question but the I have to ask and get some knowdge
    Suppose tablespace allocation_type is system then how oracle determins the inital extent and max extent size?

    Was this tablespace converted to locally managed from an existing tablespace? If so, the existing extents still exist after the conversion. Also depending on the Oracle version and maybe platform the pct_increase parameter is still honored after the conversion which can lead to odd sizes. The current value of this parameter may not be the value that was in effect when extents were allocated.
    Also Oracle enhanced the logic to not leave odd sized extents unused so that if by rights the system should take a 64K extent but there is a 56K extent available (perhaps at the end of a file) it can be used to fill the extent request.
    HTH -- Mark D Powell --

  • How to restrict the maximum size of a java.awt.ScrollPane

    Dear all,
    I would like to implement a scroll pane which is resizable, but not to a size exceeding the maximum size of the java.awt.Canvas that it contains.
    I've sort of managed to do this by writing a subclass of java.awt.ScrollPane which implements java.awt.event.ComponentListener and has a componentResized method that checks whether the ScrollPane's viewport width (height) exceeds the content's preferred size, and if so, resizes the pane appropriately (see code below).
    It seems to me, however, that there ought to be a simpler way to achieve this.
    One slightly weird thing is that when the downsizing of the pane happens, the content can once be moved to the left by sliding the horizontal scrollbar, but not by clicking on the arrows. This causes one column of gray pixels to disappear and the rightmost column of the content to appear; subsequent actions on the scrollbar does not have any further effect. Likewise, the vertical scrollbar can also be moved up once.
    Also, I would like a java.awt.Frame containing such a restrictedly resizable scrollpane, such that the Frame cannot be resized by the user such that its inside is larger than the maximum size of the scrollpane. The difficulty I encountered with that is that setSize on a Frame appears to set the size of the window including the decorations provided by the window manager (fvwm2, if that matters), and I haven't been able to find anything similar to getViewportSize, which would let me find out the size of the area inside the Frame which is available for the scrollpane which the frame contains.
    Thanks in advance for hints and advice.
    Here's the code of the componentResized method:
      public void componentResized(java.awt.event.ComponentEvent e)
        java.awt.Dimension contentSize = this.content.getPreferredSize();
        this.content.setSize(contentSize);
        java.awt.Dimension viewportSize = getViewportSize();
        System.err.println("MaxSizeScrollPane: contentSize = " + contentSize);
        System.err.println("MaxSizeScrollPane: viewportSize = " + viewportSize);
        int dx = Math.max(0, (int) (viewportSize.getWidth() - contentSize.getWidth()));
        int dy = Math.max(0, (int) (viewportSize.getHeight() - contentSize.getHeight()));
        System.err.println("MaxSizeScrollPane: dx = " + dx + ", dy = " + dy);
        if ((dx > 0) || (dy > 0))
          java.awt.Dimension currentSize = getSize();
          System.err.println("MaxSizeScrollPane: currentSize = " + currentSize);
          setSize(new java.awt.Dimension(((int) currentSize.getWidth()) - dx, ((int) currentSize.getHeight()) - dy));
        System.err.println();
      }Best regards, Jan

    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    public class ScrollPaneTest
        GraphicCanvas canvas;
        CustomScrollPane scrollPane;
        private Panel getScrollPanel()
            canvas = new GraphicCanvas();
            scrollPane = new CustomScrollPane();
            scrollPane.add(canvas);
            // GridBagLayout allows scrollPane to remain at
            // its preferred size during resizing activity
            Panel panel = new Panel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            panel.add(scrollPane, gbc);
            return panel;
        private WindowListener closer = new WindowAdapter()
            public void windowClosing(WindowEvent e)
                System.exit(0);
        private Panel getUIPanel()
            int w = canvas.width;
            int h = canvas.height;
            int visible = 100;
            int minimum = 200;
            int maximum = 500;
            final Scrollbar
                width  = new Scrollbar(Scrollbar.HORIZONTAL, w,
                                       visible, minimum, maximum),
                height = new Scrollbar(Scrollbar.HORIZONTAL, h,
                                       visible, minimum, maximum);
            AdjustmentListener l = new AdjustmentListener()
                public void adjustmentValueChanged(AdjustmentEvent e)
                    Scrollbar scrollbar = (Scrollbar)e.getSource();
                    int value = scrollbar.getValue();
                    if(scrollbar == width)
                        canvas.setWidth(value);
                    if(scrollbar == height)
                        canvas.setHeight(value);
                    canvas.invalidate();
                    scrollPane.validate();
            width.addAdjustmentListener(l);
            height.addAdjustmentListener(l);
            Panel panel = new Panel(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weightx = 1.0;
            addComponents(new Label("width"),  width,  panel, gbc);
            addComponents(new Label("height"), height, panel, gbc);
            gbc.anchor = GridBagConstraints.CENTER;
            return panel;
        private void addComponents(Component c1, Component c2, Container c,
                                   GridBagConstraints gbc)
            gbc.anchor = GridBagConstraints.EAST;
            c.add(c1, gbc);
            gbc.anchor = GridBagConstraints.WEST;
            c.add(c2, gbc);
        public static void main(String[] args)
            ScrollPaneTest test = new ScrollPaneTest();
            Frame f = new Frame();
            f.addWindowListener(test.closer);
            f.add(test.getScrollPanel());
            f.add(test.getUIPanel(), "South");
            f.pack();
            f.setLocation(200,200);
            f.setVisible(true);
            f.addComponentListener(new FrameSizer(f));
    class GraphicCanvas extends Canvas
        int width, height;
        public GraphicCanvas()
            width = 300;
            height = 300;
        public void paint(Graphics g)
            super.paint(g);
            Graphics2D g2 = (Graphics2D)g;
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                                RenderingHints.VALUE_ANTIALIAS_ON);
            int dia = Math.min(width, height)*7/8;
            g2.setPaint(Color.blue);
            g2.draw(new Rectangle2D.Double(width/16, height/16, width*7/8, height*7/8));
            g2.setPaint(Color.green.darker());
            g2.draw(new Ellipse2D.Double(width/2 - dia/2, height/2 - dia/2, dia-1, dia-1));
            g2.setPaint(Color.red);
            g2.draw(new Line2D.Double(width/16, height*15/16-1, width*15/16-1, height/16));
        public Dimension getPreferredSize()
            return new Dimension(width, height);
        public Dimension getMaximumSize()
            return getPreferredSize();
        public void setWidth(int w)
            width = w;
            repaint();
        public void setHeight(int h)
            height = h;
            repaint();
    class CustomScrollPane extends ScrollPane
        Dimension minimumSize;
        public Dimension getPreferredSize()
            Component child = getComponent(0);
            if(child != null)
                Dimension d = child.getPreferredSize();
                if(minimumSize == null)
                    minimumSize = (Dimension)d.clone();
                Insets insets = getInsets();
                d.width  += insets.left + insets.right;
                d.height += insets.top + insets.bottom;
                return d;
            return null;
        public Dimension getMinimumSize()
            return minimumSize;
        public Dimension getMaximumSize()
            Component child = getComponent(0);
            if(child != null)
                return child.getMaximumSize();
            return null;
    class FrameSizer extends ComponentAdapter
        Frame f;
        public FrameSizer(Frame f)
            this.f = f;
        public void componentResized(ComponentEvent e)
            Dimension needed = getSizeForViewport();
            Dimension size = f.getSize();
            if(size.width > needed.width || size.height > needed.height)
                f.setSize(needed);
                f.pack();
         * returns the minimum required frame size that will allow
         * the scrollPane to be displayed at its preferred size
        private Dimension getSizeForViewport()
            ScrollPane scrollPane = getScrollPane(f);
            Insets insets = f.getInsets();
            int w = scrollPane.getWidth() + insets.left + insets.right;
            int h = getHeightOfChildren() + insets.top + insets.bottom;
            return new Dimension(w, h);
        private ScrollPane getScrollPane(Container cont)
            Component[] c = cont.getComponents();
            for(int j = 0; j < c.length; j++)
                if(c[j] instanceof ScrollPane)
                    return (ScrollPane)c[j];
                if(((Container)c[j]).getComponentCount() > 0)
                    return getScrollPane((Container)c[j]);
            return null;
        private int getHeightOfChildren()
            Component[] c = f.getComponents();
            int extraHeight = 0;
            for(int j = 0; j < c.length; j++)
                int height;
                if(((Container)c[j]).getComponent(0) instanceof ScrollPane)
                    height = ((Container)c[j]).getComponent(0).getHeight();
                else
                    height = c[j].getHeight();
                extraHeight += height;
            return extraHeight;
    }

  • How to calcalate the maximum size occupied by a table/row

    Hi,
    I am using the below query to find the maximum size occupied by a table per a row of data.
    SQL> desc t2
    Name Null? Type
    NO NUMBER(1)
    CH VARCHAR2(10)
    SQL> select sum(data_length) from user_tab_columns where table_name='T2';
    SUM(DATA_LENGTH)
    32
    Is this correct? Does oracle takes 22 bytes of space to store a column of Number(1) per a row as it shows below !?
    1* select data_length from user_tab_columns where table_name='T2'
    SQL> /
    DATA_LENGTH
    22
    10
    Please give your comments/suggestions
    Thanks and Regards
    Srikanth

    If you are trying to do this for an existing table, you can get the actual number of bytes stored per column by:
    SELECT VSIZE(column_name)
    FROM tableSo, to get the largest row you could:
    SELECT MAX(VSIZE(col1) + VSIZE(col2) ... + VSIZE(coln))
    FROM tableIf you want to get the theoretical largest possible row size, then you can use something like:
    SELECT SUM(DECODE(data_type,'NUMBER', ROUND((data_precision/2)+.1,0) +1,
                                'DATE',   7,
                                'LONG',   2147483648,
                                'BLOB',   4000,
                                'CLOB',   4000,
                                data_length)) max_length
    FROM user_tab_columns
    WHERE table_name = 'MY_TABLE'This works because:
    For a number, Oracle stores two digits in each byte, and uses one byte for the mantissa. Note, if you are expecting negative numbers in your numeric columns then add one additional byte).
    For a date, Oracle always requires 7 bytes.
    A long is at most 2 GB in size.
    Both Blobs and Clobs will be stored out-of-line when they are larger than about 4,000 bytes.
    For other data types you specify bytes of storage when you define the column, and that is stored in data_length.
    I'm not sure at this point what sort of sizes you would get for object type columns or nested tables.
    HTH
    John

  • How to determine the Memory size of my computer?

    I need to find a way to determine how much computer RAM i have left. I was suggested to use System class methods like "Runtime.getRuntime().getFreeMemory()", and I need to determine how much Memory I need to use when I launch Java VM with Xmx option.
    I wonder if there is more detail I need to know at this moment? If this question is more suitable in Java VM forum, please let me know.

    This is a slightly messed version of the one in the J2D Demo, use JFrame.add(new MemoryMonitor());
    I'm not entirely sure if it'll work straight off since I messed with it but it should, all the memory stuff is hidden away there somewhere even if it won't.
    Shish
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.BufferedImage;
    import java.awt.geom.Line2D;
    import java.awt.geom.Rectangle2D;
    import java.util.Date;
    import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import javax.swing.border.TitledBorder;
    public class MemoryMonitor extends JPanel {
        static JCheckBox dateStampCB = new JCheckBox("Output Date Stamp");
        public Surface surf;
        JPanel controls;
        boolean doControls;
        JTextField tf;
        public MemoryMonitor() {
         note=n;
            setLayout(new BorderLayout());
            setBorder(new TitledBorder(new EtchedBorder(), "Memory Monitor"));
            add(surf = new Surface());
            controls = new JPanel();
            controls.setPreferredSize(new Dimension(135,80));
            Font font = new Font("serif", Font.PLAIN, 10);
            JLabel label = new JLabel("Sample Rate");
            label.setFont(font);
            label.setForeground(Color.black);
            controls.add(label);
            tf = new JTextField("1000");
            tf.setPreferredSize(new Dimension(45,20));
            controls.add(tf);
            controls.add(label = new JLabel("ms"));
            label.setFont(font);
            label.setForeground(Color.black);
            controls.add(dateStampCB);
            dateStampCB.setFont(font);
            addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                   removeAll();
                   if ((doControls = !doControls)) {
                       surf.stop();
                       add(controls);
                   } else {
                       try {
                           surf.sleepAmount = Long.parseLong(tf.getText().trim());
                       } catch (Exception ex) {note.alert(ex);}
                       surf.start();
                       add(surf);
                   validate();
                   repaint();
        public void start() {
         surf.start();
        public class Surface extends JPanel implements Runnable {
            public Thread thread;
            public long sleepAmount = 1000;
            private int w, h;
            private BufferedImage bimg;
            private Graphics2D big;
            private Font font = new Font("Times New Roman", Font.PLAIN, 11);
            private Runtime r = Runtime.getRuntime();
            private int columnInc;
            private int pts[];
            private int ptNum;
            private int ascent, descent;
            private float freeMemory, totalMemory;
            private Rectangle graphOutlineRect = new Rectangle();
            private Rectangle2D mfRect = new Rectangle2D.Float();
            private Rectangle2D muRect = new Rectangle2D.Float();
            private Line2D graphLine = new Line2D.Float();
            private Color graphColor = new Color(46, 139, 87);
            private Color mfColor = new Color(0, 100, 0);
            private String usedStr;
            public Surface() {
                setBackground(Color.black);
                addMouseListener(new MouseAdapter() {
                    public void mouseClicked(MouseEvent e) {
                        if (thread == null) start(); else stop();
            public Dimension getMinimumSize() {
                return getPreferredSize();
            public Dimension getMaximumSize() {
                return getPreferredSize();
            public Dimension getPreferredSize() {
                return new Dimension(135,80);
            public void paint(Graphics g) {
                if (big == null) {
                    return;
                big.setBackground(getBackground());
                big.clearRect(0,0,w,h);
                float freeMemory = (float) r.freeMemory();
                float totalMemory = (float) r.totalMemory();
                // .. Draw allocated and used strings ..
                big.setColor(Color.green);
                big.drawString(String.valueOf((int) totalMemory/1024) + "K allocated",  4.0f, (float) ascent+0.5f);
                usedStr = String.valueOf(((int) (totalMemory - freeMemory))/1024)
                    + "K used";
                big.drawString(usedStr, 4, h-descent);
                // Calculate remaining size
                float ssH = ascent + descent;
                float remainingHeight = (float) (h - (ssH*2) - 0.5f);
                float blockHeight = remainingHeight/10;
                float blockWidth = 20.0f;
                float remainingWidth = (float) (w - blockWidth - 10);
                // .. Memory Free ..
                big.setColor(mfColor);
                int MemUsage = (int) ((freeMemory / totalMemory) * 10);
                int i = 0;
                for ( ; i < MemUsage ; i++) {
                    mfRect.setRect(5,(float) ssH+i*blockHeight,
                                    blockWidth,(float) blockHeight-1);
                    big.fill(mfRect);
                // .. Memory Used ..
                big.setColor(Color.green);
                for ( ; i < 10; i++)  {
                    muRect.setRect(5,(float) ssH+i*blockHeight,
                                    blockWidth,(float) blockHeight-1);
                    big.fill(muRect);
                // .. Draw History Graph ..
                big.setColor(graphColor);
                int graphX = 30;
                int graphY = (int) ssH;
                int graphW = w - graphX - 5;
                int graphH = (int) remainingHeight;
                graphOutlineRect.setRect(graphX, graphY, graphW, graphH);
                big.draw(graphOutlineRect);
                int graphRow = graphH/10;
                // .. Draw row ..
                for (int j = graphY; j <= graphH+graphY; j += graphRow) {
                    graphLine.setLine(graphX,j,graphX+graphW,j);
                    big.draw(graphLine);
                // .. Draw animated column movement ..
                int graphColumn = graphW/15;
                if (columnInc == 0) {
                    columnInc = graphColumn;
                for (int j = graphX+columnInc; j < graphW+graphX; j+=graphColumn) {
                    graphLine.setLine(j,graphY,j,graphY+graphH);
                    big.draw(graphLine);
                --columnInc;
                if (pts == null) {
                    pts = new int[graphW];
                    ptNum = 0;
                } else if (pts.length != graphW) {
                    int tmp[] = null;
                    if (ptNum < graphW) {    
                        tmp = new int[ptNum];
                        System.arraycopy(pts, 0, tmp, 0, tmp.length);
                    } else {       
                        tmp = new int[graphW];
                        System.arraycopy(pts, pts.length-tmp.length, tmp, 0, tmp.length);
                        ptNum = tmp.length - 2;
                    pts = new int[graphW];
                    System.arraycopy(tmp, 0, pts, 0, tmp.length);
                } else {
                    big.setColor(Color.yellow);
                    pts[ptNum] = (int)(graphY+graphH*(freeMemory/totalMemory));
                    for (int j=graphX+graphW-ptNum, k=0;k < ptNum; k++, j++) {
                        if (k != 0) {
                            if (pts[k] != pts[k-1]) {
                                big.drawLine(j-1, pts[k-1], j, pts[k]);
                            } else {
                                big.fillRect(j, pts[k], 1, 1);
                    if (ptNum+2 == pts.length) {
                        // throw out oldest point
                        for (int j = 1;j < ptNum; j++) {
                            pts[j-1] = pts[j];
                        --ptNum;
                    } else {
                        ptNum++;
                g.drawImage(bimg, 0, 0, this);
            public void start() {
                thread = new Thread(this);
                thread.setPriority(Thread.MIN_PRIORITY);
                thread.setName("MemoryMonitor");
                thread.start();
            public synchronized void stop() {
                thread = null;
                notify();
            public void run() {
                Thread me = Thread.currentThread();
                while (thread == me && !isShowing() || getSize().width == 0) {
                    try {
                        thread.sleep(500);
                    } catch (InterruptedException e) { return; }
                while (thread == me && isShowing()) {
                    Dimension d = getSize();
                    if (d.width != w || d.height != h) {
                        w = d.width;
                        h = d.height;
                        bimg = (BufferedImage) createImage(w, h);
                        big = bimg.createGraphics();
                        big.setFont(font);
                        FontMetrics fm = big.getFontMetrics(font);
                        ascent = (int) fm.getAscent();
                        descent = (int) fm.getDescent();
                    repaint();
                    try {
                        thread.sleep(sleepAmount);
                    } catch (InterruptedException e) { break; }
                    if (MemoryMonitor.dateStampCB.isSelected()) {
                         System.out.println(new Date().toString() + " " + usedStr);
                thread = null;
    public static void main(String s[]) {
            final MemoryMonitor demo = new MemoryMonitor();
            WindowListener l = new WindowAdapter() {
                public void windowClosing(WindowEvent e) {System.exit(0);}
                public void windowDeiconified(WindowEvent e) { demo.surf.start(); }
                public void windowIconified(WindowEvent e) { demo.surf.stop(); }
            JFrame f = new JFrame("Java2D Demo - MemoryMonitor");
            f.addWindowListener(l);
            f.getContentPane().add("Center", demo);
            f.pack();
            f.setSize(new Dimension(200,200));
            f.setVisible(true);
            demo.surf.start();

  • How to control the maximum size of a component in a GridBagLayout

    Here is a small program that demonstrates my issue (it's originally from a big program that I couldn't attach here).
    I have a GridBagLayout with some components in it. Some of the components are JEditorPane (displaying some HTML) within JPanel and are individally scrollable.
    Here we go:
    - when I resize the main panel, every components will resize accordingly to their weight (which is here the same for all of them): fine
    - when I reduce the size of the main panel until it reaches all the preferred size of each component, the scrollPane of the main panel appears so that the user can scroll: not fine
    The behaviour I'm looking for is: when I reduce the size of the main panel, when it reaches the preferred size of the components, I would like that the JEditorPane (which are in JPanel with BorderLayout/CENTER) display their individual scrollbars so that I can see all the JEditor panes at the same time without having to scroll the main window.
    If the user continues to reduce the size of the main panel, then, at one point, display the scrollpane of the main panel.
    See what I mean? How to control this?
    Here is the code:
    @SuppressWarnings("serial")
    public final class CGridBagLayout2 extends JFrame {
         JPanel mainPanel;
         private final JScrollPane scrollPane;
         private JPanel panelize(Component component, String localization) {
              JPanel output = new JPanel(new BorderLayout());          
              output.add(component, localization);
              return output;
        public void addComponentsToMainPanel() {
              mainPanel.setLayout(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.weightx = 1.0;
              c.fill = GridBagConstraints.BOTH;
              String TEST_BIGTEXT = "<html><body><h2>Path</h2>toto/tutu/tata/TestN<h2>Prerequisites</h2>blah blah blah blah<br/><b>blah blah</b> blah blah\nblah blah <u>blah</u> blahblah blah blah<h2>Description</h2>blah blah blah blah<br/><b>blah blah</b> blah blah\nblah blah <u>blah</u> blahblah blah blah blah\nblah blah blah <br/>lah blah blah <br/>lah blah blah blah blah blah blah blah FIN</body></html>";
              for (int index=0; index<10; index++) {
                   c.gridheight = 5; // nb Testcases for this test
                   c.anchor = GridBagConstraints.FIRST_LINE_START; // align all the components top-left aligned
                   c.gridy = index;
                   JLabel a = new JLabel("AAAAA");
                   c.gridx = 0;
                   mainPanel.add(panelize(a, BorderLayout.NORTH), c);
                   JLabel b = new JLabel("BBBBB");
                   c.gridx = 1;
                   mainPanel.add(panelize(b, BorderLayout.NORTH), c);
                   JEditorPane d = new JEditorPane("text/html", TEST_BIGTEXT);               
                   c.gridx = 2;
                   mainPanel.add(panelize(d, BorderLayout.CENTER), c);
                   JEditorPane e = new JEditorPane("text/html", TEST_BIGTEXT);               
                   c.gridx = 3;
                   mainPanel.add(panelize(e, BorderLayout.CENTER), c);
                   index++;
         public CGridBagLayout2() {
              super("GridBagLayout");
              mainPanel = new JPanel();
              addComponentsToMainPanel();
              scrollPane = new JScrollPane(mainPanel);
              setContentPane(scrollPane);
         public static void main(String[] args) {
              Frame frame;
              WindowListener exitListener;
              exitListener = new WindowAdapter() {
                   @Override
                   public void windowClosing(WindowEvent e) {
                        Window window = e.getWindow();
                        window.setVisible(false);
                        window.dispose();
                        System.exit(0);
              frame = new CGridBagLayout2();
              frame.addWindowListener(exitListener);
              frame.setPreferredSize(new Dimension(1000, 800));
              frame.pack();
              frame.setVisible(true);
    }Many thanks in advance, I'm getting crazy on this one :)

    Ok, thanks for this information, I thought I had seen this happening in the past when embedding a component in the center area of a JPanel with BorderLayout.
    Anyway, as I said I tested with JScrollPane as well and it does not change anything.
    Here is the code modified:
    @SuppressWarnings("serial")
    public final class CGridBagLayout2 extends JFrame {
         JPanel mainPanel;
         private final JScrollPane scrollPane;
         private JPanel panelize(Component component, String localization) {
              JPanel output = new JPanel(new BorderLayout());          
              output.add(component, localization);
              return output;
        public void addComponentsToMainPanel() {
              mainPanel.setLayout(new GridBagLayout());
              GridBagConstraints c = new GridBagConstraints();
              c.weightx = 1.0;
              c.fill = GridBagConstraints.BOTH;
              String TEST_BIGTEXT = "<html><body><h2>Path</h2>toto/tutu/tata/TestN<h2>Prerequisites</h2>blah blah blah blah<br/><b>blah blah</b> blah blah\nblah blah <u>blah</u> blahblah blah blah<h2>Description</h2>blah blah blah blah<br/><b>blah blah</b> blah blah\nblah blah <u>blah</u> blahblah blah blah blah\nblah blah blah <br/>lah blah blah <br/>lah blah blah blah blah blah blah blah FIN</body></html>";
              for (int index=0; index<10; index++) {
                   c.gridheight = 5; // nb Testcases for this test
                   c.anchor = GridBagConstraints.FIRST_LINE_START; // align all the components top-left aligned
                   c.gridy = index;
                   JLabel a = new JLabel("AAAAA");
                   c.gridx = 0;
                   mainPanel.add(panelize(a, BorderLayout.NORTH), c);
                   JLabel b = new JLabel("BBBBB");
                   c.gridx = 1;
                   mainPanel.add(panelize(b, BorderLayout.NORTH), c);
                   JEditorPane d = new JEditorPane("text/html", TEST_BIGTEXT);               
                   c.gridx = 2;
                   mainPanel.add(panelize(new JScrollPane(d), BorderLayout.CENTER), c);
                   JEditorPane e = new JEditorPane("text/html", TEST_BIGTEXT);               
                   c.gridx = 3;
                   mainPanel.add(panelize(new JScrollPane(e), BorderLayout.CENTER), c);
         public CGridBagLayout2() {
              super("GridBagLayout");
              mainPanel = new JPanel();
              addComponentsToMainPanel();
              scrollPane = new JScrollPane(mainPanel);
              setContentPane(scrollPane);
         public static void main(String[] args) {
              Frame frame;
              WindowListener exitListener;
              exitListener = new WindowAdapter() {
                   @Override
                   public void windowClosing(WindowEvent e) {
                        Window window = e.getWindow();
                        window.setVisible(false);
                        window.dispose();
                        System.exit(0);
              frame = new CGridBagLayout2();
              frame.addWindowListener(exitListener);
              frame.setPreferredSize(new Dimension(1000, 800));
              frame.pack();
              frame.setVisible(true);
    }Edited by: eric_gavaldo on Sep 15, 2010 2:18 PM

  • How to determine the maximum temperature in a consecutive of 2 minutes?

    I am doing the following application:
    1) Temperature signal is read in every 1 second, define in a while loop;
    2) I want to make sure that in a consecutive of 2 minutes, temperature value is always lower than a value, say 10 degree C;
    3) If it can meet the criterion, returns true, otherwise continue monitoring until it is true.
    A possible way it to define an 1D array with 120 elements, but I would like to know if there is a more elegant way? I cannot put the array in a subVI, as it is destroyed once subVI is left. LabVIEW system provides "RMS" calculation function (everything is in a sub VI) and I do not the function used in that VI.
    Solved!
    Go to Solution.

    Ah!! so thats what you meant, ok.
    You can easily implement this as a subvi:
    This is what the subvi would look like. You would use a while loop that only iterates once with an un-initialised shift register. This will then store the last value in its shift register.
    This is how it would look on your main vi:
    In this version you do not need to wire the time limit, its default value is 120. If you ever want to change this though you can wire in a new value.
    Rgs,
    Lucither
    Message Edited by Lucither on 05-06-2010 05:04 AM
    "Everything should be made as simple as possible but no simpler"
    Attachments:
    get if temp steady for 2 mins.vi ‏26 KB
    Temp comparison and increment demo.vi ‏9 KB

  • How Do You Set the Maximum Size of a JFrame?

    Can someone show me a quick example? The JFrame can be empty, I just want to know how to set it's maximum size. I tried using setMaximumSize() and it doesn't work for some reason but setMinimumSize() works fine.
    I tried it using a BoxLayout and even using null as a layout manager and can't get it to work. I heard that the other layout managers don't allow you to set the maximum size of a JFrame so that is why I tried it with the layouts that I did.
    I tried the following code (imported the necessary classes), but it does not work...
    public class MyFrame extends JFrame
        public MyFrame()
            super("TestFrame");
            setLayout( new BoxLayout(getContentPane(), BoxLayout.X_AXIS)  );       
            setMaximumSize( new Dimension(400,200));
            setSize(300,150);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setVisible( true );                
    }// end class

    Reposted from
    {color:#0000ff}http://forum.java.sun.com/thread.jspa?threadID=5236259{color}
    @OP:
    When you repost a topic, please always provide a link to the previous post so people can check what suggestions were already offered (and didn't solve the problem).
    Better still, give a short summary of the advice you have already tried.
    I suggested setBackground(...) so you can see whether your MyFrame is actually occupying the entire real estate of the window. Looks as if trying it out (which I would have done for you if I'd been at home, where my JDK is) would have been too much effort for you.
    I'm pretty much a novice in Swing, but I can tell you this: setLayout controls the layout of components added to the JFrame, not the layout of the frame with respect to its parent container.
    Luck, Darryl

  • How to determine the scratch disc size?

    hello,
    once i was reading an adobe pdf "How to get better performance in photoshop cs5" - that was in 2009 or 2010, and may be outdated, but there was a calculation method
    to determine the size of a scratch disc. (similar calculation see below, if i can remember right)
    i am asking myself, how can i determine the correct size of an external SSD-scratch disc, only used by photoshop (completely empty):
    should i buy a 128GB or 256GB or 512GB SSD which is only reserved for photoshop?
    basic question 1 : i guess i should avoid to set the internal SSD as photoshop scratch disc, as it slows down everything?
    basic question 2 : in sense of maximum performance: better buy an external USB3.0 or thunderbolt SSD? will photoshop really use the extra thunderbolt speed when swapping data?
    secondary question:
    can i calculate the size regarding my daily working habits?
    i am mainly working like this:
    - with my imac 27" late 2013 with 32GB RAM and 256 GB internal pci-e SSD (800 MB/sec), which will stay always half empty for performance reasons.
    - OSX 10.8 mountain lion and 10.9 mavericks soon
    - photoshop cs5, cs6 and cc (always without extended)
    - 8bit and 16bit mode
    - only RGB
    - with latest phocus/Hasselblad and canon RAW Files which produce a basic .psb document at ...
    - 10.000 x 7000 px at 300dpi
    - with average 10 - 40 main image layers and 20-50 adjustement layers (try to reduce that in 16bit)
    - .psb file is 2-20 GB big (file in finder)
    - 16bit file compression is off, when saving .psb files (faster handling)
    -  set photoshop to 70% ram usage (from 32GB RAM)
    i wonder how to calculate ?
    for example:
    10.000 x 7000 px at 300dpi needs for one image layer at 16bit: 2GB RAM in photoshop cs6 or cc (just as a number), this may be wrong
    so lets take 2GB RAM and multiply with 10 image layers in my .psb file (16bit) = 20 GB RAM, and multiply with 20 adjustment layers (guess they need less ram, for one lets say 500MB) = 20GB + 10GB = this 16bit .psb layer file would need 30GB RAM, so when i have 32GB in my imac, i set cs6 or cc to 70% ram usage, it misses at least round 8-10GB RAM > can i guess that photoshop would swap these 8GB onto my scratch disc? or do i miss something important in my thinking?
    tricky thinking
    thanks for help

    station_two wrote:
    The rule of thumb I follow says to figure on 50 to 100 times the size of your largest file ever multiplied by the number of files you have open.  I have seen the scratch file exceed 300 GB once, an admittedly rare occurrence, but it often exceeds 200 GB when stitching large panoramas and the like.
    As an example—and stressing that I'm aware that others have even more scratch space than I do—I keep two dedicated, physically separate hard drives as my primary and secondary Photoshop scratch disks and a lot of GB free on my boot drive for the OS.  I also have 16 GB of RAM installed.
    Additionally, if you only have a single HD, i.e. your boot drive, you'd need it to be large enough to accommodate both the swap files of the OS as well as Photoshop's scratch.
    - i dont use HDD anymore only SSDs, both internal and external
    - i set history state to only 5 or 6, to improve performance
    - i set cache size to 4 and tiles to "big and flat" with 1028kb (there is no "big and much layers" option)
    - is this still the rule of thumb? i read it in 2009 , too, guess it was outdated, as cs6 and cc have improved codes in terms of performance?
    - if you say "50 to 100 times the size of your largest file ever multiplied by the number of files you have open.":
    i will not open more than one document at same time to prevent performance lags, so lets calc like: dokument size in finder (you mean in finder or doc. size shown in photoshop?) = e.g. 5GB x 100 = 500GB, so my external scratch disc SSD, i would buy now, should be at least 500GB, USB 3.0 or thunderbolt ... maybe better thunderbolt, yes? with usb 3.0 i could gain 300MB/sec if thats enough for photoshop?
    thanks

  • How do you Determine the Largest Size/Fastest Speed Hard Drive

    In general, how do you determine the maximum hard drive size/speed you can upgrade to?

    As long as the drive your are considering physically fits as already stated there is no maximum size you can install. Please complete your profile so we know what machine you have.
    If your machine is covered by a warranty or AppleCare I would recommend against installing another HD as this may invalidate the warranty. I would recommend in that case using a Firewire 800 external HD instead.
    Regards,
    Roger

Maybe you are looking for