Jscrollbar problem

Hii there,
I'm having a JInternalFrame, and within that frame, I added a jlabel. the jlabel contains several images that is being added dynamically. I've added a horizontal scrollbar that is working. but my problem is with the vertical scrollbar. The thing is whenever an image added to jlabel, height of the label increases and the label exceeds to internalframe. The vertivcal scrollbar does not working to see the exceeded part of the jlabel,
My code is something like this:
                        dpane.setDesktopManager(new DefaultDesktopManager());
                        iframe=new JInternalFrame("Image Frame" ,true,true,true,true);  
                        vScrollBar = new JScrollBar(JScrollBar.VERTICAL);
                        vScrollBar.setValue(jLabel.getHeight());
                        vScrollBar.setValueIsAdjusting(true);                      
                        iframe.getContentPane().add(vScrollBar,BorderLayout.EAST);
                        iframe.getContentPane().add(jLabel,BorderLayout.CENTER);                                                                                                        
                        dpane.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
                        dpane.add(iframe);               
                        iframe.setVisible(true);
                        add(dpane);could you else please help me!
thanks in advance...
Dev

You haven't written the code that links scroll bar and its target view component.
Use JScrollPane and a simple container JPanel.
Forget your scroll bar and the label.

Similar Messages

  • Problem with JPanel and JScrollBar

    I am having a few problems displaying a progress bar, it is called by the program when needed. The problem is the JFrame appears but no panel seems to be added to it and what app is in the background can be seen through it.
    The frame, panel and progressbar are all declared as global variables at the start of the program.
    I have tried using pack() and repaint() but not had any luck and not really sure how to proceed.
    Thanks in advance
    Aaron
       private void setupProgBar(String title)
          //sets up progress Jframe to contain progress bar
          progress.setTitle(title);
          progress.setMinimumSize(new Dimension(300,100));
          progress.setLocationRelativeTo(null);
          progress.setAlwaysOnTop(true);
          progressPanel.setLayout(new GridBagLayout());
          loadMedia.setIndeterminate(true);
          GridBagConstraints c = new GridBagConstraints();
          c.fill = GridBagConstraints.HORIZONTAL;
          c.weighty = 0.5;
          c.gridx = 0;
          c.gridy = 0;
          progressPanel.add(loadMedia, c);
          progress.add(progressPanel);
          progress.setVisible(true);
       }

    It's clearly a concurrency issue. Please go through this tutorial:
    The Java™ Tutorials: [Concurrency in Swing|http://java.sun.com/docs/books/tutorial/uiswing/concurrency/index.html|The best way to learn!]
    db

  • Problems with JScrollBar

    Hi
    It's my second attempt to find answer for this question on this forum :)
    I have a JPanel where i display an image. The size of the panel is set to the size of the image. Panel is added to a JScrollPane, which is added to a JFrame.
    Now, here's the problem:
    Sometimes, after frame.pack() the size of the panel is equal to the size of the image, sometimes it's bigger by the size of the scrollbars (however they are not visible, there's only gray background), sometimes there's visible place for vertical scrollbar, sometimes horizontal, sometimes both. Sometimes the size of the frame blocks and it doesn't resize anymore and then scrollbars don't show either.
    I'm new to Java, but i can't figure out why using always the same code i get different results.
    Here's the code:
    // Initialize
    frame = new JFrame(title);
    panel = new JImagePanel();
    scrollPane = new JScrollPane(panel);
    frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
    panel.setPreferredSize(new Dimension(400, 400));
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
    // Code for displaying an image
        public void viewPicture(BufferedImage image, String name) {
            // Set panels private variable which is used in paintComponent()
            panel.setImage(image);
            //Reset frame size
            frame.setPreferredSize(null);
            // Set size of the panel to the size of the image
            panel.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
            // Set title of the frame to the image name
            frame.setTitle(title + " - " + name);
            frame.pack();
            // Repaint the panel
            panel.update(panel.getGraphics());
           // Following part of the code is only for restricting frame size so it won't be
           // larger than the screen
            // Check frame size
            Dimension frameSize = frame.getSize();
            // Check screen resolution
            Dimension screenSize = toolkit.getScreenSize();
            // If the frame is bigger than screen       
            if( frameSize.width > screenSize.width || frameSize.height > screenSize.height)
                // Get scrollbars width
                UIDefaults def = UIManager.getDefaults();
                Object Width = def.get("ScrollBar.width");
                Integer intWidth = (Integer)Width;
                int scrollBarWidth = intWidth.intValue();
                if ( frameSize.width > screenSize.width )
                    frameSize.width = screenSize.width;           
                else
                    frameSize.width = image.getWidth() +  scrollBarWidth;
                                                    //frame.getInsets().left +
                                                    //frame.getInsets().right +
                if ( frameSize.height > screenSize.height )
                    frameSize.height = screenSize.height;
                else
                    frameSize.height = image.getHeight() + scrollBarWidth;
                // Limit frame to the size of the screen
                frame.setPreferredSize(frameSize);                               
                frame.pack();           
            frame.setLocationRelativeTo(null);
        }

    problem in ur program can be eliminated simply!
    First please post the complete runnable program
    By looking at your posted program part - i found nothing wrong!
    so please post the complete runnable demo(atleast)
    and get the solution at this post(from others also!)
    few suggestions:
    1. If the size of the image gets bigger than the screen size
    then can't set the frame size equivalent to the image size.
    (u done it after ... but may...problem..)
    2. only set the panel size equivalent to the image size

  • Problems with  print range from 1 to 9999 during printing

    Hi All,
    In my project i am printing the datas in a JTable by a click of the button.I have used the following link:-
    http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/advprint.html
    to print that data from the JTable.The main problem i have is that
    1) The font size in which the tableheader and tabledatas printed are so small.So that i need to increase the font size for both tableheader and tabledatas?
    2)When i click the printButton for printing it opens a dialog box showing print range from 1 to 9999. And in the pages from 1 to 9999.
    I don't want this.I want only 1 to 1.I know that by using Pageable
    interface u can change it.But i don't know how to do it
    Any one help me to solve this 2 problems i will be very thankful to u.It is Urgent.For ur reference i will provide my Code:-
    import javax.swing.*;
    import javax.swing.table.*;
    import java.awt.print.*;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.Dimension;
    import java.io.*;
    public class PrintReportPanels extends JPanel implements Printable
    JTable tableView;
    String aLine="";
    DefaultTableModel model;
    Vector columnNames = new Vector();
    Vector data = new Vector();
    JScrollBar jsb = new JScrollBar(JScrollBar.HORIZONTAL);
    JScrollBar jsb1 = new JScrollBar(JScrollBar.VERTICAL);
    JPanel southPanel=new JPanel();
    JPanel printPanel=new JPanel();
    JButton printButton=new JButton();
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    private Font fnt=new Font("Arial",Font.PLAIN,20);//Not working for increasing the font size
    public PrintReportPanels()
         try
    this.setLayout(new BorderLayout());
    UIManager.put("ScrollBar.track",Color.red);
    UIManager.put("ScrollBar.thumb",Color.blue);
         FileInputStream fin = new FileInputStream("Spooler.txt");
         BufferedReader br = new BufferedReader(new InputStreamReader(fin));
         // extract column names
         StringTokenizer st1 = new StringTokenizer(br.readLine());
         while( st1.hasMoreTokens() )
         columnNames.addElement(st1.nextToken());
         }               // extract data
         while((aLine = br.readLine())!=null) //br.readLine() which contains the Spooler.txt datas is assigned to aLine
         StringTokenizer st2 = new StringTokenizer(aLine);
         Vector row = new Vector();
         while(st2.hasMoreTokens())
         row.addElement(st2.nextToken());
         data.addElement( row );
         br.close();
         catch (Exception e)
              e.printStackTrace();
    model = new DefaultTableModel(data,columnNames);
    tableView = new JTable(model);
    JScrollPane jsp = new JScrollPane(tableView);
    this.add(jsp,BorderLayout.CENTER);
    this.add(jsb,BorderLayout.SOUTH);
    this.add(jsb1,BorderLayout.EAST);
    this.add(southPanel,BorderLayout.SOUTH);
    southPanel.setLayout(new FlowLayout());
    ImageIcon ic=new ImageIcon("print.gif");
    printButton.setIcon(ic);
    printButton.setBackground(Color.white);
    printPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    printPanel.add(printButton);
    southPanel.add(printPanel);
    this.validate();
    this.repaint();
    printButton.addActionListener( new ActionListener(){
    public void actionPerformed(ActionEvent evt) {
         PrinterJob pj=PrinterJob.getPrinterJob();
         pj.setPrintable(PrintReportPanels.this);
         pj.printDialog();
         try{
              pj.print();
         }catch (Exception PrintException) {}
    public int print(Graphics g, PageFormat pageFormat,int pageIndex) throws PrinterException
         Graphics2D g2 = (Graphics2D) g;
         g2.setColor(Color.black);
         g2.setFont(fnt);
         int fontHeight=g2.getFontMetrics().getHeight();
         int fontDesent=g2.getFontMetrics().getDescent();
         //leave room for page number
         double pageHeight = pageFormat.getImageableHeight()-fontHeight;
         double pageWidth = pageFormat.getImageableWidth();
         double tableWidth = (double) tableView.getColumnModel().getTotalColumnWidth();
         double scale = 1;
         if (tableWidth >= pageWidth) {
              scale = pageWidth / tableWidth;
         double headerHeightOnPage=
    tableView.getTableHeader().getHeight()*scale;
         double tableWidthOnPage=tableWidth*scale;
         double oneRowHeight=(tableView.getRowHeight()+
    tableView.getRowMargin())*scale;
         int numRowsOnAPage=
    (int)((pageHeight-headerHeightOnPage)/oneRowHeight);
         double pageHeightForTable=oneRowHeight*numRowsOnAPage;
         int totalNumPages= (int)Math.ceil((
    (double)tableView.getRowCount())/numRowsOnAPage);
         if(pageIndex>=totalNumPages)
    return NO_SUCH_PAGE;
         g2.translate(pageFormat.getImageableX(),
    pageFormat.getImageableY());
         g2.drawString("Page: "+(pageIndex+1),(int)pageWidth/2-35, //For printing the page no. at the bottom
    (int)(pageHeight+fontHeight-fontDesent));//bottom center
         g2.translate(0f,headerHeightOnPage);
         g2.translate(0f,-pageIndex*pageHeightForTable);
         //If this piece of the table is smaller than the size available,
         //clip to the appropriate bounds.
         if (pageIndex + 1 == totalNumPages)
    int lastRowPrinted = numRowsOnAPage * pageIndex;
    int numRowsLeft = tableView.getRowCount() - lastRowPrinted;
    g2.setClip(0, (int)(pageHeightForTable * pageIndex),
    (int) Math.ceil(tableWidthOnPage),
    (int) Math.ceil(oneRowHeight * numRowsLeft));
         //else clip to the entire area available.
         else{
    g2.setClip(0, (int)(pageHeightForTable*pageIndex),
    (int) Math.ceil(tableWidthOnPage),
    (int) Math.ceil(pageHeightForTable));
         g2.scale(scale,scale);
         tableView.paint(g2);
         g2.scale(1/scale,1/scale);
         g2.translate(0f,pageIndex*pageHeightForTable);
         g2.translate(0f, -headerHeightOnPage);
         g2.setClip(0, 0,(int) Math.ceil(tableWidthOnPage),
    (int)Math.ceil(headerHeightOnPage));
         g2.scale(scale,scale);
         tableView.getTableHeader().paint(g2);//paint header at top
         return Printable.PAGE_EXISTS;
    public static void main(String[] args)
         JFrame frame=new JFrame();
         RepaintManager.currentManager(frame).setDoubleBufferingEnabled(false);
         JPanel panel=new PrintReportPanels();
         frame.getContentPane().add(panel);
         frame.setSize(800,600);
         frame.setVisible(true);
    Pls. do provide the reply and tell me where i go wrong.I will be waiting for ur reply.It is very Urgent.
    Thanx,
    m.ananthu

    Hi conner,
    1) My font size problem is over i have used the tablename.setFont(new Font("Arial",Font.PLAIN,20)).It does change the font size of the JTable contents but the JTable Header still remains the same.I want to change the font size of the JTable header as well.How to do it?
    2)According to my second problem can u provide the code of how to change the page range from 1 - 9999 to 1-1?So that i will be very thankful to u.
    Thanx,
    m.ananthu

  • Changing Arrows and Color of a JScrollBar inside of a JScrollPane

    Hi. I can't believe this hasn't been asked and answered before but I can't find it in these forums if it has.
    I am trying to create a JScrollPane in a touchscreen based application - no mouse... The default scrollbar
    in my JScrollPane is too small for large fingers. I have successfully increased the size of the scrollbar
    to a usable size using: UIManager.put("scrollbar.width", 75).
    My next problem is two-fold.
    1) The arrows at top and bottom of the scrollbar are now heavily pixelated (i.e. jagged and blocky) and
    look like we zoomed in too much on a bitmap. How can I change these arrows to a graphic that is
    more related to the current size of my scrollbar?
    2) The color of the scrollbar is shades of 'baby blue'. My color scheme for my application is shades of
    beige or brown. This makes the scrollbar stand out like a sore thumb. How can I change the color
    of the scrollbar?
    Note: This is being coded in NetBeans 6.7.1 but I can't find any property in the visual editor that covers
    my problems.
    Also, I came across the UIManager.put("scrollbar.width", xx) from googling. Is there an official (complete)
    list of the properties available to the UIManager?
    Thanks

    To help out anyone who has been struggling with this as I have, here is the final solution we were able to use. We only needed to work with the vertical scroll bar, but it should be easy to work with now that a better part of the work is done. I do hope this is helpful.
         public ReportDisplayFrame()
              UIManager.put( "ScrollBar.width", 75);
              RDFScrollBarUI rdfScrlBarUI = new RDFScrollBarUI();
              rdfScrlBarUI.setButtonImageIcon( new ImageIcon( "C:/company/images/upArrow.jpg") , rdfScrlBarUI.NORTH);
              rdfScrlBarUI.setButtonImageIcon( new ImageIcon( "C:/company/images/downArrow.jpg") , rdfScrlBarUI.SOUTH);
              tempScrlBar = new JScrollBar();
              tempScrlBar.setBlockIncrement( 100);
              tempScrlBar.setUnitIncrement( 12);
              tempScrlBar.setUI( rdfScrlBarUI);
    // other constructor code //
              rdfScreenRedraw();
         private void rdfScreenRedraw()
              String methodName = "rdfScreenRedraw()";
              logger.log(Level.INFO, methodName + ": Revalidating: mainPanel Thread = ["+Thread.currentThread().getName()+"]");
              jPanelRpt.revalidate();
              jPanelRpt.repaint();
         class RDFScrollBarUI extends BasicScrollBarUI {
              private ImageIcon decImage = null;
              private ImageIcon incImage = null;
              public void setThumbColor(Color thumbColor) {
                   this.thumbColor = thumbColor;
              public void setThumbDarkShadowColor(Color thumbDarkShadowColor) {
                   this.thumbDarkShadowColor = thumbDarkShadowColor;
              public void setThumbHighlightColor(Color thumbHighlightColor) {
                   this.thumbHighlightColor = thumbHighlightColor;
              public void setThumbLightShadowColor(Color thumbLightShadowColor) {
                   this.thumbLightShadowColor = thumbLightShadowColor;
              public void setTrackColor(Color trackColor) {
                   this.trackColor = trackColor;
              public void setTrackHighlightColor(Color trackHighlightColor) {
                   this.trackHighlightColor = trackHighlightColor;
              public void setButtonImageIcon( ImageIcon theIcon, int orientation)
                   switch( orientation)
                        case NORTH:
                             decImage = theIcon;
                             break;
                        case SOUTH:
                             incImage = theIcon;
                             break;
                        case EAST:
              if (scrollbar.getComponentOrientation().isLeftToRight())
                                  decImage = theIcon;
                             else
                                  incImage = theIcon;
                             break;
                        case WEST:
              if (scrollbar.getComponentOrientation().isLeftToRight())
                                  incImage = theIcon;
                             else
                                  decImage = theIcon;
                             break;
              @Override
              protected JButton createDecreaseButton(int orientation) {
                   JButton button = null;
                   if ( decImage != null)
                        button = new JButton( decImage);
                   else
                        button = new BasicArrowButton(orientation);
                   button.setBackground( new Color( 180,180,130));
                   button.setForeground( new Color( 236,233,216));
                   return button;
              @Override
              protected JButton createIncreaseButton(int orientation) {
                   JButton button = null;
                   if ( incImage != null)
                        button = new JButton( incImage);
                   else
                        button = new BasicArrowButton(orientation);
                   button.setBackground( new Color( 180,180,130));
                   button.setForeground( new Color( 236,233,216));
                   return button;
         }

  • Problem with JTableHeader Render

    Hello,
    I am using JTableHeader renderer as below:
    TableHeaderRender headerRender;
    fixedModel.addColumn("");
                   TableColumnModel colModel = Table.getColumnModel();
                   for(int i=0; i<colModel.getColumnCount(); i++ )
                        colModel.getColumn(i).setHeaderRenderer(headerRender);
    And the renderer is as below:
    class FixedTableHeaderRender extends DefaultTableCellRenderer
              JLabel label = null;
              String[] selectList= {"Item1","item 2", Item 3", "Item 4"};
              JComboBox ColStatBox= new JComboBox(selectList);
    public FixedTableHeaderRender()
    super();
    label = new JLabel();
    label.setOpaque(true);
    label.setBorder(new LineBorder(Color.black));
    label.setHorizontalAlignment(SwingConstants.CENTER);
    label.setVerticalAlignment(SwingConstants.CENTER);
    ColStatBox.setSelectedIndex(0);
    ColStatBox.setEnabled(true);
    ColStatBox.setAutoscrolls(true);
    ColStatBox.addActionListener(new ActionHandler(){
    public Component getTableCellRendererComponent(JTable table, Object value,
              boolean isSelected,boolean hasFocus, int row,int column)
         Component comp= null;
         if(column==0)
              comp=ColStatBox;
         else
              label.setText("100");
              comp=label;
         return comp;
    Now in this for First column header the JComboBox is displayed and for rest of the column the label is displayed.
    But in this, the JComboBox is not working i.e. I am not able the browse through the list. If I want to select any item (Item 4), its not allowing me to select.
    How to make it enable and function normally?
    Do reply.
    Thanks and regards,
    Sheetal

    I've amended your code as shown. Some points:
    1) Not sure what all the scroll bar stuff is for, I've removed it.
    2) The method DefaultTableModel.addColumn is too crude. If you look at the JDK source it calls fireTableStructureChanged(). This has the effect of recreating the column model, which in turn resets all the widths. It will also clear out any renderers/editors you had set up within the TableColumn instances inside the TableColumnModel (if any). Those setup by column class would be OK (I think).
    I didn't look into the remainder of your problem, hopefully you are OK now...
    import java.awt.BorderLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JScrollBar;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.table.*;
    import javax.swing.table.DefaultTableModel;
    public class MyJTable extends JFrame
    DefaultTableModel model;
    JButton addBtn;
    JTable table;
    JScrollBar scrollBar;
    JScrollPane scrollPane;
         public MyJTable()
              getContentPane().setLayout(new BorderLayout());
              Object[] header= {"1", "2"};
              model= new DefaultTableModel();
              model.setDataVector(null,header);
               table = new JTable(model);
               table.getTableHeader().setReorderingAllowed(false);
               table.getTableHeader().setResizingAllowed(true);
               table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
               scrollBar=new JScrollBar();
              scrollBar.setOrientation(1);
              scrollBar.setBlockIncrement(1);
              scrollBar.setMinimum(0);
              scrollBar.setMaximum(50);
              scrollBar.setUnitIncrement(1);
              scrollBar.setVisibleAmount(1);
              table.add(scrollBar);
              scrollPane=new JScrollPane(table);
              scrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
               addBtn=new JButton("Add Column");
               addBtn.addActionListener(new ActionHandler());
               getContentPane().add(scrollPane, BorderLayout.CENTER);
               getContentPane().add(addBtn, BorderLayout.SOUTH);
         class ActionHandler implements ActionListener
              //@Override
              public void actionPerformed(ActionEvent ae)
                   // TODO Auto-generated method stub
                   if(ae.getSource()==addBtn)
                        //model=(DefaultTableModel)table.getModel();
                        //model.addColumn("A");
                        //model.fireTableStructureChanged();
                        TableColumnModel tcm = table.getColumnModel();
                        TableColumn newCol = new TableColumn();
                        newCol.setHeaderValue("A");
                        tcm.addColumn(newCol);
          * @param args
         public static void main(String[] args)
              MyJTable frame = new MyJTable();
                  frame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {
                      System.exit(0);
                  frame.setSize( 300, 400 );
                  frame.setVisible(true);
    }

  • Using JScrollBar with JTextArea

    hey!
    i'm using JDev 10g, creating a Swing Application
    i have a JTextArea and a JScrollBar (both which I have dragged down from Component Palette)
    how to I use JScrollBar with the JTextArea, such that the JScrollBar response to the JTextArea
    help me out...
    Cheers,
    Shivek

    this is the problem:
    i have a JTextArea and a JScrollBar which I have "DRAGGED" down from the component pallette in JDev...
    how do I make the JScrollBar work for the JTextArea... because right now the JTextArea is not responsing to the JScrollBar...
    so when the text is flooded in the JTextArea, scrolling the JScrollBar doesnt work
    this is my code:
    private JTextArea jTextArea1 = new JTextArea();
    private JScrollBar jScrollBar1 = new JScrollBar();
    private void jbInit() throws Exception
    this.getContentPane().add(jScrollBar1, null);
    this.getContentPane().add(jTextArea1, null);
    can u tell me wat code is missing! I've tried everything... read many tutorials some of them uses a panel...
    cheers,
    Shivek

  • SwingUtilities.paintComponent - problems with painting childs of components

    Maybe this question was mention already but i cant find any answer...
    Thats what could be found in API about method paintComponent in SwingUtilities:
    Paints a component c on an arbitrary graphics g in the specified rectangle, specifying the rectangle's upper left corner and size. The component is reparented to a private container (whose parent becomes p) which prevents c.validate() and c.repaint() calls from propagating up the tree. The intermediate container has no other effect.
    The component should either descend from JComponent or be another kind of lightweight component. A lightweight component is one whose "lightweight" property (returned by the Component isLightweight method) is true. If the Component is not lightweight, bad things map happen: crashes, exceptions, painting problems...
    So this method perfectly works for simple Java components like JButton / JCheckbox e.t.c.
    But there are problems with painting JScrollBar / JScrollPane (only background of this component appears).
    I tried to understand why this happens and i think the answer is that it has child components that does not draw at all using SwingUtilities.paintComponent()
    (JScrollBar got at least 2 childs - 2 buttons on its both sides for scroll)
    Only parent component appears on graphics - and thats why i see only gray background of scrollbar
    So is there any way to draw something like panel with a few components on it if i have some Graphics2D to paint on and component itself?
    Simple example with JScrollPane:
    JScrollPane pane = new JScrollPane(new JLabel("TEST"));
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    SwingUtilities.paintComponent(g2d, pane, new JPanel(), 0, 0, 200, 200);Edited by: mgarin on Aug 11, 2008 7:48 AM

    Well the thing you advised could work... but this wont be effective, because i call repaint of the area, where Components painted, very often..
    So it will lag like hell when i make 10-20 repaints in a second... (for e.g. when i drag anything i need mass repainting of the area)
    Isnt there any more optimal way to do painting of the sub-components?
    As i understand when any component (even complicated with childs) paints in swing - its paint method calls its child components paint() to show them... can this thing be reproduced to paint such components as JScrollPane?

  • JScrollBar - Issue when changing models

    Hey All-
    Well, I've come up with another interesting question which I haven't been able to resolve myself.
    Basically, I have a single view port which consists of a custom JPanel and (2) JScrollbar's. I then have multiple data and view models which are attached to each of these components. I then have a JList which has a list of all the Data/View Models. When a user selects one of the Data/View Models from the JList, that Data/View Model is attached to the JPanel and (2) JScrollbar's.
    Overall, this method seems to be working fine. When I select a new Data/View Model, the JPanel and both JScrollbar's update as expected. What happens next is unexpected though. If I then try to scroll one of the JScrollbar's, it jumps from its correct position to the last scrolled to position.
    Here is a scenario that might explain it better:
    1. Select one specific view model (which is basically a BoundedRangeModel for this scenario).
    2. Use the scrollbar and scroll to a value of 100 (keeping it simple).
    3. Select a new view model which has a value of 50 - the scrollbar now updates so instead of being located at value 100, it is now located at value 50
    4. Use the scrollbar to scroll to a new value - when clicking with the mouse on the scrollbar, the scrollbar jumps back to a value of 100 and does not move. You must click the scrollbar again to begin scrolling, yet it is only affecting the selected View/Model, and no other model.
    I have gone through all the code for the JScrollbar and its setModel() function from the Java source and there doesn't seem to be any obvious reason why this would be happening. Its almost as if the Scrollbar is somehow remembering its last scrolled to value and then jumping to this the first time you try to scroll, despite it not matching the value or extent contained within the RangeModel.
    Right now this is a minor annoyance, but I'm wondering if anyone else has experience this issue.
    Thanks!

    Well, I somehow didn't receive notice that someone had responded to this thread, so sorry for not replying back sooner.
    I did some additional digging using a simple application (which I will post below), and I have determined that this only appears to affect the Java Version 6. I have created and run the following simple test application in Netbeans using Java 6 in both Windows and Linux and have had the exhibited result above, but running Eclipse and Java 5 it appears to work fine (I use the IDE's to control which version of Java I am running).
    Here's the Code:
    package scrollbartest;
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.DefaultBoundedRangeModel;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.JScrollBar;
    public class ScrollbarTest extends JFrame implements ActionListener {
        public JScrollBar               displayScrollBar;          
        public ScrollbarTest() {
                super();
                this.setTitle("Scrollbar Test");
                this.setLayout(new BorderLayout());
                this.setPreferredSize(new Dimension(500, 350));
                this.setSize(new Dimension(500, 350));
                this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                displayScrollBar = new JScrollBar();
                displayScrollBar.setOrientation(JScrollBar.HORIZONTAL);
                setModel();
                this.add(displayScrollBar, BorderLayout.NORTH);
                JButton updateButton = new JButton("Update Model");
                updateButton.addActionListener(this);
                updateButton.setVisible(true);
                this.add(updateButton, BorderLayout.SOUTH);
                this.pack();
        private void setModel() {
                DefaultBoundedRangeModel rangeModel = new DefaultBoundedRangeModel();
                rangeModel.setMinimum(0);
                rangeModel.setMaximum(100);
                rangeModel.setValue(0);
                rangeModel.setExtent(0);
                displayScrollBar.setModel(rangeModel);
        public static void main(String[] args) {
                ScrollbarTest app = new ScrollbarTest();
                app.setVisible(true);
        public void actionPerformed(ActionEvent arg0) {
                this.setModel();
    }And here's how to recreate the problem:
    1. Launch a Java application using the above as the main class.
    2. Move the scrollbar to some location other than the starting point.
    3. Click the "Update Model" button which should reset the scrollbar using a new model.
    4. Attempt to click (once) on the scrollbar position.
    At step 4, using Java 6, the scrollbar "jumps" back to the position where it was located before setting the new model. This does not appear to change the value of the new model, and it locks out any more motion of the scrollbar until you release the mouse button and press again. At this point, the scrollbar begins functioning properly, except that it is now starting at the old models value instead of the current models value (which remains 0 until you click and drag a second time).
    Using Java 5, this program works exactly as expected. My thought is that somehow the Scrollbar is keeping a reference to the old model or its values even after the model has changed for one more iteration. It seems to be the only thing that makes sense.
    In any case, any help is greatly appreciated.

  • Problems with java after the last update

    Hi, yesterday I downloaded and install the last update available for Snow Leopard. After having installed the update, I had problems with Matlab (I use the version R2010a), and the error code is reported below. Do you think the error and the update are correlated? Do you have any idea of how to fix the problem?
    Many thanks, and cheers!
    Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 90
    at java.lang.String.substring(String.java:1934)
    at com.mathworks.widgets.tokenmatch.TokenMatchSyntaxLabel$PaintedBasicLabelUI.pain tEnabledText(TokenMatchSyntaxLabel.java:460)
    at javax.swing.plaf.basic.BasicLabelUI.paint(BasicLabelUI.java:162)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:153)
    at javax.swing.JComponent.paintComponent(JComponent.java:752)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintChildren(JComponent.java:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.java:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
    at javax.swing.JComponent.paintChildren(JComponent.java:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:34)
    at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
    at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
    at java.awt.Container.paint(Container.java:1793)
    at java.awt.Window.paint(Window.java:3375)
    at sun.awt.RepaintArea.paintComponent(RepaintArea.java:276)
    at sun.awt.RepaintArea.paint(RepaintArea.java:241)
    at apple.awt.ComponentModel.handleEvent(ComponentModel.java:263)
    at apple.awt.CWindow.handleEvent(CWindow.java:525)
    at java.awt.Component.dispatchEventImpl(Component.java:4812)
    at java.awt.Container.dispatchEventImpl(Container.java:2143)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4566)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:680)
    at java.awt.EventQueue.access$000(EventQueue.java:86)
    at java.awt.EventQueue$1.run(EventQueue.java:639)
    at java.awt.EventQueue$1.run(EventQueue.java:637)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:653)
    at java.awt.EventQueue$2.run(EventQueue.java:651)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:650)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:29 6)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:20 1)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Exception in thread "AWT-EventQueue-0" java.lang.StringIndexOutOfBoundsException: String index out of range: 90
    at java.lang.String.substring(String.java:1934)
    at com.mathworks.widgets.tokenmatch.TokenMatchSyntaxLabel$PaintedBasicLabelUI.pain tEnabledText(TokenMatchSyntaxLabel.java:460)
    at javax.swing.plaf.basic.BasicLabelUI.paint(BasicLabelUI.java:162)
    at javax.swing.plaf.ComponentUI.update(ComponentUI.java:153)
    at javax.swing.JComponent.paintComponent(JComponent.java:752)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintChildren(JComponent.java:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JComponent.paintChildren(JComponent.java:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at javax.swing.JLayeredPane.paint(JLayeredPane.java:567)
    at javax.swing.JComponent.paintChildren(JComponent.java:862)
    at javax.swing.JComponent.paint(JComponent.java:1038)
    at java.awt.GraphicsCallback$PaintCallback.run(GraphicsCallback.java:34)
    at sun.awt.SunGraphicsCallback.runOneComponent(SunGraphicsCallback.java:60)
    at sun.awt.SunGraphicsCallback.runComponents(SunGraphicsCallback.java:97)
    at java.awt.Container.paint(Container.java:1793)
    at java.awt.Window.paint(Window.java:3375)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:822)
    at javax.swing.RepaintManager.paintDirtyRegions(RepaintManager.java:713)
    at javax.swing.RepaintManager.seqPaintDirtyRegions(RepaintManager.java:693)
    at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueue Utilities.java:125)
    at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:678)
    at java.awt.EventQueue.access$000(EventQueue.java:86)
    at java.awt.EventQueue$1.run(EventQueue.java:639)
    at java.awt.EventQueue$1.run(EventQueue.java:637)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:648)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:29 6)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:20 1)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188

    Exception in thread "AWT-EventQueue-0" java.lang.NegativeArraySizeException
    at org.netbeans.editor.DrawGraphics$GraphicsDG.flush(DrawGraphics.java:655)
    at org.netbeans.editor.DrawGraphics$GraphicsDG.flush(DrawGraphics.java:522)
    at org.netbeans.editor.DrawGraphics$GraphicsDG.setBuffer(DrawGraphics.java:756)
    at org.netbeans.editor.DrawEngine.draw(DrawEngine.java:1116)
    at org.netbeans.editor.DrawEngineLineView.paint(DrawEngineLineView.java:233)
    at org.netbeans.lib.editor.view.GapBoxViewChildren.paintChildren(GapBoxViewChildre n.java:783)
    at org.netbeans.lib.editor.view.GapBoxView.paint(GapBoxView.java:1463)
    at org.netbeans.lib.editor.view.GapDocumentView.paint(GapDocumentView.java:231)
    at org.netbeans.editor.DrawEngineDocView.paint(DrawEngineDocView.java:314)
    at org.netbeans.editor.view.spi.LockView.paint(LockView.java:363)
    at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1423)
    at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:723)
    at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:870)
    at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:849)
    at javax.swing.JComponent.paintComponent(JComponent.java:752)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5146)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java :1515)
    at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1446)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1260)
    at javax.swing.JComponent.paintForceDoubleBuffered(JComponent.java:1065)
    at javax.swing.JViewport.blitDoubleBuffered(JViewport.java:1612)
    at javax.swing.JViewport.windowBlitPaint(JViewport.java:1573)
    at javax.swing.JViewport.setViewPosition(JViewport.java:1118)
    at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(BasicScrollPan eUI.java:1029)
    at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(BasicScrollPaneUI .java:1018)
    at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel. java:348)
    at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeMode l.java:285)
    at javax.swing.DefaultBoundedRangeModel.setValue(DefaultBoundedRangeModel.java:151 )
    at javax.swing.JScrollBar.setValue(JScrollBar.java:446)
    at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.mouseWheelMoved(BasicScrollPan eUI.java:964)
    at javax.swing.plaf.basic.BasicScrollPaneUI$MouseWheelHandler.mouseWheelMoved(Basi cScrollPaneUI.java:525)
    at com.apple.laf.AquaScrollPaneUI$XYMouseWheelHandler.mouseWheelMoved(AquaScrollPa neUI.java:38)
    at java.awt.Component.processMouseWheelEvent(Component.java:6462)
    at java.awt.Component.processEvent(Component.java:6146)
    at java.awt.Container.processEvent(Container.java:2085)
    at java.awt.Component.dispatchEventImpl(Component.java:4736)
    at java.awt.Container.dispatchEventToSelf(Container.java:2167)
    at java.awt.Component.dispatchMouseWheelToAncestor(Component.java:4886)
    at java.awt.Component.dispatchEventImpl(Component.java:4622)
    at java.awt.Container.dispatchEventImpl(Container.java:2143)
    at java.awt.Component.dispatchEvent(Component.java:4566)
    at com.mathworks.mde.editor.codepad.Codepad$2.mouseWheelMoved(Codepad.java:209)
    at java.awt.Component.processMouseWheelEvent(Component.java:6462)
    at java.awt.Component.processEvent(Component.java:6146)
    at java.awt.Container.processEvent(Container.java:2085)
    at java.awt.Component.dispatchEventImpl(Component.java:4736)
    at java.awt.Container.dispatchEventImpl(Container.java:2143)
    at java.awt.Component.dispatchEvent(Component.java:4566)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4311)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
    at java.awt.Container.dispatchEventImpl(Container.java:2129)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4566)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:680)
    at java.awt.EventQueue.access$000(EventQueue.java:86)
    at java.awt.EventQueue$1.run(EventQueue.java:639)
    at java.awt.EventQueue$1.run(EventQueue.java:637)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:653)
    at java.awt.EventQueue$2.run(EventQueue.java:651)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:650)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:29 6)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:20 1)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)
    Exception in thread "AWT-EventQueue-0" java.lang.NegativeArraySizeException
    at org.netbeans.editor.DrawGraphics$GraphicsDG.flush(DrawGraphics.java:655)
    at org.netbeans.editor.DrawGraphics$GraphicsDG.flush(DrawGraphics.java:522)
    at org.netbeans.editor.DrawGraphics$GraphicsDG.setBuffer(DrawGraphics.java:756)
    at org.netbeans.editor.DrawEngine.draw(DrawEngine.java:1116)
    at org.netbeans.editor.DrawEngineLineView.paint(DrawEngineLineView.java:233)
    at org.netbeans.lib.editor.view.GapBoxViewChildren.paintChildren(GapBoxViewChildre n.java:783)
    at org.netbeans.lib.editor.view.GapBoxView.paint(GapBoxView.java:1463)
    at org.netbeans.lib.editor.view.GapDocumentView.paint(GapDocumentView.java:231)
    at org.netbeans.editor.DrawEngineDocView.paint(DrawEngineDocView.java:314)
    at org.netbeans.editor.view.spi.LockView.paint(LockView.java:363)
    at javax.swing.plaf.basic.BasicTextUI$RootView.paint(BasicTextUI.java:1423)
    at javax.swing.plaf.basic.BasicTextUI.paintSafely(BasicTextUI.java:723)
    at javax.swing.plaf.basic.BasicTextUI.paint(BasicTextUI.java:870)
    at javax.swing.plaf.basic.BasicTextUI.update(BasicTextUI.java:849)
    at javax.swing.JComponent.paintComponent(JComponent.java:752)
    at javax.swing.JComponent.paint(JComponent.java:1029)
    at javax.swing.JComponent.paintToOffscreen(JComponent.java:5146)
    at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(RepaintManager.java :1515)
    at javax.swing.RepaintManager$PaintManager.paint(RepaintManager.java:1446)
    at javax.swing.RepaintManager.paint(RepaintManager.java:1260)
    at javax.swing.JComponent.paintForceDoubleBuffered(JComponent.java:1065)
    at javax.swing.JViewport.blitDoubleBuffered(JViewport.java:1612)
    at javax.swing.JViewport.windowBlitPaint(JViewport.java:1573)
    at javax.swing.JViewport.setViewPosition(JViewport.java:1118)
    at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.vsbStateChanged(BasicScrollPan eUI.java:1029)
    at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.stateChanged(BasicScrollPaneUI .java:1018)
    at javax.swing.DefaultBoundedRangeModel.fireStateChanged(DefaultBoundedRangeModel. java:348)
    at javax.swing.DefaultBoundedRangeModel.setRangeProperties(DefaultBoundedRangeMode l.java:285)
    at javax.swing.DefaultBoundedRangeModel.setValue(DefaultBoundedRangeModel.java:151 )
    at javax.swing.JScrollBar.setValue(JScrollBar.java:446)
    at javax.swing.plaf.basic.BasicScrollPaneUI$Handler.mouseWheelMoved(BasicScrollPan eUI.java:964)
    at javax.swing.plaf.basic.BasicScrollPaneUI$MouseWheelHandler.mouseWheelMoved(Basi cScrollPaneUI.java:525)
    at com.apple.laf.AquaScrollPaneUI$XYMouseWheelHandler.mouseWheelMoved(AquaScrollPa neUI.java:38)
    at java.awt.Component.processMouseWheelEvent(Component.java:6462)
    at java.awt.Component.processEvent(Component.java:6146)
    at java.awt.Container.processEvent(Container.java:2085)
    at java.awt.Component.dispatchEventImpl(Component.java:4736)
    at java.awt.Container.dispatchEventToSelf(Container.java:2167)
    at java.awt.Component.dispatchMouseWheelToAncestor(Component.java:4886)
    at java.awt.Component.dispatchEventImpl(Component.java:4622)
    at java.awt.Container.dispatchEventImpl(Container.java:2143)
    at java.awt.Component.dispatchEvent(Component.java:4566)
    at com.mathworks.mde.editor.codepad.Codepad$2.mouseWheelMoved(Codepad.java:209)
    at java.awt.Component.processMouseWheelEvent(Component.java:6462)
    at java.awt.Component.processEvent(Component.java:6146)
    at java.awt.Container.processEvent(Container.java:2085)
    at java.awt.Component.dispatchEventImpl(Component.java:4736)
    at java.awt.Container.dispatchEventImpl(Container.java:2143)
    at java.awt.Component.dispatchEvent(Component.java:4566)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4621)
    at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4311)
    at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4212)
    at java.awt.Container.dispatchEventImpl(Container.java:2129)
    at java.awt.Window.dispatchEventImpl(Window.java:2478)
    at java.awt.Component.dispatchEvent(Component.java:4566)
    at java.awt.EventQueue.dispatchEventImpl(EventQueue.java:680)
    at java.awt.EventQueue.access$000(EventQueue.java:86)
    at java.awt.EventQueue$1.run(EventQueue.java:639)
    at java.awt.EventQueue$1.run(EventQueue.java:637)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:87)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:98)
    at java.awt.EventQueue$2.run(EventQueue.java:653)
    at java.awt.EventQueue$2.run(EventQueue.java:651)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.AccessControlContext$1.doIntersectionPrivilege(AccessControlConte xt.java:87)
    at java.awt.EventQueue.dispatchEvent(EventQueue.java:650)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:29 6)
    at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:211)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:20 1)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:196)
    at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:188)
    at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)

  • Database connection problem when i try store the values in JTable

    Hi Sir,
    I have a database connection problem when i try to store the data's in a JTable.I think the problem is with in the database connection.I have used 3 vectors here.The database which i have used is
    Access.Where the program is compiling well.But when i run it only the first column heading is printed and error message showing that
    "Invalid Cursor State".I need to solve this problem.pls. do help me.
    I will provide u with the code.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.util.*;
    import java.sql.*;
    public class DataBaseVector extends JPanel
    //Container contentPane=getContentPane();
    JScrollBar jsb = new JScrollBar(JScrollBar.HORIZONTAL);
    JScrollBar jsb1 = new JScrollBar(JScrollBar.VERTICAL);
    Image i1;
    String url="jdbc:odbc:Ananth";
    Vector col=new Vector();
    Vector rows=new Vector();
    Vector rdata=new Vector();
    Connection conn;
    public DataBaseVector()
    //super("JTable With ScrollBars");
    this.setLayout(new BorderLayout());
    UIManager.put("ScrollBar.track",Color.red);
    UIManager.put("ScrollBar.thumb",Color.blue);
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    conn=DriverManager.getConnection(url); // Is there any problem here?
    Statement st=conn.createStatement();
    ResultSet rs=st.executeQuery("Select * from AccountMaster");
    // rs is the result set obtained
    ResultSetMetaData rsmd=rs.getMetaData();
    int cols=rsmd.getColumnCount();
    for(int i=1;i<=cols;i++)
    col.addElement(rsmd.getColumnName(i));
    rdata.addElement(rs.getString(i));
    rows.addElement(rdata);
    }catch(Exception e)
         System.out.println("The Error Message was:"+e.getMessage());
    JTable jt=new JTable(rows,col);
    int v=ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;
    int h=ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;
    JScrollPane jsp=new JScrollPane(jt,v,h);
    this.add(jsp,BorderLayout.CENTER);
    this.add(jsb, BorderLayout.SOUTH);
    this.add(jsb1, BorderLayout.EAST);
    public static void main(String args[])
    JFrame jf=new JFrame();
    JPanel frame=new DataBaseVector();
    jf.getContentPane().add(frame);
    jf.setSize(800,600);
    jf.setVisible(true);
    Thanx,
    m.ananthu

    The problem is ResultSet.next() is not called.
    Try this and modify the table creation as you need.
    ResultSetMetaData rsmd=rs.getMetaData();
    int cols=rsmd.getColumnCount();
         while(rs.next()) {
              for(int i=1;i<=cols;i++)
                        col.addElement(rsmd.getColumnName(i));
                        rdata.addElement(rs.getString(i));
              rows.addElement(rdata);
    Hope this helps

  • Problems using .getDocument()

    It started when I wanted to scroll my TextArea to the bottom when I append the text onto it. But not when you were already scrolled up.
    after searching for a while I found this handy little snip of code
              //Determine whether the scrollbar is currently at the very bottom position.
              JScrollBar vbar = scrollPane.getVerticalScrollBar();
              boolean autoScroll = ((vbar.getValue() + vbar.getVisibleAmount()) == vbar.getMaximum());
              area.append(txt + "\n");
              //now scroll if we were already at the bottom.
              if( autoScroll ) area.setCaretPosition(area.getDocument().getLength() );I understand the first part, with finding the position of the scrollbar. What happens is at "area.getDocument().getLength()"
    I have an error "the method getDocument is underfined for the type TextArea."
    I have been trying to make sense of this, but I'm only part way through my first year of compsci and I just dont really understand .getDocument() and thus am totally lost on whats wrong.
    also note, area is a TextArea andscrollPane was created via
    JScrollPane scrollPane = new JScrollPane(txtBox) incase thats where the problem is.

    no, I was simply unaware. After reading over it, it made no sense really to have a JScrollPane over a TextArea with a scrollbar.
    That being said, I have a new issue since implementing my switch to Swing from AWT.
    How do I set the background of the JTextArea
    when I try
    txtArea.setBackground(Color.white);I end up with an error "Color can't be resolved" this work with my old TextArea, Im assuming JTextArea has some much more powerful and equally confusing way of going about this.

  • Slow scrollbar problem

    Hi guys, I have a problem of slow repaint with scrolling. I have a panel which contains a lot of graphical information. It's dynamically changes its size and may have a width up to 15000 - this is when it gets really slow when I scroll it.
    I was thinking that may be implementing my own ScrollBar will solve the problem, the ScrollBar which will not technically scroll the panel, but by analyzing it's position I will be able to paint only the corresponding part of graph on the screen, and won't have to repaint all of that invisible stuff beyond the screen.
    So I don't know, is it worth trying to do this? And if it is can anybody give me some hints on how to do it? If not, is there any other way to speed it up?
    Thank you, Paulina

    Feri, I'm sorry, I posted the previous message without making some other changes, so at the end the speed was actually improved!
    However, the scrolling worked fine when I applied the changes for the separate panel only. But in my main program I'll have at least 4 of these panels on the screen. I searched the forum and found a code which creates only one scrollbar that will handle the scrolling of all panels simulteniously. In this case, scrolling works fast, but the lines do not get drawn completely, only separate points are drawn. So instead of the line ____________ I see smth like this - - - - -
    Here is the code that I use to make one scrollbar to handle all panels:
    JScrollBar horscrollbar = new JScrollBar(JScrollBar.HORIZONTAL); //scrollbar that will be placed at the bottom of the main window
    JScrollPane[] jsps = new JScrollPane[4]; //creating 4 JScrollPane's , one for each graph
    //scrollbars in those JScrollPane's should not be visible
    int hn = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER;
    int vn = ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER;
    //making graphs the clients of JScrollPane
    jsps[0] = new JScrollPane(graph, vn, hn);     
    jsps[1] = new JScrollPane(graph2, vn, hn);     
    jsps[2] = new JScrollPane(graph3, vn, hn);     
    jsps[3] = new JScrollPane(graph4, vn, hn);
    //horscrollbar is registered to listen to this event
    public void adjustmentValueChanged(AdjustmentEvent e){
         JScrollBar source = (JScrollBar) e.getSource();
         if(source==horscrollbar){
    //transferring the value of horscrollbar to each invisible horizontal scrollbar in jsps[]
         int adj = e.getValue();     
         for (int x=0; x<4; x++)
              jsps[x].getHorizontalScrollBar().setValue(adj);
         }

  • Setting the value of a JScrollBar inside a JScrollPane not working.

    I have a display area (JPanel) inside a JScrollPane. What i want to do is that every time the user closes my application a file is saved with some preferences, like position and size onscreen, and the values of the scrollbars. My problem is that when I try to set the values of the JScrollBars, they seem to be completely ignored.
    I made a small class to illustrate this:
    import java.awt.*;
    import javax.swing.*;
    public class ScrollExample extends JFrame
         private JPanel display;
         private JScrollPane displayScroll;
         public ScrollExample()
              display = new JPanel();
              display.setPreferredSize( new Dimension( 800, 600 ) );
              displayScroll = new JScrollPane( display );
              add( displayScroll );
              setSize( 400, 300 );
              setVisible( true );
              displayScroll.getHorizontalScrollBar().setValue( displayScroll.getHorizontalScrollBar().getMaximum() );
         public static void main( String args[] )
              new ScrollExample();
    }The behaviour of is as intended. However if we switch the two lines to be:
    displayScroll.getHorizontalScrollBar().setValue( displayScroll.getHorizontalScrollBar().getMaximum() );
    setVisible( true );and launch it, the scrollbar appears to have moved only a small amount. This leads me to believe that it has something to do with the main window being visible. In my actual application, this call to setValue is ignored, unlike in this sample one. Even placing it after the setVisible call, it does not do anything.
    When I tried to use:
         Runnable doScroll = new Runnable()
                 public void run()
                      taskDisplayScroll.getHorizontalScrollBar().setValue( 200 );
             SwingUtilities.invokeLater(doScroll);after the setVisible call, as mentioned on http://forum.java.sun.com/thread.jspa?threadID=723424, it rarely (maybe 3 out of 20 times) sets the scrollbar to the indicated value.
    My question is this: What does the setValue() call depend on to run properly, and how do I code it to work in my program?
    If you need any additional information, please ask.
    Note: In the sample class I provided, the scrollbar moves to its proper spot, I could not cause it to not move at all, as is the case in my application that seems to have the same calls.
    Thanks, Serge.
    Edited by: super_serge on Jun 26, 2008 8:23 AM

    Can you please explain to me how b) would be implemented.Read the Swing tutorial on Concurrency for the new approach in JDK1.6, or I still prefer to use SwingUtilities.invokeLater for somthing simple like this.

  • Problem with changing calenders and reminders colors

    Hello,
    Somehow the colors of my two of four calendar just changed them self. I've four calendar:
    Day Off (mark in yellow), Home (mark as purple), Work (mark as blue) and School (mark in green).
    The two calendar of Home and Work swap their color so Home is mark in blue and Work as purple.
    I've tried to change it colors many time, tried difference ones two but it keep turning back. Only this two calendar infected.
    Same problem in reminder. it keep turning orange from purple.
    All attemps in iPhone and in iCloud.com failed.
    Appreciate help.

    even "increment and decrement" buttons of JScrollbar are getting updated with "Button.background" colorWhen you invoke the updateComponentTreeUI() method I believe the code updates the properties of components that use the UIResource interface. The default Colors for components use the ColorUIResource class. See [url http://www.camick.com/java/blog.html?name=uimanager-defaults]UIManager Defaults.
    So to prevent a component from being changed you need to replace the ColorUIResource with a Color class for the buttons in question.
    You might be able to use Darryl's [url http://www.camick.com/java/blog.html?name=swing-utils]Swing Utils class. You can use the class to get all the JButton components used by the scrollbar. Then for each button you could replace the background by using code like:
    button.setBackground( new Color(button.getBackground().getRGB(), true) );

Maybe you are looking for

  • I am trying to use Acrobat XI Pro but it says I have no internet connection when I do. What gives?

    I am at my wits end and don't know what to do.

  • NB305-N440BL getting 0a-0224-0000 file transfer error message using USB Thumbdrive

    Doing total out of the box restore. First off, Toshiba, in their infinite wisdom sends a DVD Rom to you when you order a Recovery Media for a Netbook which has NO DVDROM.  I had to replace the HD after an accident and it is unreadable as a harddrive

  • Fact Table and Dimension Tables

    Hi Experts, I'm creating custom InfoCubes for data coming from non-SAP source systems. I have two InfoCubes. Tha data is coming from like 10 tables. I have 10 DataSources created fo this and the data will be consolidated in Standard DSO before it wil

  • How to disable the whole vi?

    Dear All,          Because the sub-vi uses much memory, when it is running, I want to forbid the user to run other sub-vi.          That is when the user presses the button to run the sub-vi which uses much memory, I want to the user don't press othe

  • Extended Witholding Tax

    Hi, In ECC 6.00 Can I get the following result in FB60: Gross: Rs.1000 Witholding Tax rate: 10% T.Code: FB60 Expenditure  Dr 1000 Vendor Cr 1000 Vendor Dr 100 TDS Payable Cr 100 At present I am getting the result as when I configured GL Account(gross