JComponent in a JScrollPane

Hi All,
I want to add a Customized JComponent in a JScrollPane, but when I do that, I am not getting the scrollbars displayed( i.e as and when needed).
Help me out.

I do it like this:
I create a JPanel, and a JScrollPane on that.
If you do not use layouting, or do an absolute layouting, panel.setLayout(null).
Create your JComponent with setBounds();
ensure that the panel has a setBounds().
The way to pack all this in your code might vary, but you get the idea.

Similar Messages

  • Centering a JComponent inside a JScrollPane

    I've got an instance of a subclass of JComponent (DrawCanvas) inside an instance of JScrollPane (scpEasel). scpEasel is itself in an instance of JInternalFrame (ifEasel) that used a GridLayout.
    When the DrawCanvas object can fit inside the JInternalFrame, it needs to be centered inside the JScrollPane object. If the canvas is wider than the window, it must be centered vertically. If it has a greater height than the window, it must be centered horizontally. When the canvas is, both horizontally and vertically bigger than the window, no centering is needed.
    I made a subclass of ScrollPaneLayout that does just that, but when only one of the scrollbars is visible, it doesn't want to scroll (whether I click on the arrows, or drag the box, etc.).
    How do I keep the scrollbars from jamming?
    Here's the code to the instance of ScrollPaneLayout:
    EaselLayout = new ScrollPaneLayout() {
        public void layoutContainer(Container parent) {
            super.layoutContainer(parent);
            Component Canvas = parent.getComponent(0);
            JScrollBar HSB = getHorizontalScrollBar(),
                       VSB = getVerticalScrollBar();
            int scpWidth = parent.getSize().width,
                scpHeight = parent.getSize().height,
                cX = Canvas.getLocation().x,
                cY = Canvas.getLocation().y,
                cWidth = Canvas.getPreferredSize().width,
                cHeight = Canvas.getPreferredSize().height;
            if (!HSB.isVisible() && !VSB.isVisible()) {
                Canvas.setLocation((scpWidth / 2) - (cWidth / 2), (scpHeight / 2) - (cHeight / 2));
            } else if (!HSB.isVisible()) {
                Canvas.setLocation((scpWidth / 2) - (cWidth / 2), cY);
            } else if (!VSB.isVisible()) {
                Canvas.setLocation(cX, (scpHeight / 2) - (cHeight / 2));
    };Please respond ASAP. Thanx.

    Please, I beg of you...someone help!!
    Here I have created a LayoutManager that is to be used within a JViewport to solve the issue of Centering the JComponent inside a JScrollPane.
    However, it works every time except the first time.
    The code for this LayoutManager (called CenteredLayoutManager) is in the first class.
    The second and third classes provide an application I wrote to test it.
    You type an integer value representing the percentage you want to zoom and press ENTER. The DrawingPanel will zoom the image for you.
    But, as you can see, the first time the image is in the upper left hand of the frame. All the other times, it is centered, but not the first time.
    Could someone explain why it doesn't do it the first time?
    Thank you for your help.
    // standard imports
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.awt.image.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.JTextComponent;
    * A Layout that handles centering if the view is smaller than the
    * JViewPort.
    final class CenteredViewportLayout extends ViewportLayout
       private Rectangle clientArea = new Rectangle(),
       parentArea = new Rectangle();
       private Dimension dimens = new Dimension();
        * This does the centering for the layout.
       public void layoutContainer(Container p)
          JViewport parent = (JViewport)p;
          JComponent client = (JComponent)parent.getView();
          SwingUtilities.calculateInnerArea(parent, parentArea);
          clientArea.setBounds(parentArea);
          clientArea.setSize(client.getPreferredSize());
           * If the client is smaller than the parent scrollPane, then center it
           * within the parent. Otherwise, do the normal thing.
          if (parentArea.contains(clientArea))
             Point point = new Point((clientArea.width/2) - (parentArea.width/2),
                                     (clientArea.height/2) - (parentArea.height/2));
             parent.setViewPosition(point);
             parent.setViewSize(parent.getSize(dimens));
          else
             super.layoutContainer(p);
    class DrawingPanel extends JComponent implements Scrollable
       BufferedImage origImage;
       double        theZoom;    // the zoom factor
       Dimension     unitScroll; // used for correct scrolling...
       public DrawingPanel(BufferedImage img)
          origImage = img;
          unitScroll = new Dimension();
          zoomMe(100);
        * Changes the zoom factor.
        * @param val  the percentage of the zoom.
       public void zoomMe(int val)
          if (val < 1) val = 100;
          theZoom = val / 100.0;
          Dimension d = new Dimension((int)(origImage.getWidth()   * theZoom),
                                      (int)(origImage.getHeight()  * theZoom));
          unitScroll.setSize(d.width / 10, d.height / 10); // scroll 1/10 the way.
          setPreferredSize(d);
          revalidate();
       // EXTENDS JComponent
       // Draws the zoomed image.
       public void paintComponent(Graphics g)
          super.paintComponent(g);
          if (Math.abs(theZoom - 1) > 0.01)
             Graphics2D g2 = (Graphics2D)g;
             g2.scale(theZoom, theZoom);
          g.drawImage(origImage, 0, 0, null);
       // IMPLEMENTS Scrollable
       public Dimension getPreferredScrollableViewportSize()
          return getPreferredSize();
       public int getScrollableUnitIncrement(Rectangle visibleRect,
             int orientation,
             int direction)
          return (orientation == SwingConstants.HORIZONTAL) ? unitScroll.width :
                                                              unitScroll.height;
       public int getScrollableBlockIncrement(Rectangle visibleRect,
                                              int orientation,
                                              int direction)
          return (orientation == SwingConstants.HORIZONTAL) ? visibleRect.width :
                                                              visibleRect.height;
       public boolean getScrollableTracksViewportWidth() { return false; }
       public boolean getScrollableTracksViewportHeight() { return false; }
    * Main class.
    * @author J. Logan
    * @since 1.0 (2003-11-04)
    public class IndexColorTest
       // CONSTANTS
       static final IndexColorModel BASIC_COLOR_MODEL;
       // STATIC METHODS
       public static void main(String [] args)
          JFrame f  = new JFrame("ImageTest");
          f.setSize(400, 400);
          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
          final BufferedImage img = createImage(100, 100);
          final DrawingPanel p = new DrawingPanel(img);
          // This is me using the new layout for the scroll pane's viewport.
          JScrollPane jsp = new JScrollPane();
          JViewport vp = jsp.getViewport();
          vp.setLayout(new CenteredViewportLayout());
          jsp.setViewportView(p);
          f.getContentPane().add(jsp);
          // This is the text field you use to change the zoomed value.
          JTextField jtf  = new JTextField("100", 3);
          jtf.addActionListener(
                new ActionListener() {
                   public void actionPerformed(ActionEvent evt)
                      JTextComponent c = (JTextComponent)evt.getSource();
                      int val = Integer.parseInt(c.getText());
                      p.zoomMe(val);
          f.getContentPane().add(jtf, BorderLayout.NORTH);
          f.setVisible(true);
        * This just creates the image to be used in the zooming.
       private static BufferedImage createImage(int width, int height)
          BufferedImage img = new BufferedImage(width, height,
                                                BufferedImage.TYPE_BYTE_INDEXED,
                                                BASIC_COLOR_MODEL);
          DataBufferByte db = (DataBufferByte)img.getRaster().getDataBuffer();
          byte [] data = db.getData();
          int val = 0;
          for (int i = 0, max = data.length; i < max; ++i)
             val = i % 100;
             if ( val < 25 ) data[i] = 60;
             else if (val < 50)  data[i] = 120;
             else if (val < 75)  data[i] = (byte)180;
             else data[i] = (byte)240;
          return img;
       // This block just creates the ColorModel to use...unimportant for
       // question.
       static
          final byte [] colors = new byte[256];
          final int start = 20, end = 256;
          final double ratio = ((end) - start) / (double)(colors.length - 1);
          double val = start;
          for (int i = 1, max = colors.length; i < max; ++i)
             colors[i] = (byte)(val += ratio);
          BASIC_COLOR_MODEL = new IndexColorModel(8, colors.length,
                                                  colors, colors, colors);
    }Can someone please tell me why it does not work the first time.
    Thanks for your help.

  • JScrollPane Resizing

    Can anyone tell me if there is some method i need to call to have force a JScrollPane to update itself? I have a JComponent inside a JScrollPane and I'm doing some custom graphics within the component. When the graphics are too large i want to scroll.
    From the tutorial, I tried to update the preferred size of the component but that doesn't seem to work. I have to manually resize the window for the scrollbars to resize properly.
    Setting the maximum vertical scroll bar size does work, but my scrollbar policy must always be set to display the scrollbars. In other words, if my scrollbars are already showing, setting the max size works, but if they are not and the graphics resize to large for the first time, the scroll bars are not painted immediately (i need to manually resize).
    Any Suggestions? Thanks in advance.

    needed. Btw, other than the javadocs, do you know of
    a good source for this type of information?This site?
    This is something I had to learn the hard way too; in fact I think a great majority of people learning to build guis in java have this exact same problem. Now that you've seen it and done it you'll know for the future.

  • A small problem with a JScrollPane and child windows

    Hi !
    I have created a customized JComponent inside a JScrollPane and when my application starts I create two JTextField's that I put in the JComponent and so far it all works fine to start with, but when ever the JComponent is redrawn after that the JTextField's are overdrawn or at least are not visible any longer...
    Do I need to repaint the sub components of my own JComponent myself or am I doing something very wrong here ?
    a JScrollPane
    a JComponent with some drawing going on in paint()
    a JTextField
    another JTextField
    Mikael

    Ooppps !
    Forget about it, I forgot to put a super.paint( g) at the top of my paint method, that was the problem.
    Mikael

  • Tooltip doesnt show up correctly

    I have written a small monitoring application tha shows gui components derieved from JComponent inside a JScrollpane. All the display works fine besides the fact, that tooltips from my gui components do not show up correctly when the tooltip window exceeds the boundaries of the JScrollPane. When the complete tooltip is displayed inside the JScrollpane it is displayed correctly. If its is partly outside the JScrollpane the tooltip window remains gray and no text is displayed.
    When I paint my graphics directly to the underlying component without using a JScrollPane the tooltip is displayed correctly disregarding whether its boundaries exceed the underlying components boundaries or not.
    I use JDK 1.5.07 for my development and Eclipse 3.2.
    Any help will be appreciated.
    thanks Christian

    Good attitude! I like that. It may be very productive to see what differences there are between your code that doesn't work and the one that does. If you still cannot find out what is going on, I can have a look to see if it does the same error on mine (its the least I could do by running your code). You could email it to me if you like. I'm a bit wary of spam so send an email to my sourceforge account first. My user name there is avian_freeware and that should be enough for you to get my email address there.
    Good luck!
    Jason.

  • Flipping problems with JTables

    I have a JTable (with scroll bar ) and a JButton inside a Jframe.
    When I push the JButton another JFrame appears with another JTable inside.
    The problem is that when I close the upper JFrame and I try to move the scroll bar of the JTable inside the father JFrame it starts to flip doing an horrible effect for the general lauyout.The solution it could be overwrite the paint method....but actually for my Java knowledges is impossibe. Help !

    Sorry I mean flashing problems (not flipping.)
    The code is:
    JPanel p1=new JPanel();
    Label lab1=new Label(" LABORATORIO ANALISI CLINICHE");
    Label lab2=new Label(" Dr.ssa xxxxxxxxxxxx ");
         Label lab3=new Label(" C/o xxxxxxxxxxxxx ");
         Label lab4=new Label(" Via xxxxxxxxxxx nr 5/7");
         Label lab5=new Label(" 86100 xxxxxxxxxx");
    Label lab6=new Label(" tel. xxxxxxxxxx");
         p1.setLayout(new GridLayout(6,1));
    p1.add(lab1);
    p1.add(lab2);
    p1.add(lab3);
    p1.add(lab4);
    p1.add(lab5);
    p1.add(lab6);
    Report myReport=new Report(tableModels[p.getSelectedIndex()],"Printer Manager",p1);
    Actually Report is a class that prepare a JFrame with a JPanel and inside the JPanel there is a JScrollPane that get the JTable.That's the code for the Report class:
    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;
    public class Report extends Frame implements Printable
    JFrame frame;
    JTable tableView;
    JComponent component_dummy;
    public Report(AbstractTableModel tableModel,String title,JComponent component)
    super(title);
    this.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) { dispose(); } } );
    final String[] headers = {"Description", "open price",
         "latest price", "End Date", "Quantity"};
    final Object[][] data = {
    {"Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
    {"Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
    {"legal pad", "1.00", "2.49", new Date(), new Integer(1)},
    {"tape", "1.00", "1.49", new Date(), new Integer(1)},
    {"stapler", "4.00", "4.49", new Date(), new Integer(1)},
    {"legal pad", "1.00", "2.29", new Date(), new Integer(5)}
    TableModel dataModel = new AbstractTableModel() {
    public int getColumnCount() { return headers.length; }
    public int getRowCount() { return data.length;}
    public Object getValueAt(int row, int col) {
         return data[row][col];}
    public String getColumnName(int column) {
         return headers[column];}
    public Class getColumnClass(int col) {
    return getValueAt(0,col).getClass();}
    public boolean isCellEditable(int row, int col) {
    return (col==1);}
    public void setValueAt(Object aValue, int row, int column) {
    data[row][column] = aValue;
    dataModel=tableModel;
    tableView = new JTable(dataModel);
    // component_dummy= new JComponent();
    component_dummy=component;
    JScrollPane scrollpane = new JScrollPane(tableView);
    scrollpane.setPreferredSize(new Dimension(600,300));
    this.setLayout(new BorderLayout());
    this.add(BorderLayout.NORTH,component);
    this.add(BorderLayout.CENTER,scrollpane);
    JButton printButton= new JButton();
    printButton.setText("Stampa");
    //this.getContentPane().add(BorderLayout.SOUTH,printButton);
    this.add(BorderLayout.SOUTH,printButton);
    // for faster printing turn double buffering off
    RepaintManager.currentManager(
         frame).setDoubleBufferingEnabled(false);
    printButton.addActionListener( new ActionListener(){
    public void actionPerformed(ActionEvent evt) {
    PrinterJob pj=PrinterJob.getPrinterJob();
    pj.setPrintable(Report.this);
    pj.printDialog();
    try{
    pj.print();
    }catch (Exception PrintException) {}
    this.setVisible(true);
    this.pack();
    public int print(Graphics g, PageFormat pageFormat,
    int pageIndex) throws PrinterException
         Graphics2D g2 = (Graphics2D) g;
         g2.setColor(Color.black);
         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+(int)(pageWidth/2-pageWidth*0.43));
         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(0f,0f);
         g2.drawString("Laboratorio analisi Cliniche",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.86));
    g2.drawString("Dr.ssa xxxxxxxxx",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.82));
    g2.drawString("C/o xxxxxxxxxxxxxx",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.78));
    g2.drawString("Via xxxxxxxxxxx",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.74));
    g2.drawString("86100 xxxxxxxxx",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.70));
    g2.drawString("tel. 0874/316147-91720",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.66));
    //      g2.translate(0f,headerHeightOnPage);
         g2.translate((int)(pageWidth/2-pageWidth*0.33),-pageIndex*pageHeightForTable+(pageHeight+fontHeight-fontDesent-pageHeight*0.56));
         //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(0,pageIndex*pageHeightForTable);
         g2.translate(0, -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)
    do you think that there are problems because the print method ? or mayby because I clipped the graphics area ?

  • Jtable flashing

    I have a print JTable within a Jscrolpane.In the JFrame
    that contains the JTable I have a print method connected to a JButton.After I pushed the JButton and after the printer has done its jobs when I move the scroll bar of the JScrollPane, the JTable starts to flash.I don't know how overwrite the paint method for avoiding this bad effect.Here some code:
    //package print.utilities;
    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;
    public class Report extends Frame implements Printable
    JFrame frame;
    JTable tableView;
    JComponent component_dummy;
    public Report(AbstractTableModel tableModel,String title,JComponent component)
    super(title);
    this.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) { dispose(); } } );
    final String[] headers = {"Description", "open price",
         "latest price", "End Date", "Quantity"};
    final Object[][] data = {
    {"Box of Biros", "1.00", "4.99", new Date(), new Integer(2)},
    {"Blue Biro", "0.10", "0.14", new Date(), new Integer(1)},
    {"legal pad", "1.00", "2.49", new Date(), new Integer(1)},
    {"tape", "1.00", "1.49", new Date(), new Integer(1)},
    {"stapler", "4.00", "4.49", new Date(), new Integer(1)},
    {"legal pad", "1.00", "2.29", new Date(), new Integer(5)}
    TableModel dataModel = new AbstractTableModel() {
    public int getColumnCount() { return headers.length; }
    public int getRowCount() { return data.length;}
    public Object getValueAt(int row, int col) {
         return data[row][col];}
    public String getColumnName(int column) {
         return headers[column];}
    public Class getColumnClass(int col) {
    return getValueAt(0,col).getClass();}
    public boolean isCellEditable(int row, int col) {
    return (col==1);}
    public void setValueAt(Object aValue, int row, int column) {
    data[row][column] = aValue;
    dataModel=tableModel;
    tableView = new JTable(dataModel);
    // component_dummy= new JComponent();
    component_dummy=component;
    JScrollPane scrollpane = new JScrollPane(tableView);
    scrollpane.setPreferredSize(new Dimension(600,300));
    this.setLayout(new BorderLayout());
    this.add(BorderLayout.NORTH,component);
    this.add(BorderLayout.CENTER,scrollpane);
    JButton printButton= new JButton();
    printButton.setText("Stampa");
    //this.getContentPane().add(BorderLayout.SOUTH,printButton);
    this.add(BorderLayout.SOUTH,printButton);
    // for faster printing turn double buffering off
    RepaintManager.currentManager(
         frame).setDoubleBufferingEnabled(false);
    printButton.addActionListener( new ActionListener(){
    public void actionPerformed(ActionEvent evt) {
    PrinterJob pj=PrinterJob.getPrinterJob();
    pj.setPrintable(Report.this);
    pj.printDialog();
    try{
    pj.print();
    }catch (Exception PrintException) {}
    this.setVisible(true);
    this.pack();
    public int print(Graphics g, PageFormat pageFormat,
    int pageIndex) throws PrinterException
         Graphics2D g2 = (Graphics2D) g;
         g2.setColor(Color.black);
         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+(int)(pageWidth/2-pageWidth*0.43));
         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(0f,0f);
         g2.drawString("Laboratorio analisi Cliniche",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.86));
    g2.drawString("Dr.ssa Evelina Gina Colella",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.82));
    g2.drawString("C/o Centro Medico Radiologico Potito",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.78));
    g2.drawString("Via Conte Verde nr 5/7",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.74));
    g2.drawString("86100 Campobasso",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.70));
    g2.drawString("tel. 0874/316147-91720",(int)(pageWidth/2-pageWidth*0.33),
    (int)(pageHeight+fontHeight-fontDesent-pageHeight*0.66));
    //      g2.translate(0f,headerHeightOnPage);
         g2.translate((int)(pageWidth/2-pageWidth*0.33),-pageIndex*pageHeightForTable+(pageHeight+fontHeight-fontDesent-pageHeight*0.56));
         //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(0,pageIndex*pageHeightForTable);
         g2.translate(0, -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)

    // for faster printing turn double buffering off
    RepaintManager.currentManager(
    frame).setDoubleBufferingEnabled(false);
    I faced the same problem. Remove above line and everything will work fine. Apparently if you disable double buffering the JTable starts to flicker.

  • What makes the scrolled image back to the same place???

    Hi, guys:
    I have asked this question but I am gonna ask again since I am going crazy literally. I put a JComponent to the JScrollPane to show a BufferedImage. But whenever I scroll, the image will move nicely then as soon as I release the mouse button, the image will repaint itself to the original place. So the final result is no scrolling. The code is here:
         canvas = new ImageDisplay(this, mainFrame);
         scroll = new JScrollPane();
    scroll.setViewportView(canvas);
    The ImageDisplay is a class extends JComponent and has a paintComponent() method. Please help me out!!! Thanks a lot!!!
    David

    Here is a sample of what I am trying to do
    JScrollPane          scrollPane = new JScrollPane();
    DragTree          tree;
    public ScrollablePane(TreeModel treeModel)
    super(new BorderLayout());
    scrollPane.setOpaque(true);
    add(BorderLayout.CENTER, scrollPane);
    scrollPane.getViewport().setBackground(Color.white);
    tree = new DragTree(treeModel);
    tree.addMouseListener(this);
    tree.addKeyListener(this);
    tree.setLargeModel(true);
    tree.addTreeSelectionListener(SelectionHolder.getInstance());
    scrollPane.getViewport().add(BorderLayout.CENTER, tree);
    tree.setBackground(Color.white);
    tree.setFont(new Font("Dialog", Font.PLAIN, 12));
    catch(Exception e)
    //Class DragTree
    class DragTree extends JTree implements DragSourceListener,                         DragGestureListener
    private DragSource dragSource = null;
    public DragTree(TreeModel model)
    super(model);
    dragSource = DragSource.getDefaultDragSource();
    dragSource.createDefaultDragGestureRecognizer(this,
              DnDConstants.ACTION_MOVE, this);
    public void dragDropEnd(DragSourceDropEvent e) {}
    public void dragEnter(DragSourceDragEvent e) {}
    public void dragExit(DragSourceEvent e) {}
    public void dragOver(DragSourceDragEvent e) {}
    public void dropActionChanged(DragSourceDragEvent e) {}
    public void dragGestureRecognized(DragGestureEvent e)
    //Do something in here
    }

  • Association between Jcheckboxes and lines of JTable

    Hello everybody,
    I would like to add a JChekBox to each line of my JTable knowing that the number of lines is given only at the time of the execution. The problem is that the contructor of JscrollPane can take only one JComponent in parameters:
    JScrollPane scrollpane=new JScrollPane(MyJTable);
    How can I make association line-JChekBox dynamically.
    I m waiting for your answers impatiently.
    Thank you for being attentive

    I don't understand your question. You where given a link to the JTable tutorial, that showed you how to add check boxes to the table.
    This is done by adding Boolean values to the TableModel. So once you know the number of rows in the table you create a simple loop and do:
    table.setValueAt(row, new Boolean(true) );

  • Trying to scroll a JComponent with JScrollPane but can't do it. :(

    Hi, what im trying to do seems to be simple but I gave up after trying the whole day and I beg you guys help.
    I created a JComponent that is my map ( the map consists only in squared cells ). but the map might be too big for the screen, so I want to be able to scroll it. If the map is smaller than the screen,
    everything works perfect, i just add the map to the frame container and it shows perfect. But if I add the map to the ScrollPane and them add the ScrollPane to the container, it doesnt work.
    below is the code for both classes Map and the MainWindow. Thanks in advance
    package main;
    import java.awt.Color;
    import java.awt.event.WindowEvent;
    import java.awt.event.WindowStateListener;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JViewport;
    public class MainWindow implements WindowStateListener {
         private JFrame frame;
         private static MainWindow instance = null;
         private MenuBar menu;
         public Map map = new Map();
         public JScrollPane Scroller =
              new JScrollPane( map,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
         public JViewport viewport = new JViewport();
         private MainWindow(int width, int height) {
              frame = new JFrame("Editor de Cen�rios v1.0");
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setSize(width,height);
              frame.setVisible(true);
              menu = MenuBar.createMenuBar();
              JFrame.setDefaultLookAndFeelDecorated(false);
              frame.setJMenuBar(menu.create());
              frame.setBackground(Color.WHITE);
              frame.getContentPane().setBackground(Color.WHITE);
                                    // HERE IS THE PROBLEM, THIS DOESNT WORKS   <---------------------------------------------------------------------------------------
              frame.getContentPane().add(Scroller);
              frame.addWindowStateListener(this);
    public static MainWindow createMainWindow(int width, int height)
         if(instance == null)
              instance = new MainWindow(width,height);
              return instance;               
         else
              return instance;
    public static MainWindow returnMainWindow()
         return instance;
    public static void main(String[] args) {
         MainWindow mWindow = createMainWindow(800,600);
    public JFrame getFrame() {
         return frame;
    public Map getMap(){
         return map;
    @Override
    public void windowStateChanged(WindowEvent arg0) {
         map.repaint();
    package main;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import javax.swing.JComponent;
    import javax.swing.Scrollable;
    public class Map extends JComponent  implements Scrollable{
         private Cell [] mapCells;
         private String mapPixels;
         private String mapAltura;
         private String mapLargura;
         public void createMap(String pixels , String altura, String largura)
              mapPixels = pixels;
              mapAltura = altura;
              mapLargura = largura;
              int cells = Integer.parseInt(altura) * Integer.parseInt(largura);
              mapCells = new Cell[cells];
              //MainWindow.returnMainWindow().getFrame().getContentPane().add(this);
              Graphics2D grafico = (Graphics2D)getGraphics();
              for(int i=0, horiz = 0 , vert = 0; i < mapCells.length; i++)
                   mapCells[i] = new Cell( horiz, vert,Integer.parseInt(mapPixels));
                   MainWindow.returnMainWindow().getFrame().getContentPane().add(mapCells);
                   grafico.draw(mapCells[i].r);
                   horiz = horiz + Integer.parseInt(mapPixels);
                   if(horiz == Integer.parseInt(mapLargura)*Integer.parseInt(mapPixels))
                        horiz = 0;
                        vert = vert + Integer.parseInt(mapPixels);
              repaint();
         @Override
         protected void paintComponent(Graphics g) {
              super.paintComponent(g);
              System.out.println("entrou");
              Graphics2D g2d = (Graphics2D)g;
              if(mapCells !=null)
                   for(int i=0, horiz = 0 , vert = 0; i < mapCells.length; i++)
                        g2d.draw(mapCells[i].r);
                        horiz = horiz + Integer.parseInt(mapPixels);
                        if(horiz == Integer.parseInt(mapLargura)*Integer.parseInt(mapPixels))
                             horiz = 0;
                             vert = vert + Integer.parseInt(mapPixels);
         @Override
         public Dimension getPreferredScrollableViewportSize() {
              return super.getPreferredSize();
         @Override
         public int getScrollableBlockIncrement(Rectangle visibleRect,
                   int orientation, int direction) {
              // TODO Auto-generated method stub
              return 5;
         @Override
         public boolean getScrollableTracksViewportHeight() {
              // TODO Auto-generated method stub
              return false;
         @Override
         public boolean getScrollableTracksViewportWidth() {
              // TODO Auto-generated method stub
              return false;
         @Override
         public int getScrollableUnitIncrement(Rectangle visibleRect,
                   int orientation, int direction) {
              // TODO Auto-generated method stub
              return 5;

    Im so sorry Darryl here are the other 3 classes
    package main;
    import java.awt.FlowLayout;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.BoxLayout;
    import javax.swing.JButton;
    import javax.swing.JFileChooser;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JTextField;
    import javax.swing.filechooser.FileNameExtensionFilter;
    public class MenuActions {
         public void newMap(){
              final JTextField pixels = new JTextField(10);
              final JTextField hCells = new JTextField(10);
              final JTextField wCells = new JTextField(10);
              JButton btnOk = new JButton("OK");
              final JFrame frame = new JFrame("Escolher dimens�es do mapa");
              frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(),BoxLayout.Y_AXIS));
              btnOk.addActionListener(new ActionListener(){
            public void actionPerformed(ActionEvent e){
              String txtPixels = pixels.getText();
              String hTxtCells = hCells.getText();
              String wTxtCells = wCells.getText();
              frame.dispose();
              MainWindow.returnMainWindow().map.createMap(txtPixels,hTxtCells,wTxtCells);         
              frame.getContentPane().add(new JLabel("N�mero de pixels em cada c�lula:"));
              frame.getContentPane().add(pixels);
              frame.getContentPane().add(new JLabel("Altura do mapa (em c�lulas):"));
              frame.getContentPane().add(hCells);
              frame.getContentPane().add(new JLabel("Largura do mapa (em c�lulas):"));
              frame.getContentPane().add(wCells);
              frame.getContentPane().add(btnOk);
              frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
              frame.setSize(300, 165);
              frame.setResizable(false);
             frame.setVisible(true);
         public Map openMap (){
              //Abre somente arquivos XML
              JFileChooser fc = new JFileChooser();
              FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml" );
              fc.addChoosableFileFilter(filter);
              fc.showOpenDialog(MainWindow.returnMainWindow().getFrame());
              //TO DO: manipular o mapa aberto
              return new Map();          
         public void save(){
         public void saveAs(){
              //Abre somente arquivos XML
              JFileChooser fc = new JFileChooser();
              FileNameExtensionFilter filter = new FileNameExtensionFilter("XML file", "xml" );
              fc.addChoosableFileFilter(filter);
              fc.showSaveDialog(MainWindow.returnMainWindow().getFrame());
              //TO DO: Salvar o mapa aberto
         public void exit(){
              System.exit(0);          
         public void copy(){
         public void paste(){
    package main;
    import java.awt.Color;
    import java.awt.Font;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.KeyEvent;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    import javax.swing.KeyStroke;
    public class MenuBar implements ActionListener{
         private JMenuBar menuBar;
         private final Color color = new Color(250,255,245);
         private String []menuNames = {"Arquivo","Editar"};
         private JMenu []menus = new JMenu[menuNames.length];
         private String []arquivoMenuItemNames = {"Novo","Abrir", "Salvar","Salvar Como...","Sair" };
         private KeyStroke []arquivoMenuItemHotkeys = {KeyStroke.getKeyStroke(KeyEvent.VK_N,ActionEvent.CTRL_MASK),
                                                                  KeyStroke.getKeyStroke(KeyEvent.VK_A,ActionEvent.CTRL_MASK),
                                                                  KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.CTRL_MASK),
                                                                  KeyStroke.getKeyStroke(KeyEvent.VK_S,ActionEvent.SHIFT_MASK),
                                                                  KeyStroke.getKeyStroke(KeyEvent.VK_F4,ActionEvent.ALT_MASK)};
         private JMenuItem []arquivoMenuItens = new JMenuItem[arquivoMenuItemNames.length];
         private String []editarMenuItemNames = {"Copiar","Colar"};
         private KeyStroke []editarMenuItemHotKeys = {KeyStroke.getKeyStroke(KeyEvent.VK_C,ActionEvent.CTRL_MASK),
                                                                 KeyStroke.getKeyStroke(KeyEvent.VK_V,ActionEvent.CTRL_MASK)};
         private JMenuItem[]editarMenuItens = new JMenuItem[editarMenuItemNames.length];
         private static MenuBar instance = null;
         public JMenuItem lastAction;
         private MenuBar()
         public static MenuBar createMenuBar()
              if(instance == null)
                   instance = new MenuBar();
                   return instance;                    
              else
                   return instance;
         public JMenuBar create()
              //cria a barra de menu
              menuBar = new JMenuBar();
              //adiciona items a barra de menu
              for(int i=0; i < menuNames.length ; i++)
                   menus[i] = new JMenu(menuNames);
                   menuBar.add(menus[i]);
              //seta a hotkey da barra como F10
              menus[0].setMnemonic(KeyEvent.VK_F10);
              //adiciona items ao menu arquivo
              for(int i=0; i < arquivoMenuItemNames.length ; i++)
                   arquivoMenuItens[i] = new JMenuItem(arquivoMenuItemNames[i]);
                   arquivoMenuItens[i].setAccelerator(arquivoMenuItemHotkeys[i]);
                   menus[0].add(arquivoMenuItens[i]);
                   arquivoMenuItens[i].setBackground(color);
                   arquivoMenuItens[i].addActionListener(this);
              //adiciona items ao menu editar
              for(int i=0; i < editarMenuItemNames.length ; i++)
                   editarMenuItens[i] = new JMenuItem(editarMenuItemNames[i]);
                   editarMenuItens[i].setAccelerator(editarMenuItemHotKeys[i]);
                   menus[1].add(editarMenuItens[i]);
                   editarMenuItens[i].setBackground(color);
                   editarMenuItens[i].addActionListener(this);
              menuBar.setBackground(color);
              return menuBar;                    
         @Override
         public void actionPerformed(ActionEvent e) {
              lastAction = (JMenuItem) e.getSource();
              MenuActions action = new MenuActions();
              if(lastAction.getText().equals("Novo"))
                   action.newMap();
              else if(lastAction.getText().equals("Abrir"))
                   action.openMap();
              else if(lastAction.getText().equals("Salvar"))
                   action.save();               
              else if(lastAction.getText().equals("Salvar Como..."))
                   action.saveAs();               
              else if(lastAction.getText().equals("Sair"))
                   action.exit();               
              else if(lastAction.getText().equals("Copiar"))
                   action.copy();               
              else if(lastAction.getText().equals("Colar"))
                   action.paste();               
    package main;
    import java.awt.geom.Rectangle2D;
    import javax.swing.JComponent;
    public class Cell extends JComponent{
         public float presSub = 0;
         public double errPressInfer = 0.02;
         public double errPressSup = 0.02;
         public float profundidade = 1;
         public Rectangle2D r ;
         public Cell(double x, double y, double pixel)
              r = new Rectangle2D.Double(x,y,pixel,pixel);          
    Edited by: xnunes on May 3, 2008 6:26 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need help fast :a question about jcomponent and jscrollpane

    I draw a graphic on a jcomponent like this :
    class drawrecttree extends JComponent {
    public void paint( Graphics g) {
    and I add this to jscrollpane:
    drawrecttree www=new drawrecttree();
    www.k_choose=k_valuenow;
    www.node=currentNode;
    www.setAutoscrolls(true);
    jScrollPane2.setViewportView(www);
    but I hope the jscrollpane can autoscroll,that means jscrollpane's size is 400*400,if the Jcomponent's size is 200*300, just add jcomponent;if jcomponent is bigger than 400*400,the jscrollpane can autoscroll,how can I do that?
    Edited by: hcgerard on Jan 8, 2008 2:18 AM
    Edited by: hcgerard on Jan 8, 2008 2:22 AM
    Edited by: hcgerard on Jan 8, 2008 2:52 AM

    Below is a small non-compilable unit (you need to add a few things of course) - but at any rate, here is some code that, if you get it working, you will see that the scrollbars do the right thing.
    public class TestScrollPane  extends JFrame {
      private Container     container;
      private JPanel        panel;
      private JLabel        label;
      private JScrollPane   scroller;
      public TestScrollPane() {
        container = getContentPane();
        panel     = new JPanel();
        panel.setLayout(new BorderLayout());
        /* Get you images here ...                */
        /* I will call them imageOne and imageTwo */
        label     = new JLabel(new ImageIcon(imageOne));
        panel.add(label);
        scroller  = new JScrollPane(panel);
        scroller.setPreferredSize(new Dimension(100, 100));
        container.add(scroller);
        pack();
        /* Rest of JFrame stuff */
      public static void main(String[] argv)  throws InterruptedException {
        TestScrollPane tsp = new TestScrollPane();
        Thread.sleep(5000);
        tsp.label.setIcon(new ImageIcon(tsp.imageTwo));
        Thread.sleep(5000);
        tsp.label.setIcon(new ImageIcon(tsp.imageOne));
    }

  • Zooming an image and scrolling it using a JScrollPane

    Hi all, I know this is one of the most common problems in this forum but i cant get any of the replys to work in my code.
    The problem:
    I create an image with varying pixel colors depending on the value obtained from an AbstractTableModel and display it to the screen.
    I then wish to be able to zoom in on the image and make it scrollable as required.
    At the minute the scrolling method is working but only when i resize or un-focus and re-focus the JInternalFrame. Ive tried calling revalidate (and various other options) on the JScrollPane within the paintComponents(Graphics g) method but all to no avail.
    Has anyone out there any ideas cause this is melting my head!
    Heres the code im using (instance is called and added to a JDesktopPane):
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.geom.AffineTransform;
    import uk.ac.qub.mvda.gui.MVDATableModel;
    import uk.ac.qub.mvda.utils.MVDAConstants;
    public class HCLSpectrumPlot extends JInternalFrame implements MVDAConstants
      AbstractAction zoomInAction = new ZoomInAction();
      AbstractAction zoomOutAction = new ZoomOutAction();
      double zoomFactorX = 1.0;
      double zoomFactorY = 1.0;
      private AffineTransform theTransform;
      private ImagePanel imageViewerPanel;
      private JScrollPane imageViewerScroller;
      public HCLSpectrumPlot(String title, MVDATableModel model)
        super(title, true, true, true, true);
        int imageHeight_numOfRows = model.getRowCount();
        int imageWidth_numOfCols = model.getColumnCount();
        int numberOfColourBands = 3;
        double maxValueInTable = 0;
        double[][] ValueAtTablePosition =
            new double[imageHeight_numOfRows][imageWidth_numOfCols];
        for(int i=0; i<imageHeight_numOfRows; i++)
          for(int j=0; j<imageWidth_numOfCols; j++)
         ValueAtTablePosition[i][j] = ((Double)model.getValueAt
                 (i,j)).doubleValue();
        for(int i=0; i<imageHeight_numOfRows; i++)
          for(int j=0; j<imageWidth_numOfCols; j++)
         if ( ValueAtTablePosition[i][j] > maxValueInTable)
           maxValueInTable = ValueAtTablePosition[i][j];
        BufferedImage newImage = new BufferedImage(imageWidth_numOfCols,
              imageHeight_numOfRows, BufferedImage.TYPE_3BYTE_BGR);
        WritableRaster newWritableImage = newImage.getRaster();
        int colourB;
        double pixelValue, cellValue, newPixelValue;
        for (int x = 0; x < imageHeight_numOfRows; x++)
          for (int y = 0; y < imageWidth_numOfCols; y++)
         colourB = 0;
         cellValue = ValueAtTablePosition[x][y];
         pixelValue = (1 - (cellValue / maxValueInTable)) * 767;
         pixelValue = pixelValue - 256;
         while (colourB < numberOfColourBands)
           if ( pixelValue < 0 )
             newPixelValue = 256 + pixelValue;
             newWritableImage.setSample(x, y, colourB, newPixelValue);
             colourB++;
                while ( colourB < numberOfColourBands )
               newWritableImage.setSample(x, y, colourB, 0);
               colourB++;
         else
           newWritableImage.setSample(x, y, colourB, 255);
         colourB++;
         pixelValue = pixelValue - 256;
          }//while
         }//for-y
        }//for-x
        imageViewerPanel = new ImagePanel(this, newImage);
        imageViewerScroller =     new JScrollPane(imageViewerPanel,
                            JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
                   JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
        this.getContentPane().setLayout(new BorderLayout());
        this.getContentPane().add(imageViewerScroller, BorderLayout.CENTER);
        JToolBar editTools = new JToolBar();
        editTools.setOrientation(JToolBar.VERTICAL);
        editTools.add(zoomInAction);
        editTools.add(zoomOutAction);
        this.getContentPane().add(editTools, BorderLayout.WEST);
        this.setVisible(true);
      class ImagePanel extends JPanel
        private int iWidth, iHeight;
        private int i=0;
        private BufferedImage bufferedImageToDisplay;
        private JInternalFrame parentFrame;
        public ImagePanel(JInternalFrame parent, BufferedImage image)
          super();
          parentFrame = parent;
          bufferedImageToDisplay = image;
          iWidth = bufferedImageToDisplay.getWidth();
          iHeight = bufferedImageToDisplay.getHeight();
          theTransform = new AffineTransform();
          //theTransform.setToScale(parent.getContentPane().getWidth(),
                                    parent.getContentPane().getHeight());
          this.setPreferredSize(new Dimension(iWidth, iHeight));
        }//Constructor
        public void paintComponent(Graphics g)
          super.paintComponent(g);
          ((Graphics2D)g).drawRenderedImage(bufferedImageToDisplay,
                                             theTransform);
          this.setPreferredSize(new Dimension((int)(iWidth*zoomFactorX),
                                          (int)(iHeight*zoomFactorY)));
        }//paintComponent
      }// end class ImagePanel
       * Class to handle a zoom in event
       * @author Ross McCaughrain
       * @version 1.0
      class ZoomInAction extends AbstractAction
       * Default Constructor.
      public ZoomInAction()
        super(null, new ImageIcon(HCLSpectrumPlot.class.getResource("../"+
                  MVDAConstants.PATH_TO_IMAGES + "ZoomIn24.gif")));
        this.putValue(Action.SHORT_DESCRIPTION,"Zooms In on the Image");
        this.setEnabled(true);
      public void actionPerformed(ActionEvent e)
        zoomFactorX += 0.5;
        zoomFactorY += 0.5;
        theTransform = AffineTransform.getScaleInstance(zoomFactorX,
                                                    zoomFactorY);
        repaint();
      // ZoomOut to be implemented
    }// end class HCLSpectrumPlotAll/any help greatly appreciated! thanks for your time.
    RossMcC

    Small mistake, the revalidate must be called on the panel not on the jsp.
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class UsaZ extends JFrame 
         IPanel      panel = new IPanel();
         JScrollPane jsp   = new JScrollPane(panel);
    public UsaZ() 
         addWindowListener(new WindowAdapter()
         addWindowListener(new WindowAdapter()
         {     public void windowClosing(WindowEvent ev)
              {     dispose();
                   System.exit(0);
         setBackground(Color.lightGray);
         getContentPane().add("Center",jsp);
         setBounds(1,1,400,320);
         setVisible(true);
    public class IPanel extends JComponent
         Image  map;
         double zoom = 1;
         double iw;
         double ih;
    public IPanel()
         map = getToolkit().createImage("us.gif");
         MediaTracker tracker = new MediaTracker(this);
         tracker.addImage(map,0);
         try {tracker.waitForID(0);}
         catch (InterruptedException e){}
         iw = map.getWidth(this);
         ih = map.getHeight(this);
         zoom(0);     
         addMouseListener(new MouseAdapter()     
         {     public void mouseReleased(MouseEvent m)
                   zoom(0.04);               
                   repaint();      
                   revalidate();
    public void zoom(double z)
         zoom = zoom + z;
         setPreferredSize(new Dimension((int)(iw*zoom)+2,(int)(ih*zoom)+2));
    public void paintComponent(Graphics g)
         super.paintComponent(g);
         Graphics2D g2 = (Graphics2D)g;
         g2.scale(zoom,zoom);
         g2.drawImage(map,1,1,null);
         g.drawRect(0,0,map.getWidth(this)+1,map.getHeight(this)+1);
    public static void main (String[] args) 
          new UsaZ();
    [/cdoe]
    Noah                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to collect JScrollPanes into a Container variable? (urgent...)

    Please help me in following problem:
    I can collect succesfully one JScrollPane into a Container variable allComponents and then show this Container in application window. However, I would like to collect several JScrollPanes into this same Container variable but it does not work. Should I use some kind of add command?
    I tried something like
    allComponents.add(jspane);
    but I got error code "variable allComponents might not have been initialized" allthough I have tried my best to initialize it.
    Thanks for your kind help!
    Snippets from my program:
    class SwingApplication implements ActionListener
    public Container createComponents()
    Container allComponents;
    jspane = new JScrollPane(panel);
    jspane2 = new JScrollPane(cards);
    allComponents = jspane; // THIS WORKS BUT I WOULD LIKE TO COLLECT BOTH jspane AND jspane2 WITH ADD COMMAND
    return allComponents;
    class DragImage
    { public static void main(String[] args)
    JFrame frame = new JFrame("SwingApplication");
    SwingApplication app = new SwingApplication();
    Container contents = app.createComponents();
    frame.getContentPane().add(contents, BorderLayout.CENTER);
    Message was edited by:
    wonderful123

    THanks for your interest!!
    Perhaps I give the whole source code
    The problem lies in the following place:
    allComponents = jspane;
    return allComponents;
    I would like to use some kind of command
    allComponents.add(jspane);
    but it does not seem to work. I get the error "variable allComponents might not be initialized".
    The program should print images in two rows. With my current knowledge i can only print one row of images.
    Thanks!
    import java.awt.*;
        import java.awt.event.*;
        import java.awt.datatransfer.*;
        import javax.swing.*;
    class SwingApplication implements ActionListener
                                            // extends JScrollPane
       private JScrollPane jspane;
       private JScrollPane jspane_n;
       private JPanel panel;
       private JLabel label;
       private Icon icon;
       private JPanel panel2;
       private JLabel label2;
       private Icon icon2;
       private JPanel panel_n;
       private JLabel label_n;
       private Icon icon_n;
       private JTextField testText;
       private int k;
        private static String labelPrefix = "Testing: ";
        private int numClicks = 0;
        final JLabel label_testing = new JLabel(labelPrefix + "nothing");
    JPanel cards; //a panel that uses CardLayout
        final String BUTTONPANEL = "JPanel with JButtons";
        final String TEXTPANEL = "JPanel with JTextField";
       public Container createComponents()
    Container allComponents;
         icon = new ImageIcon("kirjain_a.gif");
         label = new JLabel();
         label.setIcon(icon);
         icon2 = new ImageIcon("kirjain_b.gif");
         label2 = new JLabel();
         label2.setIcon(icon2);
         icon_n = new ImageIcon("numero_1.gif");
         label_n = new JLabel();
         label_n.setIcon(icon_n);
    label.setTransferHandler(new ImageSelection());              
    label2.setTransferHandler(new ImageSelection());
    label_n.setTransferHandler(new ImageSelection());
            MouseListener mouseListener = new MouseAdapter() {
              public void mousePressed(MouseEvent e) {
    JComponent sourceEvent = (JComponent)e.getSource();
    // Object sourceEvent = whatHappened.getSource();
    if (sourceEvent == label)
        { numClicks++;
            label_testing.setText(labelPrefix + numClicks);
    if (sourceEvent == label2)
    numClicks--;
            label_testing.setText(labelPrefix + numClicks);
                JComponent comp = (JComponent)e.getSource();
                TransferHandler handler = comp.getTransferHandler();
                handler.exportAsDrag(comp, e, TransferHandler.COPY);
           label.addMouseListener(mouseListener);
           label2.addMouseListener(mouseListener);  
           label_n.addMouseListener(mouseListener);  
         panel = new JPanel();
    // panel.setLayout(new GridLayout(1,3));
         panel.add(label);
         panel.add(label2);
         panel_n = new JPanel();
         panel_n.add(label_n);
    //Create the panel that contains the "cards".
            cards = new JPanel(new CardLayout());
            cards.add(panel_n, BUTTONPANEL);
            cards.add(panel_n, TEXTPANEL);
         panel.add(label_testing);
          jspane = new JScrollPane(panel);
          jspane_n = new JScrollPane(cards);
      //   jspane.setLayout(new GridLayout(3,2));      
      //   jspane.getViewport().add(panel);
      //   jspane_n.getViewport().add(cards);
      //    allComponents.add(panel, BorderLayout.PAGE_START);
      //    allComponents.add(cards, BorderLayout.CENTER);
      //     allComponents.add(jspane);
      //     allComponents.add(jspane_n);
         allComponents = jspane;
         return allComponents;
                                           //     label.addActionListener(this);
                                           //     k=0;
    public void actionPerformed(ActionEvent whatHappened)
      { Object sourceEvent = whatHappened.getSource();
        if (sourceEvent == label)
        { numClicks++;
            label_testing.setText(labelPrefix + numClicks);
    //    repaint();
    } // end class OwnPanel
    class CloserClass extends WindowAdapter
    { public void windowClosing(WindowEvent e)
       { System.exit(0);
    class DragImage
    { public static void main(String[] args)
           JFrame frame = new JFrame("SwingApplication");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            SwingApplication app = new SwingApplication();
            Container contents = app.createComponents();
            frame.getContentPane().add(contents, BorderLayout.CENTER);
            //Display the window.
    //    addWindowListener(new CloserClass());
            frame.pack();
            frame.setVisible(true);
        } // end class DragImage

  • How to make JScrollPane scrollable only in the y- direction

    Hai,
    can some one help me fix this one. I need to create a JScrollPane which is scrollable only in the y direction.

    Hi everyone,
    Create the JScrollPane in this way
    JScrollPane ScrollPane1 = new ScrollPane(JComponent,
    VERTICAL_SCROLLBAR_ALWAYS,
    HORIZONTAL_SCROLLBAR_NEVER);Richard West

  • Issues with JScrollPane

    Hi everybody
    I created a class to display help dialogs dynamically created, because I'll need lots of help windows.
    I decided to created it based on 2-dimensional arrays of data. Up till here, everything is fine.
    But I'm facing some problems with the GUI, basically my scroll pane. my problems:
    - first, the vertical scrollbar was not being displayed, which I fixed setting the panel size with the viewport width, but that leaves me the problem of the height... it will change because of the width, and I don't know what value to use...
    - changing between pages, my scroll bar goes to different values, and setting its value to 0 doesn't help...
    - if there the window is made very small, sometimes some of the components placed inside the helpPanel overlaps each other... is there a way to fully avoid that?
    my class code:
    import java.awt.Component;
    import java.awt.Dialog;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Image;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ComponentEvent;
    import java.awt.event.ComponentListener;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.text.Document;
    public class HelpWindow extends JDialog implements ActionListener {
        private Object[][] helpData;
        private JPanel helpPanel;
        private JButton /*closeButton,*/ nextButton, prevButton;
        JScrollPane helpScrollPane;
        private int currentHelpDataIndex;
        public HelpWindow(Dialog owner, Object[][] helpData) {
            super(owner,"Help",true);
            if (helpData.length < 1) {
                throw new IllegalArgumentException("the help data cannot be empty");
            for (Object[] oa : helpData) {
                if (oa.length < 1)
                    throw new IllegalArgumentException("no help data page can be empty");
                for (Object o : oa) {
                    if (o == null)
                        throw new NullPointerException();
            this.helpData = helpData;
            setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            initGUI();
            currentHelpDataIndex = 0;
            updateGUI();
        private void initGUI() {
            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            //help panel
            gbc.fill = GridBagConstraints.BOTH;
            gbc.weightx = 1;
            gbc.weighty = 1;
            helpPanel = new JPanel();
            helpScrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            helpScrollPane.getViewport().setView(helpPanel);
            add(helpScrollPane,gbc);
            //buttons panel
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.weightx = 0;
            gbc.weighty = 0;
            gbc.gridy = 1;
            JPanel buttonsPanel = new JPanel();
            buttonsPanel.setLayout(new GridBagLayout());
                GridBagConstraints gbcBp = new GridBagConstraints();
                //next/previous buttons
                gbcBp.fill = GridBagConstraints.HORIZONTAL;
                gbcBp.weightx = 1;
                prevButton = new JButton("<<");
                prevButton.setEnabled(false);
                prevButton.addActionListener(this);
                buttonsPanel.add(prevButton,gbcBp);
                nextButton = new JButton(">>");
                nextButton.setEnabled(false);
                nextButton.addActionListener(this);
                gbcBp.gridx = 1;
                buttonsPanel.add(nextButton,gbcBp);
                /*//close button
                gbcBp.fill = GridBagConstraints.NONE;
                closeButton = new JButton("Close");
                closeButton.addActionListener(this);
                gbcBp.gridx = 0;
                gbcBp.gridy = 1;
                gbcBp.gridwidth = 2;
                buttonsPanel.add(closeButton,gbcBp);*/
            add(buttonsPanel,gbc);
            addComponentListener(new ComponentListener(){
                public void componentResized(ComponentEvent e) {
                    helpPanel.setPreferredSize(
                            new Dimension(
                                    (int)helpScrollPane.getViewport().getPreferredSize().getWidth(),
                                    (int)helpPanel.getPreferredSize().getHeight())
                    helpPanel.revalidate();
                public void componentMoved(ComponentEvent e) {}
                public void componentShown(ComponentEvent e) {}
                public void componentHidden(ComponentEvent e) {}
        private void updateGUI() {
            updateHelpData();
            updateNavigationButtons();
        private void updateHelpData() {
            helpPanel.removeAll();
            helpPanel.repaint();
            //insert data again
            Object[] data = helpData[currentHelpDataIndex];
            helpPanel.setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weightx = 1;
            //gbc.weighty = 1;
            for (int i = 0; i < data.length; i++) {
                Object currentData = data;
    gbc.gridy = i;
    //images - turned into labels
    if (currentData instanceof Image) {
    JLabel label = new JLabel();
    label.setIcon(new ImageIcon((Image)currentData));
    currentData = label;
    if (currentData instanceof Component) {
    //components - added as-is
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    //gbc.weightx = 1;
    helpPanel.add((Component)currentData,gbc);
    } else {
    //everyting else - as text
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    //gbc.weightx = 0;
    JTextArea textArea;
    if (currentData instanceof Document) {
    textArea = new JTextArea((Document)currentData);
    } else {
    textArea = new JTextArea(currentData.toString());
    textArea.setOpaque(false);
    textArea.setFocusable(false);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    helpPanel.add(textArea,gbc);
    helpScrollPane.getVerticalScrollBar().setValue(0);
    validate();
    private void updateNavigationButtons() {
    prevButton.setEnabled(currentHelpDataIndex != 0);
    nextButton.setEnabled(currentHelpDataIndex < helpData.length-1);
    public void actionPerformed(ActionEvent e) {
    JButton source = (JButton)e.getSource();
    /*if (source == closeButton) {
    dispose();
    } else*/ if (source == nextButton) {
    currentHelpDataIndex++;
    updateGUI();
    } else if (source == prevButton) {
    currentHelpDataIndex--;
    updateGUI();
    public static void main(String[] args) {
    HelpWindow window = new HelpWindow(
    new JDialog(),
    new Object[][]
    {"Java Technology\nSun's home for Java. Offers Windows, Solaris, and Linux Java Development Kits (JDKs), extensions, news, tutorials, and product information.\njava.sun.com/ - 26k - 17 Oct 2006 - Cached - Similar pages",
    "The Java� Tutorials\nFrom the download page, you can download the Java Tutorials for browsing ... The Java Tutorials are practical guides for programmers who want to use the ...\njava.sun.com/docs/books/tutorial/index.html - 13k - Cached - Similar pages\n[ More results from java.sun.com ]",
    new JButton("some button"),
    "Sun Microsystems\nSun Java Enterprise System Every time you log on to My Sun Connection (MSC), you're using Sun Java Enterprise System (JES) products. ...\nwww.sun.com/ - 15k - Cached - Similar pages"},
    {"another page...",
    new JCheckBox("something")}
    window.pack();
    window.setVisible(true);
    System.exit(0);
    many thanks in advance!

    Why are you doing it this way? It is just a help
    displayer right? It would be simplier to just keep
    it as text. Or create an object that can add itself.
    I veiw the instanceof Operator as a bad smell.I did this mainly because these help windows will surely contain images along with the text... so to avoid creating tons of windows, I choose to create this class.
    Did you try using a borderlayout instead of the
    gridbag?
    Put the ScrollPane in the center with the button
    panel at PAGE_END.No use. The problem is the layout management inside helpPanel.
    Messing around, the only (dirty) working solution was recreating the help panel at each resize, and using grid bag for the panel, instead of box layout. And the problem about the scroll bar value is still there...
    It's a workaround... if someone know a better way, tell me please...
    current code:
    import java.awt.Component;
    import java.awt.Dialog;
    import java.awt.Dimension;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import java.awt.Image;
    import java.awt.Insets;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.ComponentEvent;
    import java.awt.event.ComponentListener;
    import javax.swing.Box;
    import javax.swing.BoxLayout;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JCheckBox;
    import javax.swing.JComponent;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextArea;
    import javax.swing.text.Document;
    public class HelpWindow extends JDialog implements ActionListener {
        private Object[][] helpData;
        private JPanel helpPanel;
        private JButton /*closeButton,*/ nextButton, prevButton;
        JScrollPane helpScrollPane;
        private int currentHelpDataIndex;
        public HelpWindow(Dialog owner, Object[][] helpData) {
            super(owner,"Help",true);
            if (helpData.length < 1) {
                throw new IllegalArgumentException("the help data cannot be empty");
            for (Object[] oa : helpData) {
                if (oa.length < 1)
                    throw new IllegalArgumentException("no help data page can be empty");
                for (Object o : oa) {
                    if (o == null)
                        throw new NullPointerException();
            this.helpData = helpData;
            setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
            initGUI();
            currentHelpDataIndex = 0;
            updateGUI();
        private void initGUI() {
            setLayout(new GridBagLayout());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            //help panel
            gbc.fill = GridBagConstraints.BOTH;
            gbc.weightx = 1;
            gbc.weighty = 1;
            helpPanel = new JPanel();
            helpScrollPane = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
            helpScrollPane.getViewport().setView(helpPanel);
            //helpScrollPane.setPreferredSize( new Dimension(300, 300) );
            add(helpScrollPane,gbc);
            //buttons panel
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.weightx = 0;
            gbc.weighty = 0;
            gbc.gridy = 1;
            JPanel buttonsPanel = new JPanel();
            buttonsPanel.setLayout(new GridBagLayout());
                GridBagConstraints gbcBp = new GridBagConstraints();
                //next/previous buttons
                gbcBp.fill = GridBagConstraints.HORIZONTAL;
                gbcBp.weightx = 1;
                prevButton = new JButton("<<");
                prevButton.setEnabled(false);
                prevButton.addActionListener(this);
                buttonsPanel.add(prevButton,gbcBp);
                nextButton = new JButton(">>");
                nextButton.setEnabled(false);
                nextButton.addActionListener(this);
                gbcBp.gridx = 1;
                buttonsPanel.add(nextButton,gbcBp);
                /*//close button
                gbcBp.fill = GridBagConstraints.NONE;
                closeButton = new JButton("Close");
                closeButton.addActionListener(this);
                gbcBp.gridx = 0;
                gbcBp.gridy = 1;
                gbcBp.gridwidth = 2;
                buttonsPanel.add(closeButton,gbcBp);*/
            add(buttonsPanel,gbc);
            addComponentListener(new ComponentListener(){
                public void componentResized(ComponentEvent e) {
                    /*helpPanel.setPreferredSize(
                            new Dimension(
                                    (int)helpScrollPane.getViewport().getPreferredSize().getWidth(),
                                    (int)helpPanel.getPreferredSize().getHeight())
                    helpPanel.revalidate();
                    helpScrollPane.validate();*/
                    //helpPanel.revalidate();
                    //helpPanel.repaint();
                    updateHelpData();
                public void componentMoved(ComponentEvent e) {}
                public void componentShown(ComponentEvent e) {}
                public void componentHidden(ComponentEvent e) {}
        private void updateGUI() {
            updateHelpData();
            updateNavigationButtons();
        private void updateHelpData() {
            helpPanel.removeAll();
            helpPanel.repaint();
            //helpPanel = new JPanel();
            //insert data again
            Object[] data = helpData[currentHelpDataIndex];
            //helpPanel.setLayout(new BoxLayout(helpPanel,BoxLayout.Y_AXIS));
            helpPanel.setLayout(new GridBagLayout());
            //helpPanel.add(Box.createVerticalBox());
            //helpPanel.add(Box.createHorizontalGlue());
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(2,2,2,2);
            gbc.weightx = 1;
            //gbc.weighty = 1;
            for (int i = 0; i < data.length; i++) {
                Object currentData = data;
    gbc.gridy = i;
    //images - turned into labels
    if (currentData instanceof Image) {
    JLabel label = new JLabel();
    label.setIcon(new ImageIcon((Image)currentData));
    currentData = label;
    if (currentData instanceof JComponent) {
    //components - added as-is
    gbc.fill = GridBagConstraints.NONE;
    gbc.anchor = GridBagConstraints.CENTER;
    //gbc.weightx = 1;
    JComponent c = (JComponent)currentData;
    c.setAlignmentX(Component.CENTER_ALIGNMENT);
    helpPanel.add(c,gbc);
    } else {
    //everyting else - as text
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.WEST;
    //gbc.weightx = 0;
    JTextArea textArea;
    if (currentData instanceof Document) {
    textArea = new JTextArea((Document)currentData);
    } else {
    textArea = new JTextArea(currentData.toString());
    textArea.setOpaque(false);
    textArea.setFocusable(false);
    textArea.setLineWrap(true);
    textArea.setWrapStyleWord(true);
    textArea.setAlignmentX(Component.CENTER_ALIGNMENT);
    helpPanel.add(textArea,gbc);
    //helpScrollPane.getViewport().setView(helpPanel);
    helpScrollPane.validate();
    helpScrollPane.getVerticalScrollBar().setValue(helpScrollPane.getVerticalScrollBar().getMinimum());
    private void updateNavigationButtons() {
    prevButton.setEnabled(currentHelpDataIndex != 0);
    nextButton.setEnabled(currentHelpDataIndex < helpData.length-1);
    public void actionPerformed(ActionEvent e) {
    JButton source = (JButton)e.getSource();
    /*if (source == closeButton) {
    dispose();
    } else*/ if (source == nextButton) {
    currentHelpDataIndex++;
    updateGUI();
    } else if (source == prevButton) {
    currentHelpDataIndex--;
    updateGUI();
    public static void main(String[] args) {
    HelpWindow window = new HelpWindow(
    new JDialog(),
    new Object[][]
    {"Java Technology\nSun's home for Java. Offers Windows, Solaris, and Linux Java Development Kits (JDKs), extensions, news, tutorials, and product information.\njava.sun.com/ - 26k - 17 Oct 2006 - Cached - Similar pages",
    "The Java� Tutorials\nFrom the download page, you can download the Java Tutorials for browsing ... The Java Tutorials are practical guides for programmers who want to use the ...\njava.sun.com/docs/books/tutorial/index.html - 13k - Cached - Similar pages\n[ More results from java.sun.com ]",
    new JButton("some button"),
    "Sun Microsystems\nSun Java Enterprise System Every time you log on to My Sun Connection (MSC), you're using Sun Java Enterprise System (JES) products. ...\nwww.sun.com/ - 15k - Cached - Similar pages"},
    {"another page...",
    new JCheckBox("something")}
    window.setPreferredSize(new Dimension(300,300));
    window.pack();
    window.setVisible(true);
    System.exit(0);

Maybe you are looking for

  • File lock() method problem

    I know this may be a common question, but can someone explain why this code: import java.io.*; import java.nio.channels.*; import java.util.*; public class TestFileLock      private static File file;      private static RandomAccessFile fileRandom;  

  • IPod touch 5th gen. Home button stuck and power button not working! Please help!

    I have an iPod 5th Generation and the home button is jammed down! It felt sticky earlier but now it's stuck down. I used it when the home button wasn't working and had to use my notifications to change from app to app (as I didn't know about assistiv

  • Looking for some advice.

    Hi. Hope this is right forum. First post. A brief background. Years ago (2007-2008) I created a web portfolio for school. First it was in HTML (Dreamweaver) and then Flash. I hadn't really touched it in years and decided this past couple of months, a

  • P10-554 Display Driver Problem

    When running games,such as COUNTER STRIKE 1.6,my FPS would running down to 30-40.BTW,i had download the newest graphic card driver "display-s-p-xp-4485",which is issued on 05/08/2004,but failed to upgrade it.Everytime after installed the new driver,t

  • Verizon Error Message when Calling out?

    Whenever I call out to a select few numbers, I get an error message that says "We could not complete your call at this time. Announcement 3 switch 20-1" Does anyone know what this means?