How to add scrollbar to jpanel

i created a jpanel with images & related text to images, which repaints dynamically according to width,now i wann to add a vertical scrollbar to it.
plz..help me

iam getting scrollbar but iam unable to get scrolling when i change the size
my code like this....
//here iam using jpanel to get images and text
public class ImgNtext extends JPanel {
   public ImgNtext(){
       //to intialize values
       init_values();
  public void init_values{
   //In these init_values iam decalaring imageFile name & text using hashtable
   public void paintComponent(Graphics g) {
         super.paintComponent(g);
         //getting width of screen
         int gw = getWidth();
         //then iam retriving all the values using while loop
         while(i.hasMoreElements())
                    //accroding to width iam painting the components
                      if(gw<100){
                           g.drawImage(image,x,y,null);
                           g.drawString(string,x,y+80);
                           gw -=100;
                           x += 100;
                     else{
                           y += 100;
                           gw = getWidth();
public class ImagePanel
       ImgNtext it = new ImgNtext();
       JScrollPane sp;
       public ImagePanel() {
                 JFrame jf = new JFrame();
                 jf.setSize(1000,1000);
                 scp = new                JScrollPane(it,JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
                 jf.getContentPane().add(scp);
                 jf.setVisible(true);
          public static void main(String s[]){
               ImagePanel img = new ImagePanel();
}

Similar Messages

  • How to add scrollbar to the JInternal Frame

    How to add scrollbar to JInternal Frame?
    I have One JInternal frame i want it should have a scrollbar when we reduces its size.

    [url http://java.sun.com/docs/books/tutorial/uiswing/components/scrollpane.html]How to Use Scroll Panes

  • How to add scrollbar to jpopup menu

    Hi everyone,
    Do u know how to add a scrollbar to jpopup menu ?

    Menus don't scroll, and shouldn't scroll. Given that, you shouldn't try and use JPopupMenu at all... rather, create your own component that implements the look and behavior you want. It will be far easier and less frustrating.
    Either that... or you should re-think what functionality you are trying to provide, and how you are trying to implement it. A scrolling menu just seems like a counterintuitive wacky UI design to me.

  • How To Add scrollbar in Spark list which will work on mouse movement ?

    Hi,
    I want to add scrollbar in Spark list which will work on mouse movement, i.e instead scrolling down it will sense mouse position and scroll automatically. I could not find a way to handle this with horizontalLayout.
    I tried hovering on list and setting ensureIndexIsVisible(index) but hovering element index is not present in the Spark List.
    Any idea on this will be highly appreciated.
    Thanks in advance
    Avishek

    Hi,
    I want to add scrollbar in Spark list which will work on mouse movement, i.e instead scrolling down it will sense mouse position and scroll automatically. I could not find a way to handle this with horizontalLayout.
    I tried hovering on list and setting ensureIndexIsVisible(index) but hovering element index is not present in the Spark List.
    Any idea on this will be highly appreciated.
    Thanks in advance
    Avishek

  • How to add separator on JPanel?

    How do you add a separator on a JPanel like shown on the following screen shot?:
    http://www.carpenterdev.com/scrn.jpg
    Thanks,
    --BobC                                                                                                                                                                                                                                                                               

    Thanks! I'll do that - upperPanel JSeparator lowerPanel; Makes sense.
    --BobC                                                                                                                                                                                   

  • How to add component to JPanel

    Hello,
    I Try to add a JPnel to other JPnel
    but it works not ther is a error in this code ??
    class MyClass extends JFrame
        Container contentPane;
      public MyClass()
                  contentPane = this.getContentPane();
                  contentPane.setBorderLayout(new BorderLayout());
                 MainPanel();
    puplic void MainPanel()
         Dimension dim = new Dimension(w,h);
         Dimension aDim = new Dimension((w / 2),(h / 2));
         JPanel mainPanel = JPanel();
         mainPanel.setPrefferedSize(dim);
         mainPanel.setLayout(new BorderLayout());
         JPanel pp = getLanguagePanel(aDim);
         pp.revalidate();
         mainPanel.add(pp,BorderLayout.PAGE_END);
         mainPanel.revalidate();
         contentPane.add(mainPanel,BoderLayout.CENTER)
    public JPanel getLanguagePanel(Dimension aDim)
             JPanel retPanel = new JPanel();
         retPanel.setPreferredSize(aDim);
         retPanel.setBorder(null);
         JLabel L = new JLabel("Test Label");
         L.setBounds(50,50,250,30);
         retPanel.add(L);
         retPanel.setBackground(Color.GREEN);
         retPanel.setOpaque(true);
         retPanel.revalidate();
         retPanel.repaint();
         return retPanel;
    }thanks

    contentPane.setBorderLayout(...)There is no such method. Your compiler should be telling you this.
    puplic void MainPanel()There is no such modifier. Your compiler should be telling you this.
    mainPanel.setPrefferedSize(...)There is no such method. Your compiler should be telling you this.
    BoderLayout.CENTERThere is no such class. Your compiler should be telling your this.

  • How to add scroll bar to JDesktopPane?

    Hi All,
         After download the "InternalFrameDemo.java" from the swing tutorial, I want to add scrollbars to JDesktopPane so that whenever a internal frame moves off the desktop view port, a scrollbar will display. I have tried many ways to implement this but no success.
    Do you know how to add scrollbars to JDesktopPane?
    Thanks
    Anson

    You can't get there from here! Assuming that wou want is to make the desktop scrollable that is.
    The trick to make somthing scrollable is to make JScrollPane CONTAIN the component to be scrolled. If you could ask the desktop to return the component it contains, you might have a chance but no luck, the desktop pane actually inherits a layered pane which is most likey is what you would like JScrollPane to contain.
    Now here's another angle to this story... the desktop is complex enough without scrollbars, why would you want to complicate things by adding a scroll bar anyway? Say one of its window is maximized and has a scrollbar of its own AND the desktop has one.... that makes TWO scroll bars side by side. Talk about confusing.
    I believe the desktop was designed so scroll bars can't be added for a very good reason: good UI practises.

  • How to add an image to the JPanel

    i have been searching for many to add in an iamge to the JPanel...but with error..can anyone kndly help?
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class adv extends JPanel {
    ImageIcon pic = new ImageIcon("home.gif");
    public void paintComponent(Graphics g) {
    g.drawImage(pic,0,0,this);
    super.paintComponent(g);
    public static void main(String[] args) {
    adv mpg= new adv();
    mpg.setLayout(new GridLayout(5,1,15,15));
         JFrame window = new JFrame ("dv");
    window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);     
    window.add(mpg);
    window.setVisible(true);
    window.setSize (550,225);
    }

    i have try out the suggestion that u have provided...still with error...wat can i do to solve it? any other way?
    below is how i add to my program...
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    public class adv extends JPanel {
        ImageIcon pic = createImageIcon("home.gif");
        public void paintComponent(Graphics g) {
      super.paintComponent(g);
    g.drawImage(pic.getImage(),0,0,this);
        public static void main(String[] args) {
           /*adv mpg= new adv();
          mpg.setLayout(new GridLayout(5,1,15,15));
             JFrame window = new JFrame ("dv");
             window.setLayout(new BorderLayout());
             frame.add(mpg, BorderLayout.CENTER);
           window.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);     
           window.add(mpg);
           window.setVisible(true);
           window.setSize (550,225);*/
           adv mpg = new adv();
           JFrame frame = new JFrame();
         frame.setLayout(new BorderLayout());
         frame.add(pic, BorderLayout.CENTER);
         frame.setSize(500, 500);
         frame.setVisible(true);
    }

  • How to add an image to a JPanel ?

    hi,
    do you now how to add an image to a JPanel ?
    thanks a lot !

    You can either use the Graphics method drawImage from the panel's paintComponent(Graphics g) method, or you can create an ImageIcon, with your Image in its constructor. And then create a JLabel, passing that ImageIcon in its constructor. Then, you can simple use the panel.add() method to add that JLabel.
    For using the paintComponent method, check out the thread already posted above (I'll type it in again just in case)
    http://forum.java.sun.com/thread.jsp?forum=31&thread=288769
    If you want to use a JLabel, you can do something like this:
    Image img;
    JLabel label = new JLabel(new ImageIcon(img));
    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout());
    panel.add(label);Val

  • How to add an image in a JPanel

    Hi All,
    How to add an image in a JPanel and make it display.
    Thanks,

    I have tried with the below code. If I there is any fault please correct me.
    import java.awt.event.*;
    import java.awt.*;
    import javax.swing.*;
    public class HomePage extends JFrame implements     ActionListener {
        JButton cmdClick;
        JLabel label;
        JPanel homePanel = new JPanel();
        JPanel headPanel = new JPanel();
        JPanel btPanel = new JPanel();
        private JPanel mainPanel = new JPanel(new CardLayout());
        CardLayout cl;
        CalScenario calcFrame = null;
        public HomePage() {
           setTitle("Test Kit");
           setSize( 1008,399);
           setBackground( Color.gray );
           setResizable(false);
           Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
           Rectangle window = getBounds();
           setLocation((screen.width - window.width) / 2, (screen.height - window.height) / 2);
           setVisible(true);
            homePanel.setLayout(new BorderLayout());
            headPanel.setPreferredSize(new Dimension(1008,153));
            label = new JLabel("Main menu");
            headPanel.add(label);
            headPanel.setBackground(Color.CYAN);
            ImageIcon icon = new ImageIcon("images/slash.gif");
            JLabel imglabel = new JLabel();
            imglabel.setIcon(icon);
            headPanel.add(label);
            this.getContentPane().add(headPanel);
            btPanel.setBackground(Color.ORANGE);
            cmdClick = new JButton("Click here");
            btPanel.add(cmdClick);
            cmdClick.addActionListener(this);
            homePanel.add("North",headPanel);
            homePanel.add("West",btPanel);
            calcFrame = new CalScenario(mainPanel);
            mainPanel.add(homePanel, "HomePanel");
            mainPanel.add(calcFrame, "CalcFrame");
            cl = (CardLayout) (mainPanel.getLayout());
            add(mainPanel);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public void actionPerformed(ActionEvent source)  {
          if (source.getSource() == (JButton) cmdClick) {
                cl.show(mainPanel, "CalcFrame");
        public static void main( String args[]) {
             HomePage homeFrame = new HomePage();
             homeFrame.setVisible(true);
    }

  • How to add JPanel in  JComboBox?

    Hi.
    How to add JPanel in JComboBox...?
    Regards
    Bilal

    I do not know much about Cardlayout.
    As far as I know, it is a layout which let you assign a serveral 'card' and exist together. By consider the order of the card, you could change the view of each page by using method- first, last, next etc. However, I would like to know what if I got a number of buttons, say A B C D E F, and having cards called a b c d e f,I know I could change from a to b, but what if I want to change from c to e by pressing the button E (assuming it showing the c card now).
    Actually, I was able to create the code now which adding one JPanel to another now. First create a JPanel with prefer size, min max size.
    then add a JPanel into the CENTER of the above JPanel, both using borderlayout.
    But having a little difficulties, could I add more JPanel into the CENTER such that one overlapping each other, by those Buttons, through action and event, hide those which I do not want to show?
    Like A B C buttons, a b c panels. When press A hide b c and show a, so on.
    Could I use method like movetofront(something like that, forgot detail which read in a book) to do this?
    Cheers

  • How can we add components to JPanel so that they can be resizeable

    Is it possible to add components to JPanel so that we can resize them or drag them.

    You could try searching the forums, but I'll save you the trouble. tjacobs has oft posted code which does what you want, both dragging and resizing.
    You can find an example here or here.

  • How to add Panel in JScrollPane? URGENT!

    I need to add a Panel in JScrollPane
    I have try to add JPanel into JScrollPane, but apparently, the JPanel did not show up at all in the JScrollPane (all i see is the border of JScrollPane)
    Then I switch my JPanel to Panel (awt) and it does appear on the JScrollPane, but scrollbars are not visible even i have set the size of the panel is larger than the JScrollPane. (and i also set the VERTICAL_SCROLLBARS_ALWAYS) I can scroll with my mousewhieel, but the panel can scroll out of place(ie outside of the Jscrollpane)
    Can someone teach me how to add a Panel or JPanel to a JScrollPane Please~ Thanks!!!

    here is an example that illustrate my problem:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.filechooser.*;
    public class testing extends JFrame
         public testing()
              Container pane=getContentPane();
              pane.setLayout(null);
              setSize(600,600);
              JPanel backgroundpanel= new JPanel();
              backgroundpanel.setLayout(null);
              backgroundpanel.setSize(500,500);
              backgroundpanel.setLocation(0,0);
              Panel insidepanel = new Panel();
              insidepanel.setLayout(null);
              insidepanel.setSize(300,300);
              insidepanel.setLocation(0,0);
              JLabel something= new JLabel("something");
              JTextField someTF= new JTextField(10);
              something.setSize(100,20);
              something.setLocation (20,20);
              someTF.setSize(100,20);
              someTF.setLocation(50,60);
              insidepanel.add(something);
              insidepanel.add(someTF);
              JScrollPane scrollpane= new JScrollPane(insidepanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
              scrollpane.setSize(200,200);
              scrollpane.setLocation(10,10);
              backgroundpanel.add(scrollpane);
              pane.add(backgroundpanel);
              setVisible(true);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String args[]) throws FileNotFoundException, IOException
                        testing test=new testing();
    apparently, the panel i add in teh scrollpane is on the top layer instead of inside the scroll... can anyone help?

  • How can I Print a JPanel including all added Components?

    Hello dear saviours,
    I have a JPanel object which is responsible for displaying a Graph.
    I need to Print the Components of this JPanel as close to what they look like to the user as possible.
    I thought about casting the JPanel into an Image of some kind, but couldn't find anything but how to add am Image to a JPanel (God damned search engines :-).
    But wait, this gets more interesting!
    I need to have control over the scale of the Printed matterial.
    I want the option to choose between a single page and dividing the drawing the JPanel displays into Multiple-Pages.
    In both cases I need full details of all the data (Nodes, Arcs, Text describing the various Nodes and Arcs names or type, etc.).Keeping the sizes of all these components is also important (that means, I don't want the nodes to be tinny-winny and the Fonts to be twice as large as the nodes and so on...).
    Attached is the code of the PrintUtillity class I created as an API for printing the JPanel data:
    package ild;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.print.*;
    /** A simple utility class that lets you very simply print
    * an arbitrary component. Just pass the component to the
    * PrintUtilities.printComponent. The component you want to
    * print doesn't need a print method and doesn't have to
    * implement any interface or do anything special at all.
    * <P>
    * If you are going to be printing many times, it is marginally more
    * efficient to first do the following:
    * <PRE>
    * PrintUtilities printHelper = new PrintUtilities(theComponent);
    * </PRE>
    * then later do printHelper.print(). But this is a very tiny
    * difference, so in most cases just do the simpler
    * PrintUtilities.printComponent(componentToBePrinted).
    * 7/99 Marty Hall, http://www.apl.jhu.edu/~hall/java/
    * May be freely used or adapted.
    public class PrintUtilities implements Printable {
    private Component componentToBePrinted;
    public PrintUtilities(Component componentToBePrinted) {
    this.componentToBePrinted = componentToBePrinted;
    public static void printComponent(Component c) {
    new PrintUtilities(c).print();
    public void print() {
    PrinterJob printJob = PrinterJob.getPrinterJob();
    printJob.setPrintable(this);
    if (printJob.printDialog())
    try {
    printJob.print();
    } catch(PrinterException pe) {
    System.out.println("Error printing: " + pe);
    public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
    return(NO_SUCH_PAGE);
    } else {
    Graphics2D g2d = (Graphics2D)g;
    // double scale = 2;
    // g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    double scaleFactor = java.lang.Math.min((double)this.componentToBePrinted.getSize().width/(double)(pageFormat.getImageableWidth()),
    (double)this.componentToBePrinted.getSize().height/(double)(pageFormat.getImageableHeight()));
    g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    g2d.scale(1.0/scaleFactor,1.0/scaleFactor);
    // disableDoubleBuffering(componentToBePrinted);
    componentToBePrinted.paint(g2d);
    enableDoubleBuffering(componentToBePrinted);
    return(PAGE_EXISTS);
    /** The speed and quality of printing suffers dramatically if
    * any of the containers have double buffering turned on.
    * So this turns if off globally.
    * @see enableDoubleBuffering
    public static void disableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(false);
    /** Re-enables double buffering globally. */
    public static void enableDoubleBuffering(Component c) {
    RepaintManager currentManager = RepaintManager.currentManager(c);
    currentManager.setDoubleBufferingEnabled(true);

    That's a nice utility, but my JPanel gets truncated when printed. Is there a way to print a JPanel in full.

  • How to add a table(from TableRenderDemo) to a JFrame again

    Hello again:
    Thanks for stephen andrews's adivice, I follow your adivice to add code (it is in
    EventHandeler of DrawCalendar class, and they indicated by ???????????), but it still not work, please check for me why, Thanks.
    My problem
    Please run my coding first, and get some view from my coding.
    At the movement, I got a problem, I have not idea how to add a table(it is from TableRenderDemo) to JFrame when I click on the button(from DrawCalendar) of the numer 20, and I want the table disply under the buttons(from DrawCalendar).
    Please help me to solve this problem, thanks.
    *This program for add some buttons and a table on JFrame
    import java.awt.*;
    import javax.swing.*;public class TestMain extends JFrame{
    private static TableRenderDemo tRD;
    private static TestMain tM;
    protected static Container c;
    private static DrawCalendar dC;
    public static void main(String[] args){
    tM = new TestMain();
    tM.setVisible(true);
         public TestMain(){
         super(" Test");
         setSize(800,600);
    //set up layoutManager
    c=getContentPane();
    c.setLayout ( new GridLayout(3,1));
    tRD=new TableRenderDemo();
    dC=new DrawCalendar();
    addItems();//add Buttons to JFrame
    private void addItems(){
         c.add(dC); //add Buttons to JFrame
         //c.add(tRD); //add Table to JFrame     
    *This program for add some buttons to JPanel
    *and add listeners to each button
    *I want to display myTable under the buttons,
    *when I click on number 20, but why it doesn't
    *work, The coding for these part are indicated by ??????????????
    [import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.GridLayout;
    public class DrawCalendar extends JPanel {
         private static DrawCalendar dC;
         private static TestMain tM;
         private static TableRenderDemo myTable;
         private static GridLayout gL;
         private static final int nlen = 35;
        private static String names[] = new String[nlen];
    private static JButton buttons[] = new JButton[nlen];
         public DrawCalendar(){
              gL=new GridLayout(5,7,0,0);
              setLayout(gL);
              assignValues();
              addJButton();
              registerListener();
    //assign values to each button
         private void assignValues(){
              names = new String[35];
         for(int i = 0; i < names.length; i++)
         names[i] = Integer.toString(i + 1);
    //create buttons and add them to Jpanel
    private void addJButton(){
         buttons=new JButton[names.length];
         for (int i=0; i<names.length; i++){
         buttons=new JButton(names[i]);
         buttons[i].setBorder(null);
         buttons[i].setBackground(Color.white);
         buttons[i].setFont(new Font ("Palatino", 0,8));
    add(buttons[i]);
    //add listeners to each button
    private void registerListener(){
         for(int i=0; i<35; i++)
              buttons[i].addActionListener(new EventHandler());          
    //I want to display myTable under the buttons,
    //when I click on number 20, but why it doesn't
    //work
    private class EventHandler implements ActionListener{
         public void actionPerformed(ActionEvent e){
         for(int i=0; i<35; i++){
         if(i==20){                  //????????????????????
              tM=new TestMain(); //I want to display myTable under the buttons,
              tM.c.removeAll(); //when I click on number 20, but why it doesn't
              tM.c.add(dC); //work
              tM.c.add(myTable); //???????????????????????????????????????
              tM.validate();
         if(e.getSource()==buttons[i]){
         System.out.println("testing " + names[i]);
         break;
    *This program create a table with some data
    [import javax.swing.table.AbstractTableModel;
    import javax.swing.table.TableColumn;
    import javax.swing.DefaultCellEditor;
    import javax.swing.table.TableCellRenderer;
    import javax.swing.table.DefaultTableCellRenderer;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class TableRenderDemo extends JScrollPane {
        private boolean DEBUG = true;
        public TableRenderDemo() {
          //  super("TableRenderDemo");
            MyTableModel myModel = new MyTableModel();
            JTable table = new JTable(myModel);
            table.setPreferredScrollableViewportSize(new Dimension(700, 70));//500,70
             //Create the scroll pane and add the table to it.
             setViewportView(table);
            //Set up column sizes.
            initColumnSizes(table, myModel);
            //Fiddle with the Sport column's cell editors/renderers.
            setUpSportColumn(table.getColumnModel().getColumn(2));
    * This method picks good column sizes.
    * If all column heads are wider than the column's cells'
    * contents, then you can just use column.sizeWidthToFit().
    private void initColumnSizes(JTable table, MyTableModel model) {
    TableColumn column = null;
    Component comp = null;
    int headerWidth = 0;
    int cellWidth = 0;
    Object[] longValues = model.longValues;
    for (int i = 0; i < 5; i++) {
    column = table.getColumnModel().getColumn(i);
    try {
    comp = column.getHeaderRenderer().
    getTableCellRendererComponent(
    null, column.getHeaderValue(),
    false, false, 0, 0);
    headerWidth = comp.getPreferredSize().width;
    } catch (NullPointerException e) {
    System.err.println("Null pointer exception!");
    System.err.println(" getHeaderRenderer returns null in 1.3.");
    System.err.println(" The replacement is getDefaultRenderer.");
    comp = table.getDefaultRenderer(model.getColumnClass(i)).
    getTableCellRendererComponent(
    table, longValues[i],
    false, false, 0, i);
    cellWidth = comp.getPreferredSize().width;
    if (DEBUG) {
    System.out.println("Initializing width of column "
    + i + ". "
    + "headerWidth = " + headerWidth
    + "; cellWidth = " + cellWidth);
    //XXX: Before Swing 1.1 Beta 2, use setMinWidth instead.
    column.setPreferredWidth(Math.max(headerWidth, cellWidth));
    public void setUpSportColumn(TableColumn sportColumn) {
    //Set up the editor for the sport cells.
    JComboBox comboBox = new JComboBox();
    comboBox.addItem("Snowboarding");
    comboBox.addItem("Rowing");
    comboBox.addItem("Chasing toddlers");
    comboBox.addItem("Speed reading");
    comboBox.addItem("Teaching high school");
    comboBox.addItem("None");
    sportColumn.setCellEditor(new DefaultCellEditor(comboBox));
    //Set up tool tips for the sport cells.
    DefaultTableCellRenderer renderer =
    new DefaultTableCellRenderer();
    renderer.setToolTipText("Click for combo box");
    sportColumn.setCellRenderer(renderer);
    //Set up tool tip for the sport column header.
    TableCellRenderer headerRenderer = sportColumn.getHeaderRenderer();
    if (headerRenderer instanceof DefaultTableCellRenderer) {
    ((DefaultTableCellRenderer)headerRenderer).setToolTipText(
    "Click the sport to see a list of choices");
    class MyTableModel extends AbstractTableModel {
    final String[] columnNames = {"First Name",
    "Last Name",
    "Sport",
    "# of Years",
    "Vegetarian"};
    final Object[][] data = {
    {"Mary ", "Campione",
    "Snowboarding", new Integer(5), new Boolean(false)},
    {"Alison", "Huml",
    "Rowing", new Integer(3), new Boolean(true)},
    {"Kathy", "Walrath",
    "Chasing toddlers", new Integer(2), new Boolean(false)},
    {"Sharon", "Zakhour",
    "Speed reading", new Integer(20), new Boolean(true)},
    {"Angela", "Lih",
    "Teaching high school", new Integer(4), new Boolean(false)}
    public final Object[] longValues = {"Angela", "Andrews",
    "Teaching high school",
    new Integer(20), Boolean.TRUE};
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return data.length;
    public String getColumnName(int col) {
    return columnNames[col];
    public Object getValueAt(int row, int col) {
    return data[row][col];
    * JTable uses this method to determine the default renderer/
    * editor for each cell. If we didn't implement this method,
    * then the last column would contain text ("true"/"false"),
    * rather than a check box.
    public Class getColumnClass(int c) {
    return getValueAt(0, c).getClass();
    * Don't need to implement this method unless your table's
    * editable.
    public boolean isCellEditable(int row, int col) {
    //Note that the data/cell address is constant,
    //no matter where the cell appears onscreen.
    if (col < 2) {
    return false;
    } else {
    return true;
    * Don't need to implement this method unless your table's
    * data can change.
    public void setValueAt(Object value, int row, int col) {
    if (DEBUG) {
    System.out.println("Setting value at " + row + "," + col
    + " to " + value
    + " (an instance of "
    + value.getClass() + ")");
    if (data[0][col] instanceof Integer
    && !(value instanceof Integer)) {
    //With JFC/Swing 1.1 and JDK 1.2, we need to create
    //an Integer from the value; otherwise, the column
    //switches to contain Strings. Starting with v 1.3,
    //the table automatically converts value to an Integer,
    //so you only need the code in the 'else' part of this
    //'if' block.
    try {
    data[row][col] = new Integer(value.toString());
    fireTableCellUpdated(row, col);
    } catch (NumberFormatException e) {
    JOptionPane.showMessageDialog(TableRenderDemo.this,
    "The \"" + getColumnName(col)
    + "\" column accepts only integer values.");
    } else {
    data[row][col] = value;
    fireTableCellUpdated(row, col);
    if (DEBUG) {
    System.out.println("New value of data:");
    printDebugData();
    private void printDebugData() {
    int numRows = getRowCount();
    int numCols = getColumnCount();
    for (int i=0; i < numRows; i++) {
    System.out.print(" row " + i + ":");
    for (int j=0; j < numCols; j++) {
    System.out.print(" " + data[i][j]);
    System.out.println();
    System.out.println("--------------------------");

    http://forum.java.sun.com/faq.jsp#format

Maybe you are looking for

  • Functions from Module Scoping Question

    Hello, I have the following case: I`m using module that contains several functions, some of them are executing commends in remote sessions. These functions are used from Powershell Script. The issue is that when function refers to variable from the l

  • 1z0-045 - 10g upgrade exam for oracle 8i Ocps

    Hi Guys, Can any body tell me about 1z0-045 exam books or material. Thanks in advance. Ram

  • What is the consensus regarding AMM

    Hi I am running a test database on AIX and have just upgraded from 10.2 to 11.2 When i created my database using DBCA i set the SGA to 512 mb. When i upgraded to 11g it said the minimum was 624mb which i increased it to. I have just had a message in

  • Fatal error when trying to load illustrator on windows 8.1.

    I deactivated cs5 on my windows xp and loaded the cs5 disk onto new windows 8 computer. But illustrator will not load, shows fatal error, does not even show in the menu of programs on disk, but if I stick the disk back into the xp machine, it loads f

  • How to clear Cache in application module

    Hi, i am using jDeveloper 10.1.3.4 ADF BC after executing ADF search form, i want to clear Cache. how can i do it. Pl. help Thanks Ajit