Multiple JScrollPanes in a singe JFrame

Hi
I want both JPanels to scroll. Pretty simple code, just add 9 buttons to two JPanels, out the JPanels in JScrollPanes and put the JScrollPanes in the JFrame. I've tried resizing the JFrame and setSize for the Panels/ScrollPanes but I can only get the top (doesn't matter which panel is added first) of the JFrame to show the scroll bar. The bottom Panel doesn't show the scroll bar.
import java.io.*;
import java.util.*;
import javax.swing.*;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.*;
import javax.swing.event.*;
import java.awt.*;
import java.awt.event.*;
import java.util.StringTokenizer;
import java.lang.*;
public class testSP   {
   public static void main(String args[]) {
      JFrame j = new JFrame();
      JPanel jjj = new JPanel();
    //jjj.setSize(new Dimension(600,600));
      jjj.setLayout(new GridLayout(0,1));
      JButton b0 = new JButton("0");
      JButton b1 = new JButton("1");
      JButton b2 = new JButton("2");
      JButton b3 = new JButton("3");
      JButton b4 = new JButton("4");
      JButton b5 = new JButton("5");
      JButton b6 = new JButton("6");
      JButton b7 = new JButton("7");
      JButton b8 = new JButton("8");
      b0.setSize(new Dimension(100,100));
      b1.setSize(new Dimension(100,100));
      b2.setSize(new Dimension(100,100));
      b3.setSize(new Dimension(100,100));
      b4.setSize(new Dimension(100,100));
      b5.setSize(new Dimension(100,100));
      b6.setSize(new Dimension(100,100));
      b7.setSize(new Dimension(100,100));
      b8.setSize(new Dimension(100,100));
      jjj.add(b0);
      jjj.add(b1);
      jjj.add(b2);
      jjj.add(b3);
      jjj.add(b4);
      jjj.add(b5);
      jjj.add(b6);
      jjj.add(b7);
      jjj.add(b8);
      JScrollPane jjjSP = new JScrollPane(jjj);
     //jjjSP.setSize(new Dimension(600,600));
      JPanel kkk = new JPanel();
    //kkk.setSize(new Dimension(600,600));
      kkk.setLayout(new GridLayout(0,1));
      JButton k0 = new JButton("0");
      JButton k1 = new JButton("1");
      JButton k2 = new JButton("2");
      JButton k3 = new JButton("3");
      JButton k4 = new JButton("4");
      JButton k5 = new JButton("5");
      JButton k6 = new JButton("6");
      JButton k7 = new JButton("7");
      JButton k8 = new JButton("8");
      k0.setSize(new Dimension(100,100));
      k1.setSize(new Dimension(100,100));
      k2.setSize(new Dimension(100,100));
      k3.setSize(new Dimension(100,100));
      k4.setSize(new Dimension(100,100));
      k5.setSize(new Dimension(100,100));
      k6.setSize(new Dimension(100,100));
      k7.setSize(new Dimension(100,100));
      k8.setSize(new Dimension(100,100));
      kkk.add(k0);
      kkk.add(k1);
      kkk.add(k2);
      kkk.add(k3);
      kkk.add(k4);
      kkk.add(k5);
      kkk.add(k6);
      kkk.add(k7);
      kkk.add(k8);
      JScrollPane kkkSP = new JScrollPane(kkk);
    //kkkSP.setSize(new Dimension(600,600));
      j.getContentPane().add(kkkSP, BorderLayout.SOUTH);
      j.getContentPane().add(jjjSP, BorderLayout.CENTER);
      j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      j.setSize(275,395);
      j.setVisible(true);
}

import javax.swing.*;
import java.awt.*;
class testSP
   public static void main(String args[])
      JFrame j = new JFrame();
      JPanel jjj = new JPanel(new GridLayout(0,1));
      JPanel kkk = new JPanel(new GridLayout(0,1));
      JButton[] btn = new JButton[20];
      for(int x = 0; x < btn.length; x++)
        btn[x] = new JButton(""+(x+1));
        btn[x].setSize(new Dimension(100,100));
        if(x < 10)jjj.add(btn[x]);
        else kkk.add(btn[x]);
      JScrollPane jjjSP = new JScrollPane(jjj);
      jjjSP.setPreferredSize(new Dimension(300,200));//<--------------
      JScrollPane kkkSP = new JScrollPane(kkk);
      kkkSP.setPreferredSize(new Dimension(300,200));//<-----------
      j.getContentPane().add(kkkSP, BorderLayout.SOUTH);
      j.getContentPane().add(jjjSP, BorderLayout.CENTER);
      j.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      j.pack();
      j.setVisible(true);
}

Similar Messages

  • Multiple Layouts in a single JFrame

    Hi,
    Is it possible to have multiple layouts in a single JFrame ? What I need to do is that I need to have following components in a SINGLE content pane of a JFrame:-
    A) 2 Labels
    B) 1 Button
    C) 1 4x4 Grid of buttons
    Now implement (C) I need to use GridLayout for nide grid like looks like
    mContentPane.setLayout(new GridLayout(4,4));
    But (A) and (B) obviously shouldn't be part of Grid. So I assume I need to use different layout in the same content pane. Any idea how can I accomplish this ?
    Thanks

    import java.awt.*;
    import javax.swing.*;
    class Testing extends JFrame
      public Testing()
        setLocation(400,300);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        JPanel main = new JPanel(new BorderLayout());
        JPanel top = new JPanel(new GridLayout(4,4));
        for(int x = 0; x < 16; x++) top.add(new JButton(""+(x+1)));
        JPanel bottom = new JPanel();
        bottom.add(new JLabel("JLabel 1"));
        bottom.add(new JButton("JButton"));
        bottom.add(new JLabel("JLabel 2"));
        main.add(top,BorderLayout.CENTER);
        main.add(bottom,BorderLayout.SOUTH);
        getContentPane().add(main);
        pack();
      public static void main(String[] args){new Testing().setVisible(true);}
    }

  • Urgent ! How to add multiple JToolBars in a single JFrame

    How to implement multiple JToolBars in a single JFrame
    or what is the concept behind floating toolBars.If anybody can help me ,Thisis very urgent

    If you insist on multiple toolbars, use the following code:
    JToolBar tb1 = new JToolBar();
    //add stuff
    JToolBar tb2 = new JToolBar();
    //add stuff
    //put the toolbars on the top of the window
    JPanel toolbars = new JPanel(new BorderLayout());
    toolbars.add(tb1, BorderLayout.NORTH);
    toolbars.add(tb2, BorderLayout.CENTER);
    getContentPane().add(toolbars, BorderLayout.NORTH);Stephen

  • Multiple JScrollPanes in one window

    Hi.
    I've been trying to figure out how to make multiple scrollable text areas in one window. I'm trying to use JEditorPanes for the text areas so that they can display html. Does anyone know how I can make multiple scrollable JEditorPanes appear side by side in one window? I tried just adding many JScrollPanes to the window, but that doesn't seem to work - it only displays the first one.
    Thanks.

    Just to help since no one's said anything for so long.
    The only way I know how may be to use a JSplitPane and add the components to the splitpane. This allows for resizing but I'm not very sure if it will exactly resize the components in them
    Check the Java Demos in your SDK (Swing Set 2) I believe the demo splitpanes should give you enough go ahead to start using split panes effectlvely
    ICE

  • How do I add multiple JInternalFrames to 1 main JFrame

    It may seem like a silly question but I'd really appreciate any help offered. Sample code might be of assistance.
    Thanks people :-)

    It's very simple. Create a JFrame,
    then create separate classes for each JInternalFrame (here: TFrame, SFrame, GFrame)
    Here's some code:
    public class GWorkBench extends JFrame {
    public GWorkBench() {
    //Set up the GUI.
    desktop = new JDesktopPane(); //a specialized layered pane
    setContentPane(desktop);
    setJMenuBar(createMenuBar());
    protected JMenuBar createMenuBar() {
    JMenuBar menuBar = new JMenuBar();
    JMenu menu = new JMenu("Modules");
    menu.setMnemonic(KeyEvent.VK_D);
    JMenuItem menuItem1 = new JMenuItem("Data Entry");
    JMenuItem menuItem2 = new JMenuItem("Search Module");
    JMenuItem menuItem3 = new JMenuItem("Generation Module");
    menuItem1.setMnemonic(KeyEvent.VK_E);
    menuItem2.setMnemonic(KeyEvent.VK_S);
    menuItem3.setMnemonic(KeyEvent.VK_G);
    menuItem1.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    createTFrame();
    menuItem2.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              createSFrame();
    menuItem2.addActionListener(new ActionListener() {
         public void actionPerformed(ActionEvent e) {
              createGFrame();
    menu.add(menuItem1);
    menu.add(menuItem2);
    menu.add(menuItem3);
    menuBar.add(menu);
    return menuBar;

  • Accessing multiple instance of the same JFrame.

    Hi, I'm hoping someone out there can help. I'm a student desperatly trying to finish my discertation in time, I'm making an RMI chat application, everything works fine except for one thing.
    If a client sends a message to another client and they have one or more conversation windows open at that time, the correct conversation window is not selected to display the message.
    e.g 'Team one' sends a message to 'Team Two', who has windows open for both 'Team One' and 'Team Three'.
    The conversation window is a seperate class and everytime a client creates a new conversation, a new instance of this is created.
    To group all the client windows together I've created an array of client windows and every new instance is added to this array.
    public static ClientWin[] group = new ClientWin[10];
    public void NewWindow(Server serv, String WhoTo, String Name){
        group[count] = new ClientWin(serv, WhoTo, Name);
        count++;
    } This works fine, new conversation windows are created fine but when I try to access something within the array e.g
    group[count].transcript.append(msg); the correct transcript in the corresponding JFrame in the ClientWin array is never selected and infact, every instance within the array appears to correspond with the last JFrame instance when I've looped through the array checking values.
    Any help will be greatly appreciated, this is killing my head. Thank you.
    Matt

    Thanks, I thought that was what I was doing, thats what I intended anyway.
    The ClientWin class is my own class which extends JFrame.
    The ClientWin[] group = new ClientWin[10]; is the arraylist you refer to, at least I wanted it to be.
    And I check group.whoTo currently to see you the window is for and the group array is the arraylist you reffer to.
    However with doing this (prob just a stupid mistake) I can't send a message to the corresponding window in the array and in fact every item in the array is the same as the last window created.
    Thanks

  • Zoom Issues with JScrollPane

    Hello all,
    I have ran into an issue with zoom functionality on a JScrollPane.
    Here is the situation (code to follow):
    I have a JFrame with a JDesktopPane as the contentpane. Then I have a JScrollPane with a JPanel inside. On this JPanel are three rectangles. When they are clicked on, they will open up a JInternalFrame with their name (rect1, rect2, or rect3) as the title bar. Rect3 is positioned (2000,2000).
    I have attached a mousewheel listener to the JPanel so I can zoom in and out.
    I have also attached a mouse listener so I can detect the mouse clicks for the rectangles. I also do a transformation on the point so I can be use it during clicks while the panel is zoomed.
    All of this works fantastic. The only issue I am having is that when the JScrollPane scroll bars change, I cannot select any of the rectangles.
    I will give a step by step reproduction to be used with the code:
    1.) Upon loading you will see two rectangles. Click the far right one. You'll see a window appear. Good. Move it to the far right side.
    2.) Zoom in with your mouse wheel (push it towards you) until you cannot zoom anymore (May have to get focus back on the panel). You should see three rectangles. Click on the newly shown rectangle. Another window, titled rect3 should appear. Close both windows.
    3.) This is where things get alittle tricky. Sometimes it works as intended, other times it doesn't. But do something to this affect: Scroll to the right so that only the third rectangle is showing. Try to click on it. If a window does not appear - that is the problem. But if a window does appear, close it out and try to click on the 3rd rect again. Most times, it will not display another window for me. I have to zoom out one step and back in. Then the window will appear.
    After playing around with it for awhile, I first thought it may be a focus issue...I've put some code in the internal window listeners so the JPanel/JScrollPane can grab the focus upon window closing, but it still does not work. So, either the AffineTransform and/or point conversion could be the problem with the scroll bars? It only happens when the scroll bar has been moved. What affect would this have on the AffineTransform and/or point conversion?
    Any help would be great.
    Here is the code, it consists of two files:
    import java.awt.Color;
    import java.awt.Dimension;
    import javax.swing.BorderFactory;
    import javax.swing.JDesktopPane;
    import javax.swing.JFrame;
    import javax.swing.JScrollPane;
    public class InternalFrameAffineTransformIssue
         public static void main ( String[] args )
              JFrame frame = new JFrame("AffineTransform Scroll Issue");
              frame.setLayout(null);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              JDesktopPane desktop = new JDesktopPane();
              frame.setContentPane(desktop);
              MyJPanel panel = new MyJPanel(frame);
              JScrollPane myScrollPane = new JScrollPane(panel);
              panel.setScrollPane(myScrollPane);
              myScrollPane.setLocation(0, 0);
              myScrollPane.setSize(new Dimension(800, 800));
              myScrollPane.getVerticalScrollBar().setUnitIncrement(50);
              myScrollPane.getHorizontalScrollBar().setUnitIncrement(50);
              myScrollPane.setViewportBorder(BorderFactory.createLineBorder(Color.black));
              frame.getContentPane().add(myScrollPane);
              frame.setBounds(0, 100, 900, 900);
              frame.setVisible(true);
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.Rectangle;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseWheelEvent;
    import java.awt.event.MouseWheelListener;
    import java.awt.geom.AffineTransform;
    import java.awt.geom.NoninvertibleTransformException;
    import java.awt.geom.Point2D;
    import javax.swing.JFrame;
    import javax.swing.JInternalFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.event.InternalFrameAdapter;
    import javax.swing.event.InternalFrameEvent;
    import javax.swing.event.InternalFrameListener;
    public class MyJPanel extends JPanel implements MouseWheelListener
              double zoom = 1;
              Rectangle rect1 = new Rectangle(50, 50, 20, 20);
              Rectangle rect2 = new Rectangle(100, 50, 20, 20);
              Rectangle rect3 = new Rectangle(2000, 2000, 20, 20);
              AffineTransform zoomedAffineTransform;
              JFrame frame;
              JPanel myPanel = this;
              JScrollPane myScrollPane;
              public MyJPanel(JFrame inputFrame)
                   setAutoscrolls(true);
                   addMouseListener(new MouseAdapter(){
                        public void mousePressed ( MouseEvent e )
                             System.out.println("Clicked: " + e.getPoint());
                             AffineTransform affineTransform = zoomedAffineTransform;
                             Point2D transformedPoint = e.getPoint();
                             //Do the transform if it is not null
                             if(affineTransform != null)
                                  try
                                       transformedPoint = affineTransform.inverseTransform(transformedPoint, null);
                                  catch (NoninvertibleTransformException ex)
                                       ex.printStackTrace();
                             System.out.println("Tranformed Point: " + transformedPoint);
                             if(rect1.contains(transformedPoint))
                                  System.out.println("You clicked on rect1.");
                                  createInternalFrame("Rect1");
                             if(rect2.contains(transformedPoint))
                                  System.out.println("You clicked on rect2.");
                                  createInternalFrame("Rect2");
                             if(rect3.contains(transformedPoint))
                                  System.out.println("You clicked on rect3.");
                                  createInternalFrame("Rect3");
                   addMouseWheelListener(this);
                   frame = inputFrame;
                   setPreferredSize(new Dimension(4000, 4000));
                   setLocation(0, 0);
              public void paintComponent ( Graphics g )
                   super.paintComponent(g);
                   Graphics2D g2d = (Graphics2D) g;
                   g2d.scale(zoom, zoom);
                   zoomedAffineTransform = g2d.getTransform();
                   g2d.draw(rect1);
                   g2d.draw(rect2);
                   g2d.draw(rect3);
              public void mouseWheelMoved ( MouseWheelEvent e )
                   System.out.println("Mouse wheel is moving.");
                   if(e.getWheelRotation() == 1)
                        zoom -= 0.05;
                        if(zoom <= 0.20)
                             zoom = 0.20;
                   else if(e.getWheelRotation() == -1)
                        zoom += 0.05;
                        if(zoom >= 1)
                             zoom = 1;
                   repaint();
              public void createInternalFrame ( String name )
                   JInternalFrame internalFrame = new JInternalFrame(name, true, true, true, true);
                   internalFrame.setBounds(10, 10, 300, 300);
                   internalFrame.setVisible(true);
                   internalFrame.addInternalFrameListener(new InternalFrameAdapter(){
                        public void internalFrameClosed ( InternalFrameEvent arg0 )
                             //myPanel.grabFocus();
                             myScrollPane.grabFocus();
                        public void internalFrameClosing ( InternalFrameEvent arg0 )
                             //myPanel.grabFocus();
                             myScrollPane.grabFocus();
                   frame.getContentPane().add(internalFrame, 0);
              public void setScrollPane ( JScrollPane myScrollPane )
                   this.myScrollPane = myScrollPane;
         }

    What I'm noticing is your zoomedAffineTransform is changing when you click to close the internal frame. This ends up being passed down the line, thus mucking up your clicks until you do something to reset it (like zoom in and out).
    Clicking on the JInternalFrame appears to add a translate to the g2d transform. This translation is what's throwing everything off. So in the paintComponent where you set the zoomedAffineTransform, you can verify if the transform has a translation before storing the reference:
             if (g2d.getTransform().getTranslateX() == 0.0) {
                zoomedAffineTransform = g2d.getTransform();
             }Edited by: jboeing on Oct 2, 2009 8:23 AM

  • Table does not fit into JScrollPane...

    Hello,
    I created a JTable and want to put this table into a JScrollPane, because the table is larger than the screen-size. The problem is that I never get the horizontal ScrollBar displayed, and the columns of my table are pressed together.
    Just try yourself, here's a piece of my source code:
    JTable table = new JTable(100,100);
    JScrollPane pane = new JScrollPane(table);
    I tried different constructor-versions of the JScrollPane-object, but the result was always the same: very very small columns and no horizontal ScrollBar.
    Who can tell me how to do so...? I'd be very pleased about any kind of
    advision because this problem really drives me crazy...
    Thanx, Findus

    Hi,
    The reason that the horizontal scrollbar is not appearing is because you have the columns as resizeable. By default the column are automatically resizeable. You have to switch off the resizing.
    The code should be something like this (an example)
    import javax.swing.JFrame;
    import javax.swing.JTable;
    import javax.swing.JScrollPane;
    public class MyFrame extends JFrame {
    private JTable table = null;
    public MyFrame() {
    try{
    GUI();
    catch(Exception ex) {
    ex.printStackTrace();
    private void GUI() throws Exception {
    table = new JTable(100, 100);
    table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    this.getContentPane().add(new JScrollPane(table);
    this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.setSize(400, 400);
    this.setVisible(true);
    public static void main(String[] args) {
    MyFrame app = new MyFrame();
    I hope this helps

  • Redisplaying jFrame with updated components

    I have an object A that instantiates object B.
    My object name is B_Object.
    I call B_Object.setVisible(true);
    (This is basically a jframe with jpanel with empty jScrollPane)
    Later on, I call B_Object.redisplay() which I want to add components into my jScrollPane and redisplay the jFrame with the new information in the jScrollPane. However, it doesn't display everything in my jScrollPane. It looks like it wants to, but doesn't.
    Is this a thread problem? Or I can't just recreate a jFrame that I already have it visible?

    When you add or remove a component from a Container, then you need to revalidate() the container so the Layout Manager can be invoked.

  • Zooming a plot in a JScrollPane

    Hi,
    I am stuck! I'd appreciate it if you can get me unstuck ...
    Below a trimmed-down .java file with a "main" that shows my problem. I create a JFrame. In the contentPane of this JFrame I put a JScrollPane, and in that JScrollPane I put a JPanel. I then show() the JFrame and set the preferredSize of the JPanel equal to it's actual getSize(). This way the scrollbars are just not required. If the user makes the JFrame a little bit smaller with the mouse, then the scrollbars appear. Try it!
    In the JPanel I plot an artificial profile in a white rectangle, i.e. a simple cross-plot. To convert from userspace to physical space I use a combination of 4 affineTransforms, all according to 'the book'. All works lovely.
    Now I want to zoom by dragging a box in the plot. Note that I already have the code that shows the zoom-box! Once I let go of the mouse (mouseReleased) I want to zoom on that box, and that's where it goes wrong. With some jickerypoke I can actually do the zoom (not in the code below), but ... the scrollBars do not appear, and the whole idea of course if that they do appear, so that the user can scroll up/down sideways without having to change the scaling.
    ( In essence the question is this: if I plot outside of the (user) min/max (for instance change the line "line.lineTo((float)x, (float)y[i]);" to "line.lineTo((float)x[i], (float)(y[i]+500));"), why does the JScrollPane not decide to pop-up the scrollBars so that the user can scroll to the bit outside of the (user) min/max? )
    I'd be grateful for some pointers as to how to fix this, as I am going around in circles.
    Cheers - Michel - London
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class PanelModelTest2 extends JPanel implements MouseListener, MouseMotionListener {
    //Constants
    private final double MARGIN_TOP = 50.0;
    private final double MARGIN_BOTTOM = 10.0;
    private final double MARGIN_LEFT = 50.0;
    private final double MARGIN_RIGHT = 10.0;
    //Private parts
    private Model model_;
    private Point2D mouseDownPosition_ = null;
    private Point2D mouseDragPosition_ = null;
    private boolean flMouseInPanel_;
    private AffineTransform affineTransform_;
    public PanelModelTest2(Model model) {
    model_ = model;
    addMouseListener(this);
    addMouseMotionListener(this);
    public void paintComponent(Graphics g) {
    //Always call this method on the parents first. (Why???)
    super.paintComponent(g);
    //Cast g onto g2d to expose the extra methods!
    Graphics2D g2d = (Graphics2D)g;
    //Determine the userspace
    double xMin = model_.getXMin();
    double xMax = model_.getXMax();
    double xRng = xMax - xMin;
    double yMin = model_.getYMin();
    double yMax = model_.getYMax();
    double yRng = yMax - yMin;
    //Determine the physical space (width and height is all you need)
    Dimension panelDimension = getSize();
    double xRngPhy = panelDimension.getWidth();
    double yRngPhy = panelDimension.getHeight();
    //Instantiate the affineTransform_, then compose in reverse order!
    affineTransform_ = new AffineTransform(); //Default: the Identity transform
    //==>Step 4: Move axes "Margin' away from the origin
    affineTransform_.translate(MARGIN_LEFT, MARGIN_TOP);
    //==>Step 3: Map from panelspace to axesspace
    affineTransform_.scale((xRngPhy - MARGIN_LEFT - MARGIN_RIGHT)/xRngPhy, (yRngPhy - MARGIN_TOP - MARGIN_BOTTOM)/yRngPhy);
    //==>Step 2: Map from userspace to panelspace
    affineTransform_.scale(xRngPhy/xRng, yRngPhy/yRng);
    //==>Step 1: Map (xMin,yMin) onto (0,0)
    affineTransform_.translate(-xMin, -yMin);
    //1. Make, then draw the axes rectangle
    Rectangle2D whiteAxes = new Rectangle2D.Double(xMin, yMin, xRng, yRng);
    g2d.setColor(Color.WHITE);
    g2d.fill(affineTransform_.createTransformedShape(whiteAxes));
    g2d.setColor(Color.BLACK); //Reset color to black!
    //2. Plot the axes
    //Still outstanding!!
    //3. Get, then plot the data
    double[] y = model_.getY();
    double[] x = model_.getX();
    GeneralPath line = new GeneralPath();
    for (int i=0; i<y.length; i++) {
    if (i==0) line.moveTo((float)x[i], (float)y[i]);
    line.lineTo((float)x[i], (float)y[i]);
    g2d.clip(affineTransform_.createTransformedShape(whiteAxes));
    g2d.draw(affineTransform_.createTransformedShape(line));
    //Zoom box
    if (flMouseInPanel_) {
    if (mouseDownPosition_ != null) {
    Rectangle2D zoomBox = new Rectangle2D.Double(mouseDownPosition_.getX(), mouseDownPosition_.getY(), mouseDragPosition_.getX() - mouseDownPosition_.getX(), mouseDragPosition_.getY() - mouseDownPosition_.getY());
    g2d.draw(zoomBox);
    public void mouseEntered(MouseEvent evt) {
    flMouseInPanel_ = true;
    public void mouseExited(MouseEvent evt) {
    flMouseInPanel_ = false;
    public void mouseMoved(MouseEvent evt) {
    public void mouseReleased(MouseEvent evt) {
    //Here code to zoom!!!???
    mouseDownPosition_ = null; //This ensures that the
    mouseDragPosition_ = null; //zoombox is no longer plotted!
    repaint();
    public void mousePressed(MouseEvent evt) {
    mouseDownPosition_ = evt.getPoint();
    public void mouseClicked(MouseEvent evt) {
    public void mouseDragged(MouseEvent evt) {
    mouseDragPosition_ = evt.getPoint();
    repaint();
    public static void main(String[] args) {
    Model model = new Model();
    MainJFrame mainJFrame = new MainJFrame(model);
    class Model {
    //Private parts ...
    private double yMin_;
    private double yMax_;
    private double xMin_;
    private double xMax_;
    private double[] y_ = new double[20];
    private double[] x_ = new double[20];
    public Model() {
    //Make fake profile
    for (int i=0; i<20; i++) {
    y_[i]=50*i+1300;
    x_[i]=Math.sin(i/3);
    //Set corresponding mins and maxs
    xMin_ = -1;
    xMax_ = 1;
    yMin_ = 1300;
    yMax_ = 2300;
    public double getXMin() {return xMin_;}
    public double getXMax() {return xMax_;}
    public double getYMin() {return yMin_;}
    public double getYMax() {return yMax_;}
    public double[] getX() {return x_;}
    public double[] getY() {return y_;}
    class MainJFrame extends JFrame {
    //Constants
    public final static int WINDOWS_START_BAR_HEIGHT = 28;
    //Private parts ...
    private Model model_;
    private PanelModelTest2 pnlModel_;
    public MainJFrame(Model model) {
    //Set the private parts associated with the input arguments ...
    model_ = model;
    //Deal with using clicking the 'x' in the top right corner
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {dispose(); System.exit(0);}
    //Panel goes 'in' JScrollPane, which goes 'in' JFrame's contentPane
    pnlModel_ = new PanelModelTest2(model_);
    JScrollPane scroller = new JScrollPane(pnlModel_);
    getContentPane().add(scroller, BorderLayout.CENTER);
    //Pack, set to full screen, show and set preferredSize of panel to it's getSize
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    pack();
    setBounds(0, 0, (int)screenSize.getWidth(), (int)screenSize.getHeight() - WINDOWS_START_BAR_HEIGHT);
    show();
    pnlModel_.setPreferredSize(pnlModel_.getSize()); //Now, if you make window wee bit
    } //smaller, scrollbars appear
    public PanelModelTest2 getPnlModel() {return pnlModel_;}

    Oops, I forgot the tags. Here it is again ...
    import java.awt.*;
    import java.awt.geom.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class PanelModelTest2 extends JPanel implements MouseListener, MouseMotionListener {
        //Constants
        private final double MARGIN_TOP = 50.0;
        private final double MARGIN_BOTTOM = 10.0;
        private final double MARGIN_LEFT = 50.0;
        private final double MARGIN_RIGHT = 10.0;
        //Private parts
        private Model model_;
        private Point2D mouseDownPosition_ = null;
        private Point2D mouseDragPosition_ = null;
        private boolean flMouseInPanel_;
        private AffineTransform affineTransform_;
        public PanelModelTest2(Model model) {
            model_ = model;
            addMouseListener(this);
            addMouseMotionListener(this);
        public void paintComponent(Graphics g) {
            //Always call this method on the parents first. (Why???)
            super.paintComponent(g);
            //Cast g onto g2d to expose the extra methods!
            Graphics2D g2d = (Graphics2D)g;
            //Determine the userspace
            double xMin = model_.getXMin();
            double xMax = model_.getXMax();
            double xRng = xMax - xMin;
            double yMin = model_.getYMin();
            double yMax = model_.getYMax();
            double yRng = yMax - yMin;
            //Determine the physical space (width and height is all you need)
            Dimension panelDimension = getSize();
            double xRngPhy = panelDimension.getWidth();
            double yRngPhy = panelDimension.getHeight();
            //Instantiate the affineTransform_, then compose in reverse order!
            affineTransform_ = new AffineTransform(); //Default: the Identity transform
            //==>Step 4: Move axes "Margin' away from the origin
            affineTransform_.translate(MARGIN_LEFT, MARGIN_TOP);
            //==>Step 3: Map from panelspace to axesspace
            affineTransform_.scale((xRngPhy - MARGIN_LEFT - MARGIN_RIGHT)/xRngPhy, (yRngPhy - MARGIN_TOP - MARGIN_BOTTOM)/yRngPhy);
            //==>Step 2: Map from userspace to panelspace
            affineTransform_.scale(xRngPhy/xRng, yRngPhy/yRng);
            //==>Step 1: Map (xMin,yMin) onto (0,0)
            affineTransform_.translate(-xMin, -yMin);
            //1. Make, then draw the axes rectangle     
            Rectangle2D whiteAxes = new Rectangle2D.Double(xMin, yMin, xRng, yRng);
            g2d.setColor(Color.WHITE);
            g2d.fill(affineTransform_.createTransformedShape(whiteAxes));
            g2d.setColor(Color.BLACK); //Reset color to black!
            //2. Plot the axes
            //Still outstanding!!
            //3. Get, then plot the data
            double[] y = model_.getY();
            double[] x = model_.getX();
            GeneralPath line = new GeneralPath();
            for (int i=0; i<y.length; i++) {
                if (i==0) line.moveTo((float)x, (float)y[i]);
    line.lineTo((float)x[i], (float)y[i]);
    g2d.clip(affineTransform_.createTransformedShape(whiteAxes));
    g2d.draw(affineTransform_.createTransformedShape(line));
    //Zoom box
    if (flMouseInPanel_) {
    if (mouseDownPosition_ != null) {
    Rectangle2D zoomBox = new Rectangle2D.Double(mouseDownPosition_.getX(), mouseDownPosition_.getY(), mouseDragPosition_.getX() - mouseDownPosition_.getX(), mouseDragPosition_.getY() - mouseDownPosition_.getY());
    g2d.draw(zoomBox);
    public void mouseEntered(MouseEvent evt) {
    flMouseInPanel_ = true;
    public void mouseExited(MouseEvent evt) {
    flMouseInPanel_ = false;
    public void mouseMoved(MouseEvent evt) {
    public void mouseReleased(MouseEvent evt) {
    //Here code to zoom!!!???
    mouseDownPosition_ = null; //This ensures that the
    mouseDragPosition_ = null; //zoombox is no longer plotted!
    repaint();
    public void mousePressed(MouseEvent evt) {
    mouseDownPosition_ = evt.getPoint();
    public void mouseClicked(MouseEvent evt) {
    public void mouseDragged(MouseEvent evt) {
    mouseDragPosition_ = evt.getPoint();
    repaint();
    public static void main(String[] args) {
    Model model = new Model();
    MainJFrame mainJFrame = new MainJFrame(model);
    class Model {
    //Private parts ...
    private double yMin_;
    private double yMax_;
    private double xMin_;
    private double xMax_;
    private double[] y_ = new double[20];
    private double[] x_ = new double[20];
    public Model() {
    //Make fake profile
    for (int i=0; i<20; i++) {
    y_[i]=50*i+1300;
    x_[i]=Math.sin(i/3);
    //Set corresponding mins and maxs
    xMin_ = -1;
    xMax_ = 1;
    yMin_ = 1300;
    yMax_ = 2300;
    public double getXMin() {return xMin_;}
    public double getXMax() {return xMax_;}
    public double getYMin() {return yMin_;}
    public double getYMax() {return yMax_;}
    public double[] getX() {return x_;}
    public double[] getY() {return y_;}
    class MainJFrame extends JFrame {
    //Constants
    public final static int WINDOWS_START_BAR_HEIGHT = 28;
    //Private parts ...
    private Model model_;
    private PanelModelTest2 pnlModel_;
    public MainJFrame(Model model) {
    //Set the private parts associated with the input arguments ...
    model_ = model;
    //Deal with using clicking the 'x' in the top right corner
    addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {dispose(); System.exit(0);}
    //Panel goes 'in' JScrollPane, which goes 'in' JFrame's contentPane
    pnlModel_ = new PanelModelTest2(model_);
    JScrollPane scroller = new JScrollPane(pnlModel_);
    getContentPane().add(scroller, BorderLayout.CENTER);
    //Pack, set to full screen, show and set preferredSize of panel to it's getSize
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    pack();
    setBounds(0, 0, (int)screenSize.getWidth(), (int)screenSize.getHeight() - WINDOWS_START_BAR_HEIGHT);
    show();
    pnlModel_.setPreferredSize(pnlModel_.getSize()); //Now, if you make window wee bit
    } //smaller, scrollbars appear
    public PanelModelTest2 getPnlModel() {return pnlModel_;}

  • Hi can u please help me out to display multiple [b]thumbnail images[/b]

    hi,
    hi,
    please help me out!
    please help me out!!
    I need to display multiple thumbnail images on the jframe or on a jpanel . From the database where the path of the images are stored
    say i should first get thumbnail of the images and then display
    any one can please give me the code
    Thanx and Regards

    What is the context you're asking these questions in? Are these interview questions? Homework questions? Or is there some underlying business problem you're trying to solve?
    user644700 wrote:
    Create Query to restrict the user to a single row.                     I don't understand the question. You may be trying to create a VPD policy for the table, but that is far from clear from the question.
    Query to get the first inserted record FROM a table.                Probably not possible in general. Oracle doesn't track the date at which a row was inserted.
    Concatenate a column value with multiple rows.                          Again, I don't understand the question.
    Query to delete all the tables at once.                You'd need dynamic SQL. And a definition of "all tables"-- are you talking about all tables in a particular schema? All the tables in multiple schemas? Something else? Does "at once" imply that you want things to run in parallel? And does "delete" really mean delete (a DML operation)? truncate (a DDL operation)? or drop?
    SQL Query for getting Orphan Records.You'd need a definition of "orphan record" and requirements for what the parent and child tables are. The normal approach to finding parent and child tables dynamically would leverage foreign key constraints, but that would generally preclude the presence of orphan records.
    Justin

  • Deleting multiple records using ibatis framework

    The code i am using is
    String deleteArray[ ] = request.getParameterValues("sel");
    String selected= " " ;
    if(deleteArray ! = null){
    for(int i = 0; i < deleteArray.length ; i++){
    selected += deleteArray [ i ];
    if( i < deleteArray.length - 1){
    selected += "," ;
    I am using sqlMapClient of ibatis for connecting to database
    sqlMapClient.delete("deleteMultipleRecords",selected);
    In my xml file i use
    <delete id="deleteMultipleRecords" parameterClass="java.lang.String">
    delete from ADDRESS where id in (#value#)
    </delete>
    When i execute the above code , the delete query is not executing.Can anyone help me out.

    I dont think so u can delete multiple recods with a sing line of querey.
    Why dont u use a for loop in DAO file and call the query with a single value ....

  • Multiple AD account in single domain for a single user

    Hi,
    Does OIM support multiple AD account in single domain for a single user?
    Scenario 1 :- If the multiple accounts already exists in AD can I pull it from AD to OIM for single user.
    Scenraio 2:- Does OIM allow creation of multiple account in AD for a single user, when requested from OIM?
    Thanks,

    yes. this is possible. OIM allow this.
    obviously the recon rule would be employee number or anything other than ' sAmAccontName' for target recon
    while provisioning make sure you are generating unique sAmAccountName and Common Name(if in same OU) for same user
    If you maintain above no issue having multiple account for a sing user in single domain

  • Filling out available space in JScrollPane

    Hello all,
    Is there a way to inform a JScrollPane that it's viewport's component should fill out the entire area of the viewport? I have a scroll pane whose viewport is a JPanel with a BoxLayout. The contents of the JPanel will change size depending on certain events. However, the JPanel at first is not very wide (it's components have a preferred size of 100), so it does not fill out the width of the viewport and is also displayed in the center of the scroll pane. Is there a way to have the JPanel fill out the entire viewport, or at least have it displayed on the left (I have set both the JViewport and JPanel's alignmentX values to 0.0 but it's still in the center)?
    Thank you all for your time.

    It looks like you have an intermediate panel between the viewport and the JPanel with the BoxLayout. In other words, the view is not the BoxLayout JPanel, but the intermediate one. A newly constructed JPanel will have FlowLayout and position the component top centered as displayed in your picture.
    I wasn't lying when I said the JPanel should be the same size as the viewport. That's the default behavior. Example,
    import javax.swing.*;
    public class Demo {
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
        private static void createAndShowGUI() {
            try {
                UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
            } catch (Exception e) {
                e.printStackTrace();
            String lines = "------------\n" +
                           "------------\n" +
                           "------------\n" +
                           "------------\n" +
                           "------------\n";
            JFrame frame = new JFrame();
            //Box musicPanel = Box.createVerticalBox();
            JPanel musicPanel = new JPanel();
            musicPanel.setBorder(BorderFactory.createEtchedBorder());
            musicPanel.setLayout(new BoxLayout(musicPanel,BoxLayout.PAGE_AXIS));
            Box tempo = Box.createHorizontalBox();
            tempo.add(new JLabel("Temp = 120"));
            tempo.add(new JButton("Change Tempo"));
            musicPanel.add(tempo);
            musicPanel.add(new JLabel("Tack 0: tuba"));
            musicPanel.add(new JTextArea(lines));
            musicPanel.add(new JLabel("Track 1: trombone"));
            musicPanel.add(new JTextArea(lines));
            musicPanel.add(new JLabel("Track 2: C_trumpet"));
            musicPanel.add(new JTextArea(lines));
            musicPanel.add(new JLabel("Track3: English_horn"));
            leftAlign(musicPanel);
            frame.setContentPane(new JScrollPane(musicPanel));
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.pack();
            frame.setVisible(true);
        private static void leftAlign(JComponent parent) {
            parent.setAlignmentX(JComponent.LEFT_ALIGNMENT);
            for(java.awt.Component c : parent.getComponents()) {
                leftAlign((JComponent) c);
    } If you change
    frame.setContentPane(new JScrollPane(musicPanel)); to
    JPanel intermediate = new JPanel();
    intermediate.add(musicPanel);
    frame.setContentPane(new JScrollPane(intermediate)); in the above code, then you'll get something that looks remarkably like the picture you provided.

  • SpringLayout problem for JScrollPane

    hi,
    Though i can add JScrollPane all my panels that i use layoutmanagers except
    springlayout ; i cannot add JScrollPane to a panel that use springLayout as layout manager. if someone helps me , i will be very pleased. I need it for my graduation project so i'm in trouble with this problem:(
    thanks

    Putting in explicit constraints in a reverse direction (i.e. constraing the container's edges to the label) fixes the problem:
        public static void main(String[] argv)
            final SpringLayout layout = new SpringLayout();
            JPanel center = new JPanel(layout);
            final JLabel label = new JLabel("hello");
            label.setFont(label.getFont().deriveFont(150.0f));
            Spring heightSpring = Spring.height(label);
            Spring widthSpring = Spring.width(label);
            center.add(label);
    //        layout.putConstraint(SpringLayout.NORTH, label, 0, SpringLayout.NORTH, center);
    //        layout.putConstraint(SpringLayout.WEST, label, 0, SpringLayout.WEST, center);
    //        layout.putConstraint(SpringLayout.EAST, label, widthSpring, SpringLayout.WEST, center);
    //        layout.putConstraint(SpringLayout.SOUTH, label, heightSpring, SpringLayout.NORTH, center);
            layout.putConstraint(SpringLayout.NORTH, center, 0, SpringLayout.NORTH, label);
            layout.putConstraint(SpringLayout.WEST, center, 0, SpringLayout.WEST, label);
            layout.putConstraint(SpringLayout.EAST, center, widthSpring, SpringLayout.WEST, label);
            layout.putConstraint(SpringLayout.SOUTH, center, heightSpring, SpringLayout.NORTH, label);
            JScrollPane pane = new JScrollPane();
            pane.setViewportView(center);
            JFrame f = new JFrame();
            f.setContentPane(pane);
            f.setSize(100, 100);
            f.setVisible(true);
        }The commented-out lines make no difference to the behaviour wrt the scrollpane.

Maybe you are looking for

  • Upgrading from CS3 to CS5 issues

    I work at a medium size College on a pretty small team, 1 editor/writer, 1 communications coordinator, and 1 designer (me). I've been using InDesign (ID) for 5 years now and we added on the InCopy (IC) workflow a few years ago with CS3 (both of us th

  • How to do data quality check on XI?

    Hi XI guru, I am working on a project, our architect want XI to perform some data quality check to make sure the message contains correct data in future processing. Is there any existing solution or walk arround for XI to perform the data quality che

  • MX: onEnterFrame not being triggered

    I have this code that is supposed to move a movieclip once loaded. It is loading into the initial position but doesn't then trigger the onEnterFrame

  • Library thumbnails taking forever to update

    Up till now I have only had 1500 images imported in folders. When scrolling down within Grid mode in the Library the images updated very quickly, going from blurry thumbnail to sharp thumbnail. Yesterday I added a folder with 4800 images spread in ma

  • Installing GC 10.2.0.3 on linux

    Is it true - 10.2.0.3 gui install option not supported on Linux 5? If no, then can i install 10.2.0.3 and straight upgrade it to 10.2.0.5 without moving to 10.2.0.4?