Adding Canvas to JScrollPane

I'm trying to add a Canvas to a JScrollPane, but it always seems to show the ENTIRE canvas instead of just a scrollable portion of it.
I've read about and tried examples using methods such as 'setPreferredSize' for both the scroll pane and it's container (I'm using a JPanel), but neither of these seem to stop the canvas from showing at full size.
I've also tried 'scrollPane.setViewportView(myCanvas)', but this doesn't work either.
Any ideas anyone?? I'm really stuck on this.

Canvas is a heavy component and JScrollPane is a light component. A heavy component always paint on top a light component.
The better is using only Swing's components or only AWT's components. Mixing have some problems
Hope this help.

Similar Messages

  • Printing JPanel that is added to the JScrollPane

    Hi
    I am facing a typical problem while I am printing my JPanel.
    My Panel is added to the JScrollPane.And I added 200 Images to the JPanel (20 rows and 10 columns).
    To see the 6,7,8,9,10 Images I have to scroll it left side and for 80 to 200 images I have to scroll down.
    Now if i print my JPanel it is only printing the Images those are visible to the user at a time. If scroll down and say print again it is printing the bottom components and missing Top components (Images).
    I want to print all the images at a time.
    Can any body suggest me how to do it. My Panel implements Printable interface and the following is the print method that I implemented
    public int print(Graphics g, PageFormat pageFormat, int pageIndex) {
    if (pageIndex > 0) {
    return(NO_SUCH_PAGE);
    } else {
    Graphics2D g2d = (Graphics2D)g;
    g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
    componentToBePrinted.paintAll(g2d);
    return(PAGE_EXISTS);
    Thank you and Regards
    Kiran Kumar Vasireddy

    could you publish the entire code or at least your paintall method....
    Loic

  • Canvas and JScrollPane

    Hi,
    I have a GUI which has textboxes and buttons on one side and a canvas on the other. I have implemented a scrollpane onto the canvas, so I can scroll graphics. I have added the canvas to the scrollpane but when I compile, the screen only shows the scrolling canvas, the buttons etc have disappeared. The canvas is set in an XYLayout, is their a setpreferredlocation so the canvas is drawn in the write place once added to the scrollpane.
    can anyone help.
    thanks

    One question, you're posting in Project swing, but reading your post, it seems your not using swing at all. Did you use swing? if no, well you should have a look at classes such as javax.swing.JScrollPane. If yes, well, why do you make your own JScrollPane-like class since it already exist. If your using awt, you should have posted this message in another forum, but then again, you could have used java.awt.ScrollPane.
    So I will rather answer by another question: Why do you implement your own scrollpane?
    Note: maybe I should have read "I use a scrollpane" instead of "I have implemented a scrollpane".

  • Re: adding canvas to applet

    Hi
    I am trying to add a canvas to an applet. I am successful in doing so. There is a JMenuBar added to the applet. when I click on the file menu The contents are being displayed behind the canvas and as a result I am neither able to see the buttons nor select them. Could some one help me with this.
    Note: Once you compile the code you wouldn't be able to see the contents right away. Click on left top,immidiately below the applet menu. This will repaint the contentpane. This is some thing I am working on.
    applet class
    package aple;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Shape;
    import java.awt.geom.AffineTransform;
    import java.util.ArrayList;
    import javax.swing.JApplet;
    public class NewJApplet extends JApplet{
        public Graphics2D g2;
        AffineTransform atf = new AffineTransform();
        sketch sk = new sketch();   
            @Override
        public void init() {      
            getContentPane().add(sk);
           Gui gui = new Gui();
            // menubar
            this.setJMenuBar(gui.Gui());     
        @Override
    gui class
    package aple;
    import javax.swing.JMenu;
    import javax.swing.JMenuBar;
    import javax.swing.JMenuItem;
    public class Gui {
        JMenuBar menuBar;
        JMenu file,edit,insert,view,draw,circle;
        JMenuItem nu,close,saveAs,open,centreandradius,line,rectangle,point,arc;
        public JMenuBar Gui(){
            //Menubar
            menuBar = new JMenuBar();
            //Menus
            file = new JMenu("File");
            menuBar.add(file);
            edit = new JMenu("Edit");
            menuBar.add(edit);
            view = new JMenu("View");
            menuBar.add(view);
            insert = new JMenu("Insert");       
            draw = new JMenu("Draw");
            circle = new JMenu("Circle");
            draw.add(circle);
            insert.add(draw);       
            menuBar.add(insert);
            //MenuItems
            nu = new JMenuItem("New");
            file.add(nu);
            open = new JMenuItem("Open");
            file.add(open);
            saveAs = new JMenuItem("SaveAs");
            file.add(saveAs);
            close = new JMenuItem("Close");
            file.add(close);
            line = new JMenuItem("Line");
            draw.add(line);
            centreandradius = new JMenuItem("Centre and Radius");
            circle.add(centreandradius);
            rectangle = new JMenuItem("Rectangle");
            draw.add(rectangle);
            point = new JMenuItem("Point");
            draw.add(point);
            arc = new JMenuItem("arc");
            draw.add("Arc");
            return(menuBar);
    sketch class
    package aple;
    import java.awt.Canvas;
    import java.awt.Color;
    import java.awt.Graphics;
    public class sketch extends Canvas{
        public void sketch(){
            this.setBackground(Color.green);
        @Override
        public void paint(Graphics g){
         // g.fillRect(50,50, 50, 50); 
    }

    When you were using JPanel, your "setBackground" didn't work because you were overriding its paint(Graphics) method without calling "super.paint(g);". If you don't do this, the panel won't paint its background.
    You should also override "protected void paintComponent(Graphics g)" in any JComponent, such as JPanel, instead of just "paint(Graphics)". (And don't forget to call super.paintComponent(g) FIRST in your subclass's overridden method, if you want the background painted):
    class MyJPanelSubclass extends JPanel {
       protected void paintComponent(Graphics g) {
          super.paintComponent(g); // Paints background and any other stuff normally painted.
          // Do your custom painting here.
    }

  • Very basic problem with a Canvas and JScrollPane

    Ok, I'm making this software, with a lot of graphics, and as usual I start all classes alone to see them work and then I put them together in one nice JFrame with MenuBar and so on... but something strange (to me) happened when I made a JScrollPane with some of the Canvas because I couldn't make them for 1024x768 because of its contents.... so I add this JScrollPane to the TabbedPane as a new tab, so I have in my JFrame: the menubar, the tabbedpane and the canvas with a vertical scrollbar in the right, BUT, when I scroll down, the Canvas starts to scroll over the tabbedpane and the menubar!
    very wierd to me, I know one must try to not use scrollbars, but I really need this to work this way!
    thanks!!
    help!!
    Message was edited by:
    Reinaldo_Matte

    Ok, I'm making this software, with a lot of graphics,
    and as usual I start all classes alone to see them
    work and then I put them together in one nice JFrame
    with MenuBar and so on... but something strange (to
    me) happened when I made a JScrollPane with some of
    the Canvas because I couldn't make them for 1024x768
    because of its contents.... so I add this JScrollPane
    to the TabbedPane as a new tab, so I have in my
    JFrame: the menubar, the tabbedpane and the canvas
    with a vertical scrollbar in the right, BUT, when I
    scroll down, the Canvas starts to scroll over the
    tabbedpane and the menubar!
    very wierd to me, I know one must try to not use
    scrollbars, but I really need this to work this way!
    thanks!!
    help!!Don't mix heavyweight(AWT) components such as Canvas, with lightweight (Swing) components.
    See:
    http://java.sun.com/products/jfc/tsc/articles/mixing/
    and
    http://java.sun.com/products/jfc/tsc/articles/painting/index.html

  • MouseDragged on canvas, and JScrollPane

    Hi,
    I have created a canvas which appear transparent in front of the JScrollPane.
    How to make the ScrollBar in JScrollPane scrolling down while the mouse is drag on the canvas?
    Here is my code:
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.image.*;
    import java.awt.geom.*;
    public class Try extends JFrame{
         JPanel all = new JPanel(new BorderLayout());
         JPanel main = new JPanel(new BorderLayout());
         DisplayCanvas canvas;
         JScrollPane scroll;
         JButton btn1;
         public Try(){
              super("Trying");
              setResizable(false);
              canvas = new DisplayCanvas();
              scroll = new JScrollPane(new JLabel(new ImageIcon("contain.jpg")));
              scroll.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
              scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
              main.add(scroll);
              canvas.setOpaque(false);
              all.add(main,BorderLayout.CENTER);
              all.setBounds(55,82,240,319);
              setContentPane(new JLabel(new ImageIcon("myBorder.gif")));
              getContentPane().add(canvas);
              getContentPane().add(all);
              addWindowListener(new WindowEventHandler());
              pack();
              setVisible(true);
              class WindowEventHandler extends WindowAdapter{
                   public void windowClosing(WindowEvent e){
                        System.exit(0);
              public static void main(String args[]){
                   new Try();
    class DisplayCanvas extends JPanel{
         BufferedImage bi;
         AffineTransform at;
         double x;
         DisplayCanvas(){
              setBounds(55,105,239,295);
              addMouseMotionListener(new MouseMotionHandler());
              Image image = getToolkit().getImage("line.gif");
              MediaTracker mt = new MediaTracker(this);
              mt.addImage(image,1);
              try{
                   mt.waitForAll();
              }catch (Exception e){
                   System.out.println("Exception while loading image.");
              if(image.getWidth(this)==-1){
                   System.out.println("Make sure image line.jpg is in the same directory");
                   System.exit(0);
              bi = new BufferedImage(image.getWidth(this),image.getHeight(this),BufferedImage.TYPE_INT_ARGB);
              Graphics2D big = bi.createGraphics();
              big.drawImage(image,0,0,this);
              at = new AffineTransform();
              at.translate(getWidth()/2, getHeight()/2);
         public void paintComponent(Graphics g){
              super.paintComponent(g);
              Graphics2D g2D = (Graphics2D)g;
              AffineTransform saveXform = g2D.getTransform();
              at.rotate(Math.toRadians(x));
              AffineTransform toCenterAt = new AffineTransform();
              toCenterAt.concatenate(at);
              toCenterAt.translate(-(getWidth()/2),-(getHeight()/2));
              g2D.transform(toCenterAt);
              g2D.drawImage(bi,150,200,this);
              g2D.setTransform(saveXform);
         class MouseMotionHandler extends MouseMotionAdapter{
              public void mouseDragged(MouseEvent e){
                   x = 5;
                   repaint();
    }

    Already answered here:
    http://forum.java.sun.com/thread.jspa?threadID=5148607

  • Problem in Adding Panel to JScrollPane

    I have added a JScrollPane to the Frame which has GridbagLayout.For JScrollPane,I added one panel.I set the background color of Panel as white.But I am unable to get the white color.I tried by changing background color of JScrollPane also.Still I am unable to get the white color.I set the size of panel as (3000,300) then also I am not getting scroll bars.
    If anybody worked on JScrollpane Please help me.
    Thanks in advance
    Vattikuti

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Test extends JFrame {
        public Test() {
         setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         Container content = getContentPane();
         content.setLayout(new GridBagLayout());
         JPanel myPanel = new JPanel();
         myPanel.setBackground(Color.white);
         myPanel.setPreferredSize(new Dimension(500,500));
         myPanel.setBorder(BorderFactory.createTitledBorder("Hello"));
         content.add(new JScrollPane(myPanel), new GridBagConstraints(0,0,1,1,1.0,1.0,
                   GridBagConstraints.EAST, GridBagConstraints.BOTH,
                   new Insets(2,2,2,2),0,0));
         setSize(200,200);
         show();
        public static void main(String[] args) { new Test(); }
    }

  • Adding JButton to JScrollPane

    Hi there,
    Just a quick request to look at this piece of code and see what I might be doing wrong... I'm trying to add a JButton to the bottom left of a JScrollPane using this code...
    private JScrollPane resultsPane;
    private JTextArea resultsArea;
    private JButton saveResultsButton;
    Container container = getContentPane();
    resultsPane = new JScrollPane(resultsArea);
    resultsPane.add(saveResultsButton);
    container.add(topPanel) // this is a JPanel containing 2 other panels...
    container.add(resultsPane, Borderlyout.SOUTH);The problem is that my 'saveResultsButton' is simply not being displayed. Anyone have any idea from this code what my error could be?
    Any help appreciated.

    Hi there,
    Just a quick request to look at this piece of code
    and see what I might be doing wrong... I'm trying to
    add a JButton to the bottom left of a JScrollPane
    using this code...
    private JScrollPane resultsPane;
    private JTextArea resultsArea;
    private JButton saveResultsButton;
    Container container = getContentPane();
    resultsPane = new JScrollPane(resultsArea);
    resultsPane.add(saveResultsButton);The JScrollPane merely adds the up and down scroll bars. You can't really add anything to a scrollbar. You probably don't want to add a JButton to the JTextArea either! Create another JPanel and add(resultsPane) to it then add(saveResultsButton) to it. Then add the JPanel to the container.

  • MS JView  & adding Canvas to Panel

    Hi,
    I want to animate the opening of my Dialogs by a dotted line starting from one edge of the main frame and finally leading to the dialog. I've put the code into the setVisible method of the Dialog. It adds small canvases to the main frame's panel, one by one with a break of 5 ms and after reaching the position of the dialog it shows up the dialog. It works fine on Sun jdks, but it does not show the canvases on MS JView until the dialog is visible. That means, it runs the code, I can hear the ticks, but it does not refresh the frame's panel until the dialog is visible. It doesn't matter if it is a modal dialog or not.
    Has anymone any clue how to make it work on JView?
    Here's the Dialog.setVisible code (just the basics):
    public void setVisible(boolean visible) {
         if (visible) {
              for (int i = 0; i < 20; i++) {
                   Panel dot = new Panel();
                   dot.setBackground(Color.black);
                   dot.setBounds(20 * i, 20 * i, 2, 2);
                   frame.getPanel().add(dot, 0); // frame is a reference to my main frame
                   try {
                        Thread.sleep(5);
                   } catch (InterruptedException ex) { }
              super.setVisible(visible);
    }Thanks
    Mani

    Hi Noah,
    I tried almost everything I can imagine before posting here. I'm going mad about that. It seems that jview doesn't want to add the component until the dispatcher thread gets unblocked again. Here's what I tried:
    dot.getPeer().show();
    frame.dispatchEvent(new ContainerEvent(this, ContainerEvent.ComponentAdded, ...));and many more things. Finally, I created a new Thread inside of the set visible method, which created the dots and called super.setVisible(). That works, but if you need a modal dialog like for example a message box for confirmation, it won't wait for the response (since it is a new thread). So, that can't be my solution.
    By the way, you can try the applet under http://www.jq-consulting.de/pages/psm.html
    Thanks, but no Duke Dollars, unfortunately.
    Mani

  • Adding JScrollPane to JInternalFrame

    Hello, I have been having a rather difficult time adding a a jscrollpane to my jinternalframe. I have a panel that I am adding some objects to. I add that panel to a jscrollpane, then add the jscrollpane to the container of the JInternalFrame. I get no errors, but when I run this thing, the panel spills out over the JInternalFrame, the panel is bigger than the internal frame. When I take the jscrollpane off of it and just add the panel directly to the JInternalFrame, it fits jsut fine. However, I need the scrollbar to view all of the material. Any ideas? Here is a piece of my code.
             JInternalFrame internal = new JInternalFrame("New Tree",true,true,true,true);
          Container c = internal.getContentPane();
    //this panel is something I created earlier and have added stuff to it
    //panel is of the type java.awt.panel
            panel.setBackground(Color.white);
            JScrollPane jsp = new JScrollPane();
            jsp.setViewportView(panel);
            c.add(jsp);
            internal.setSize(700,400);
            internal.setOpaque(true);
            internal.setVisible(true);
    //I add it to a desktop pane a little later on

    Here's an example:
    import java.awt.*;
    import javax.swing.*;
    public class InternalFrameTest extends JFrame {
         private JInternalFrame internalFrame1;
         private JInternalFrame internalFrame2;
         private JScrollPane scrollPane;
         private JDesktopPane desktopPane;
         public InternalFrameTest() {
              try {
                   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                   desktopPane = new JDesktopPane();
                   scrollPane = new JScrollPane(desktopPane);
                   desktopPane.setPreferredSize(new Dimension(350, 250));
                   internalFrame1 = new JInternalFrame();
                   desktopPane.add(internalFrame1);
                   internalFrame1.setBounds(30, 30, 100, 100);
                   internalFrame1.setVisible(true);
                   internalFrame2 = new JInternalFrame();
                   desktopPane.add(internalFrame2);
                   internalFrame2.setBounds(150, 100, 100, 100);
                   internalFrame2.setVisible(true);
                   getContentPane().add(scrollPane, BorderLayout.CENTER);
                   pack();
                   setSize(300, 200);
                   setLocationRelativeTo(null);
                   setVisible(true);
              } catch (Exception e) { e.printStackTrace(); }
         public static void main(String[] args) { new InternalFrameTest(); }
    }

  • How can i  add more than 500 jPanels in a jScrollPane

    Hello to all ,
    I am facing a problem related to adding jPanels in jScrollPane. My application needs more than 500 jpanels in the jscrollpane.where in each jPanel 4 jtextboxes, 1 comboboxes, 1 check box is there.when the check box will be clicked then the total row( ie row means the panel containing the 4 jtextboxes, 1 comboboxes, 1 check box ).and when the user will click on move up or move down button then the selected jpanel will move up or down.
    The tool(sun java studio enterprise 8.1) is not allowing more Jpanels to add manually. so i have to add the jpanels by writing the code in to a loop. and the problem is that when i am trying to add the code in the code generated by the tool the code written out side the code by me is not integratable into the tool generated code.
    If u watch the code here am sending u ll get what am facing the problem. The idea of creating jpanels through loop is ok but when trying to impleent in tool facing difficulties.
    A example code am sending here. please tell me how i can add more panels to the scrollpane(it is the tool generated code)
    Thanks in advance , plz help me for the above
    package looptest;
    public class loopframe extends javax.swing.JFrame {
    /** Creates new form loopframe */
    public loopframe() {
    initComponents();
    private void initComponents() {
    jScrollPane1 = new javax.swing.JScrollPane();
    jPanel1 = new javax.swing.JPanel();
    jPanel2 = new javax.swing.JPanel();
    jTextField1 = new javax.swing.JTextField();
    jComboBox1 = new javax.swing.JComboBox();
    jPanel3 = new javax.swing.JPanel();
    jTextField2 = new javax.swing.JTextField();
    jComboBox2 = new javax.swing.JComboBox();
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jTextField1.setText("jTextField1");
    jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
    org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
    jPanel2.setLayout(jPanel2Layout);
    jPanel2Layout.setHorizontalGroup(
    jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel2Layout.createSequentialGroup()
    .add(28, 28, 28)
    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 109, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(54, 54, 54)
    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(35, Short.MAX_VALUE))
    jPanel2Layout.setVerticalGroup(
    jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel2Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addContainerGap(21, Short.MAX_VALUE))
    jTextField2.setText("jTextField2");
    jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
    org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
    jPanel3.setLayout(jPanel3Layout);
    jPanel3Layout.setHorizontalGroup(
    jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel3Layout.createSequentialGroup()
    .add(20, 20, 20)
    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 111, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(33, 33, 33)
    .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 168, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(40, Short.MAX_VALUE))
    jPanel3Layout.setVerticalGroup(
    jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel3Layout.createSequentialGroup()
    .add(21, 21, 21)
    .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    .add(jComboBox2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addContainerGap(21, Short.MAX_VALUE))
    org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
    jPanel1.setLayout(jPanel1Layout);
    jPanel1Layout.setHorizontalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel1Layout.createSequentialGroup()
    .addContainerGap()
    .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    .addContainerGap(58, Short.MAX_VALUE))
    jPanel1Layout.setVerticalGroup(
    jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(jPanel1Layout.createSequentialGroup()
    .add(21, 21, 21)
    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .add(49, 49, 49)
    .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(66, Short.MAX_VALUE))
    jScrollPane1.setViewportView(jPanel1);
    org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .add(31, 31, 31)
    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 439, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(74, Short.MAX_VALUE))
    layout.setVerticalGroup(
    layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    .add(layout.createSequentialGroup()
    .add(30, 30, 30)
    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 254, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    .addContainerGap(55, Short.MAX_VALUE))
    pack();
    }// </editor-fold>
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new loopframe().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JTextField jTextField2;
    // End of variables declaration
    and
    package looptest;
    public class Main {
    public Main() {
    public static void main(String[] args) {
    new loopframe().setVisible(true);
    }

    Thanks for here kind attention to solve my problem.
    I am thinking to create the classes separately for the components (i.e the jpanel, combobox,textbox etc)and call their instaces from the for loop .But the problem is the jpanel will contain the other components and that jpanels (unlimited jpanels will be added later)will be later added to the jscrollpane.
    By writing code, the problem is to place components( the comboboxes,textboxes etc placed on the jpanel ) in appropriate coordinates . So i am doing it through tool .
    I am sending here the sample code related to my actual need . In this i have taken a jScrollPane, on that i have added jPanel1 and on jPanel1 i have added jPanel2.On jPanel2 jTextField1, jComboBox1,jCheckBox are added. If the u ll see the code u can understand what problem i am facing.
    If i am still not clearly explained ,please ask me. plz help me if u can as u have already handled a problem similar to this.
    package addpanels;
    public class Main {
    /** Creates a new instance of Main */
        public Main() {
        public static void main(String[] args) {
            new addpanels().setVisible(true);
    } and
    package addpanels;
    public class addpanels extends javax.swing.JFrame {
        /** Creates new form addpanels */
        public addpanels() {
            initComponents();
        private void initComponents() {
            jScrollPane1 = new javax.swing.JScrollPane();
            jPanel1 = new javax.swing.JPanel();
            jPanel2 = new javax.swing.JPanel();
            jTextField1 = new javax.swing.JTextField();
            jComboBox1 = new javax.swing.JComboBox();
            jCheckBox1 = new javax.swing.JCheckBox();
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            jTextField1.setText("jTextField1");
            jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
            jCheckBox1.setText("jCheckBox1");
            jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
            jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));
            org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 131, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 144, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                    .add(jCheckBox1)
                    .addContainerGap(39, Short.MAX_VALUE))
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addContainerGap(17, Short.MAX_VALUE)
                    .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                        .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jComboBox1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(jCheckBox1))
                    .addContainerGap())
            org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
            jPanel1.setLayout(jPanel1Layout);
            jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .addContainerGap()
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(34, Short.MAX_VALUE))
            jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(jPanel1Layout.createSequentialGroup()
                    .add(26, 26, 26)
                    .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(152, Short.MAX_VALUE))
            jScrollPane1.setViewportView(jPanel1);
            org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
                    .addContainerGap(36, Short.MAX_VALUE)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 449, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(18, 18, 18))
            layout.setVerticalGroup(
                layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                .add(layout.createSequentialGroup()
                    .add(32, 32, 32)
                    .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 230, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(38, Short.MAX_VALUE))
            pack();
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new addpanels().setVisible(true);
        // Variables declaration - do not modify//GEN-BEGIN:variables
        private javax.swing.JCheckBox jCheckBox1;
        private javax.swing.JComboBox jComboBox1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JPanel jPanel2;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTextField jTextField1;
        // End of variables declaration//GEN-END:variables
    }

  • Canvas content is not visible

    Hi,
    I am adding canvas to a custom actionscript component which extends UIComponent.
    The canvas is created but it is not visible.The depth of the canvas is also shown.How to get it visible.
    Any help is appreciated.
    Thanks
    Srinivas

    Canvas problem is in RUNTIME. Not development.
    Frame prop has been changed to "Manually".
    Thanks,
    nicholas

  • How to create a single action for adding a border and signature for portrait AND landscape images???

    i would love to be able to create a single photoshop action for adding a border, plus a signature in the bottom right corner, that works for both portrait and landscape images.
    need i say more?!
    i already have an action that adds a signature in the centre of the border at the bottom of the image e.g. the image below. what i want though is for that signature to be on the RHS and for the same action to work for portrait images as well.
    supplementary info: reason for this is that I want to be able to export 300 wedding images (mix of landscape and portrait images) from lightroom in my pre-selected order (meaning the files are labelled from 001 to 300, ordered according to how the wedding day unfolded) and then use PS to add the border and the signature, in the same place, and for it to work for both orientations.
    i need this to work for full sized exported jpeg images, i.e. i want the files that i give on CD to my clients to include my signature in this manner. so I don't want to copy the initial layer and then reduce the second layer size to leave a border around the second layer.
    i hope i've been clear and that someone can help me here. I think that this sort of presentation makes such a difference to final printed image, and I DONT want to have to go to all 300 images picking out the landscape from portrait ones (although this may be what I have to do and wouldn't really take that long but surely there's a better way!!!!).
    Thanks in advance photoshoppers ...

    It is actually quite easy to do if you have a good understanding of how Photoshop works.  To be able to handle any size Landscape and Portrait you need to scale the document to a known width or height.  Once the document is resized to the width or height it easy.  When yot resize the document you use Image size with resample NOT checked.  Not a single image pixels is changed all the happens is the documents DPI is set to the proper DPI resolution to print that size.  This lets you add a border sized for and document.  You can use Canvas Size check relative and  leatve the anchor point centered and set width and height to 2" this will add 1"on all sides. Use Canvas size a second time move the anchor point to the top center check relative and set height 1" the will add an additional 1" border on the bottom.  You then record a text layer with your Name title or what ever to the top left of the image. Select all ant the align the text layer to the selection to move it to the bottom right.
    Adding a couple of scripts to the action you can make sure there is a background layer so the added canvas will be filled with pixels.  You can restore the document to its original DPI resolution to retain the images print size. Down load my crafting actions package it contains a dozen scripts to be used within actions. There are text file with tips and guidelines additionaly there is one on dealing with document size and includes a sample action set with a watermarking action the can watermark and size image. The Action set is also saved as a text file with additional comments I added my downloads can be found here http://mouseprints.net/Photoshop.html

  • Help with JScrollPane

    I have a JScrollPane that I need to add multiple components to. That includes 5 JButtons, and 5 Jtree's.
    I need to add all of the components at once, making the JTree's visible and invisible by clicking the JButton's. My first problem is when I try to add multiple objects to the JScrollPane using the default layout manager. The last object added is always stretched to fill the entire viewport. This makes the objects first added un-viewable. So I decided to first add all of the objects to a Box then add the Box to the scrollpane.
    My second problem occurs when I make a JTree visible, aftering adding it to the Box. It draws the tree completely from top to bottom as it should, but clips the right end of titles on the nodes. The horizontal scroll adjusts enought so that you can scroll far enough to the right, but the titles are cut off.
    If I add one of the JTree's directly to the JScrollPane it behaves as it should, showing the complete node titles.
    I've tried revalidating, updating, and repainting without success.
    So, first question is can multiple objects be added to a JScrollPane using the default layout manager, without having the last object hide the previously added objects?
    Secondly, does anyone know why nodes in a JTree would be clipped when added to a Box then added the Box added to a JScrollPane. And more importantly how to fix it.
    Any help would be appreciated,
    Thanks,
    Jim

    Hi there
    Im not sure on exactly what you are trying to do.
    But if you want multiple components in one JScrollPane
    I would use a JPanel that I would add to the JScrollPane
    On that JPanel I would then add my components.
    I would also use GridBagLayout instead of any other layout manager. Thats because it is the most complex
    layout manager and it will arrange the components as I whant.
    If you whant to be able to remove a component from the view by making them invisible. I think I would consider
    JLayeredPane.
    on a JLayeredPane you add components on different layers. Each component is positionend exactly with setLocation or setBounds. This is the most exact thing to use. The JLayeredPane uses exact positioning of its components. which can be usefull when you use
    several components that will be visible at different times
    /Markus

  • Keep vertical scroll bar still y JScrollPane

    Hello all!
    I have got a JTable added into a JScrollPane, which scroll bars are always shown.
    I have to repaint the JTable each 3 seconds and I would like to keep the vertical scroll bar in its original position, for example if I am watching row 24 of the JTable when the JTable is repainted I would like the vertical scroll bar to be in the same position as it was before repainting because now the vertical scroll bar is repainted always at the top...
    With the horizontal bar it works, the bar does not move from its previous state when the JTable is repainted...
    Any idea of what is happening?
    Thanks in advance :)

    This would do for u! ... do it after you have updated the table with the new rows... if you are not using the default table model then you can still get the row count through your JTable object ...
    This part moves the scrollbar to the last row coz im doing "myDefaultTableModel.getRowCount()-1", you can keep the current row index in an instance level variable bjust before refreshing the table and use it in this.setRowSelectionInterval() method ...
    this.setRowSelectionInterval(myDefaultTableModel.getRowCount()-1, myDefaultTableModel.getRowCount()-1);
    this.setColumnSelectionInterval(1, 1); //didnt need any specific column coz I wanted the row basically..
    this.scrollRectToVisible(this.getCellRect(this.getSelectedRow(), 1, true));This basically selects the given row and then moved the scrollbar over to that point as well ...
    OR, here's another alternative!! you can also get the current scrollbar value similarly jsut before refreshing and pass that on to this method ...
    this.jScrollPane1.getVerticalScrollBar().setValue(jScrollPane1.getVerticalScrollBar().getValue());Hope it helps...
    Cheers!
    Asim

Maybe you are looking for

  • Can EJB and BC exist at the same time in one project?

    having to use ADF's BC and EJB to access data in both way due to the special requirements, but I am always getting the deployment failure. can Ejbs and BC components exist at the same time in one project?

  • CREATION OF SET FOR PURCHASE ORDER NUMBER

    Dear Sirs, I want to create a basic set containing all purchase order number, even though i am using table MSEG and field EBELN, i am not getting and values in it. how to create a basic set containing all the available PO numbers, which can be used i

  • Pavilion dv6 3104sl

    I tried to press F11 to restore the machine but the screen remains black ( not boot recovery manager ) .I tried also turning off and on the PC and putting a DVD with win 7 machine ignores the DVd and boots from the hard drive . I can't get into the b

  • Orders05 idoc mapping

    Hi, Please help me where to map below fields in orders05 idoc. 1) shipping terms 2) shipping via. 3) NSP Quote Number ( discount ) Thanks, Raghu.

  • Transfer OCI CUST_FIELDS into SC with BADI BBP_CATALOG_TRANSFER

    Hello guys, we want to transfer a 1 CHAR value that comes from the catalog (CCM 200)in OCI field CUST_FIELD1 into to the shopping cart. Are there any fields in the shopping cart item tables, that we can use. I cannot find any. I think field "DUMMY_EE