JScrollPane's scroll

i have a jpalel onto JScrollPane, how can I know from program this jcrollpane's vertical scroll is shown or not ( this panel needs scroll or not ).
Has a JScrollpane object or variable , which messages me this .
I dont wont solve this problem with size of panel. I wont enything usable and symple.
enyone know how can I do?

Could you please explain your exact requirement. If you just want whether you have to show the scrollpane or not then there is a policy in JScrollpane in which you can set the vertical scrollbar policy as required.

Similar Messages

  • JScrollPane auto scrolling.

    Hi Friends,
    Basically I want text in the JTextArea added to the JScrollPane to scroll automatically.
    I have a JFrame to which I have added a horizontal JSplitPane. The Left side of the SplitPane consists of a JPanel with different components and the Right side consists of a JPanel with a JScrollPane containing the JTextArea which displays some Help/News etc.
    I want this text to keep on scrolling continuously, while the user does his work on the Left side, till me application exits.
    Please help me out on this.
    Regards,
    Ravi

    try this:
    JScrollPane scrollPane = new JScrollPane(textArea);
    textArea.setPreferredSize(new Dimension(100,300)):
    scrollpane.setPreferredSize(new Dimension(82,250));
    I am not sure whether it will work or not in your case.but it does work in my application.Hope it works!

  • Need debugging help: Why is JScrollPane auto-scrolling?

    I'm trying to figure out why when I double-click on a cell within a JTable that's wrapped in a JScrollPane in order to open up another window, the JScrollPane automatically scrolls to the top.
    Even when I update the double click operation to simply call setSelected(false), the JScrollPane still automatically scrolls to the top.
    I added myself as a change listener to the scroll pane's row header view port, and captured the following stack trace.
    I'm having trouble debugging exactly what is causing the following chain of events to fire. If I try to put a debug breakpoint on a method like EventQueue.invokeLater() that's probably initiating the following chain of events, I can't even get back to my application window from my IDE without having to dismiss all of the breakpoints that are reached.
    If I try to follow through from the double-click to the actual JScrollPane auto-scroll, I get lost in a maze of Swing events that I can't navigate out of.
    Any suggestions on how to appropriately debug this would be greatly appreciated.
    Thanks,
    Mike
    rowHeaderViewPort stateChanged fired
    chgEvent == javax.swing.event.ChangeEvent[source=javax.swing.JViewport[,1,21,0x329,invalid,layout=javax.swing.ViewportLayout,alignmentX=null,alignmentY=null,border=,flags=8,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=0,height=0],isViewSizeSet=false,lastPaintPosition=,scrollUnderway=false]]
    chgEvent source == javax.swing.JViewport[,1,21,0x329,invalid,layout=javax.swing.ViewportLayout,alignmentX=null,alignmentY=null,border=,flags=8,maximumSize=,minimumSize=,preferredSize=java.awt.Dimension[width=0,height=0],isViewSizeSet=false,lastPaintPosition=,scrollUnderway=false]
    java.lang.Exception: stack trace
         at MyForm$2.stateChanged(MyForm.java:192)
         at javax.swing.JViewport.fireStateChanged(JViewport.java:1341)
         at javax.swing.JViewport.setViewPosition(JViewport.java:1096)
         at javax.swing.ViewportLayout.layoutContainer(ViewportLayout.java:179)
         at java.awt.Container.layout(Container.java:1020)
         at java.awt.Container.doLayout(Container.java:1010)
         at java.awt.Container.validateTree(Container.java:1092)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validateTree(Container.java:1099)
         at java.awt.Container.validate(Container.java:1067)
         at javax.swing.RepaintManager.validateInvalidComponents(RepaintManager.java:353)
         at javax.swing.SystemEventQueueUtilities$ComponentWorkRequest.run(SystemEventQueueUtilities.java:116)
         at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:178)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:454)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:201)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:151)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:145)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:137)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:100)

    Thanks for your response. I examined the code and nowhere that I can see is it calling either of those two methods.
    At some point, it looks like something within my code or in the UI frameworks that I'm using is invalidating my JScrollPane. I'm having a very difficult time, though, tracking down exactly which component is causing that invalidation.
    Short of writing my own JScrollPane so that I can capture the stack trace of calls to invalidate(), does anyone have any suggestions for debugging this further? I tried to use a conditional breakpoint in Eclipse 2.1.3 (Component.invalidate() where the Component is an instance of JScrollPane), but my breakpoint is never being executed.
    Thanks,
    Mike

  • My JScrollpane wont scroll horizontally?

    hmmmm...
    As the title says, my JSCrollPane wont scroll horizontally. I've passed a customer "Drawer" object to it.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.ArrayList;
    public class gui extends JFrame{
         Container c;
         JPanel p;
         Drawer d;
         JComboBox box;
         JLabel lab;
         JScrollPane sp=new JScrollPane(p);
         String options[]={"Terminal","Non-Terminal","Repeat","Or"};
         ArrayList list=new ArrayList();
         String lastTerminal="";
         String lastNonTerminal="";
         int x=0;
         int y=350;
         boolean stupid=true;
         int pixelsize=0;
         String orString;
         ArrayList orStringList=new ArrayList();
         ArrayList orList=new ArrayList();
         boolean done=false;
         int count=0;
         int lastx=0;
         int lasty=0;
         public gui(){
              super("Something");
              setSize(900,700);
              c=getContentPane();
              c.setLayout(new BorderLayout(5,5));
              c.setBackground(Color.white);          
              p=new JPanel();
             d=new Drawer();
             box=new JComboBox(options);
             lab=new JLabel("Add:");
            box.addActionListener(new BoxListener());
            box.setOpaque(false);
             p.add(lab);
              p.add(box);
              sp=new JScrollPane(d);
              c.add(sp,BorderLayout.CENTER);
              c.add(p,BorderLayout.SOUTH);
              show();
         public class BoxListener implements ActionListener{
          public void actionPerformed(ActionEvent evt) {
               //if(!stupid){
                if (box.getSelectedIndex()==0)
                     lastTerminal=JOptionPane.showInputDialog("Enter your Terminal name");
                     list.add(new Terminal(lastTerminal,x,y,true));
                     Terminal tt=(Terminal)list.get(list.size()-1);
                     x=x+tt.getStringWidth()+45;
                     repaint();
                if (box.getSelectedIndex()==1)
                       lastNonTerminal=JOptionPane.showInputDialog("Enter your Non-Terminal name");
                     list.add(new Terminal(lastNonTerminal,x,y,false));
                     Terminal tt=(Terminal)list.get(list.size()-1);
                     x=x+tt.getStringWidth()+45;
                     repaint();
             if (box.getSelectedIndex()==3)
                       orStringList.clear();
                       orString=JOptionPane.showInputDialog("Enter your Or, seperate each Or with a |")+"|";
                       StringBuffer sb=new StringBuffer(orString);
                       while(sb.indexOf("|")!=-1)
                            orStringList.add(sb.substring(0,sb.indexOf("|")));
                            sb.delete(0,sb.indexOf("|")+1);
                       int eveny=y;
                        int oddy=y;
                        for(int i=1;i<orStringList.size()+1;i++)
                                 if((i%2)==0)
                                           eveny=eveny+25;
                                           orList.add(new OrTerm((String)orStringList.get(i-1),x+35,eveny,false,x,y,x+130,y));
                                  else
                                            oddy=oddy-25;
                                           orList.add(new OrTerm((String)orStringList.get(i-1),x+35,oddy,false,x,y,x+130,y));
                       OrTerm tt=(OrTerm)orList.get(orList.size()-1);
                     x=x+tt.getStringWidth()+100;
                       repaint();
         public static void main (String args[]) {
              gui app = new gui();
              app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public class Drawer extends JPanel
              public Drawer()
                   this.setBackground(Color.ORANGE);
         public void paint(Graphics g2)
             super.paint(g2);
             Graphics2D g=(Graphics2D)g2;
              g.setFont(new Font(null,Font.BOLD,15));
              Terminal temp=null;
              OrTerm temp2=null;
              for(int i=0;i<orList.size();i++)
                        temp2=(OrTerm)orList.get(i);
                        pixelsize=SwingUtilities.computeStringWidth(g.getFontMetrics(),temp2.getName());
                        g.drawString(temp2.getName(),temp2.getx(),temp2.gety());
                        g.drawRect(temp2.getx()-4,temp2.gety()-16,pixelsize+7,25);
                        g.drawLine(temp2.getx()-2,temp2.gety()-2,temp2.getx2()-5,temp2.gety2()-2);
                        g.drawLine(temp2.getx()+pixelsize+7,temp2.gety()-2,temp2.getx3(),temp2.gety3());
              for(int i=0;i<list.size();i++)
                   temp=(Terminal)list.get(i);
                   g.drawString(temp.getName(),temp.getx(),temp.gety());
                   pixelsize=SwingUtilities.computeStringWidth(g.getFontMetrics(),temp.getName());
                   if(temp.isTerminal()==true)
                     g.drawOval(temp.getx()-4,temp.gety()-16,pixelsize+7,25);
                   else
                     g.drawRect(temp.getx()-4,temp.gety()-16,pixelsize+7,25);
                   lastx=temp.getx()+pixelsize+7+30;
                   lasty=y-2;
                   //drawing line
                   g.drawLine(temp.getx()+pixelsize+7,y-2,temp.getx()+pixelsize+7+30,y-2); 
                 //drawing little array >
                 g.drawLine(temp.getx()+pixelsize+7+30,y-2,temp.getx()+pixelsize+7+25,y-7);
                  g.drawLine(temp.getx()+pixelsize+7+30,y-2,temp.getx()+pixelsize+7+25,y+5);
    class Terminal {
         private String name;
         private int x2;
         private int y2;
         private boolean terminal;
         public Terminal(String name, int x, int y,boolean boo)
              this.name=name;
              this.x2=x;
              this.y2=y;
              this.terminal=boo;
         public String getName(){return this.name;}
         public int getx(){return this.x2;}
         public int gety(){return this.y2;}
         public int getStringWidth()
              return SwingUtilities.computeStringWidth(Toolkit.getDefaultToolkit().getFontMetrics(new Font(null,Font.BOLD,15)),this.name);
         public boolean isTerminal(){return this.terminal;}
    class OrTerm {
         private String name;
         private int x;
         private int y;
         private int x2;
         private int y2;
         private int x3;
         private int y3;
         private boolean terminal;
         public OrTerm(String name, int x, int y,boolean boo,int x2,int y2,int x3,int y3)
              this.name=name;
              this.x=x;
              this.y=y;
              this.terminal=boo;
              this.x2=x2;
              this.y2=y2;
              this.x3=x3;
              this.y3=y3;          
         public String getName(){return this.name;}
         public int getx(){return this.x;}
         public int gety(){return this.y;}
         public int getx2(){return this.x2;}
         public int gety2(){return this.y2;}
         public int getx3(){return this.x3;}
         public int gety3(){return this.y3;}
         public int getStringWidth()
              return SwingUtilities.computeStringWidth(Toolkit.getDefaultToolkit().getFontMetrics(new Font(null,Font.BOLD,15)),this.name);
         public boolean isTerminal(){return this.terminal;}
         import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.ArrayList;
    public class gui extends JFrame{
         Container c;
         JPanel p;
         Drawer d;
         JComboBox box;
         JLabel lab;
         JScrollPane sp=new JScrollPane(p);
         String options[]={"Terminal","Non-Terminal","Repeat","Or"};
         ArrayList list=new ArrayList();
         String lastTerminal="";
         String lastNonTerminal="";
         int x=0;
         int y=350;
         boolean stupid=true;
         int pixelsize=0;
         String orString;
         ArrayList orStringList=new ArrayList();
         ArrayList orList=new ArrayList();
         boolean done=false;
         int count=0;
         int lastx=0;
         int lasty=0;
         public gui(){
              super("Something");
              setSize(900,700);
              c=getContentPane();
              c.setLayout(new BorderLayout(5,5));
              c.setBackground(Color.white);          
              p=new JPanel();
         d=new Drawer();
         box=new JComboBox(options);
         lab=new JLabel("Add:");
    box.addActionListener(new BoxListener());
    box.setOpaque(false);
         p.add(lab);
              p.add(box);
              sp=new JScrollPane(d);
              c.add(sp,BorderLayout.CENTER);
              c.add(p,BorderLayout.SOUTH);
              show();
         public class BoxListener implements ActionListener{
         public void actionPerformed(ActionEvent evt) {
              //if(!stupid){
              if (box.getSelectedIndex()==0)
         lastTerminal=JOptionPane.showInputDialog("Enter your Terminal name");
         list.add(new Terminal(lastTerminal,x,y,true));
         Terminal tt=(Terminal)list.get(list.size()-1);
         x=x+tt.getStringWidth()+45;
         repaint();
              if (box.getSelectedIndex()==1)
         lastNonTerminal=JOptionPane.showInputDialog("Enter your Non-Terminal name");
         list.add(new Terminal(lastNonTerminal,x,y,false));
         Terminal tt=(Terminal)list.get(list.size()-1);
         x=x+tt.getStringWidth()+45;
         repaint();
    if (box.getSelectedIndex()==3)
              orStringList.clear();
              orString=JOptionPane.showInputDialog("Enter your Or, seperate each Or with a |")+"|";
              StringBuffer sb=new StringBuffer(orString);
              while(sb.indexOf("|")!=-1)
                   orStringList.add(sb.substring(0,sb.indexOf("|")));
                   sb.delete(0,sb.indexOf("|")+1);
              int eveny=y;
                        int oddy=y;
                        for(int i=1;i<orStringList.size()+1;i++)
                        if((i%2)==0)
                                  eveny=eveny+25;
                                  orList.add(new OrTerm((String)orStringList.get(i-1),x+35,eveny,false,x,y,x+130,y));
                                  else
                                            oddy=oddy-25;
                                  orList.add(new OrTerm((String)orStringList.get(i-1),x+35,oddy,false,x,y,x+130,y));
              OrTerm tt=(OrTerm)orList.get(orList.size()-1);
         x=x+tt.getStringWidth()+100;
              repaint();
         public static void main (String args[]) {
              gui app = new gui();
              app.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public class Drawer extends JPanel
              public Drawer()
                   this.setBackground(Color.ORANGE);
    public void paint(Graphics g2)
         super.paint(g2);
         Graphics2D g=(Graphics2D)g2;
              g.setFont(new Font(null,Font.BOLD,15));
         Terminal temp=null;
         OrTerm temp2=null;
              for(int i=0;i<orList.size();i++)
                   temp2=(OrTerm)orList.get(i);
                   pixelsize=SwingUtilities.computeStringWidth(g.getFontMetrics(),temp2.getName());
                   g.drawString(temp2.getName(),temp2.getx(),temp2.gety());
                   g.drawRect(temp2.getx()-4,temp2.gety()-16,pixelsize+7,25);
                   g.drawLine(temp2.getx()-2,temp2.gety()-2,temp2.getx2()-5,temp2.gety2()-2);
                   g.drawLine(temp2.getx()+pixelsize+7,temp2.gety()-2,temp2.getx3(),temp2.gety3());
         for(int i=0;i<list.size();i++)
              temp=(Terminal)list.get(i);
              g.drawString(temp.getName(),temp.getx(),temp.gety());
              pixelsize=SwingUtilities.computeStringWidth(g.getFontMetrics(),temp.getName());
              if(temp.isTerminal()==true)
              g.drawOval(temp.getx()-4,temp.gety()-16,pixelsize+7,25);
              else
              g.drawRect(temp.getx()-4,temp.gety()-16,pixelsize+7,25);
              lastx=temp.getx()+pixelsize+7+30;
              lasty=y-2;
              //drawing line
              g.drawLine(temp.getx()+pixelsize+7,y-2,temp.getx()+pixelsize+7+30,y-2);
         //drawing little array >
         g.drawLine(temp.getx()+pixelsize+7+30,y-2,temp.getx()+pixelsize+7+25,y-7);
         g.drawLine(temp.getx()+pixelsize+7+30,y-2,temp.getx()+pixelsize+7+25,y+5);
    class Terminal {
         private String name;
         private int x2;
         private int y2;
         private boolean terminal;
         public Terminal(String name, int x, int y,boolean boo)
              this.name=name;
              this.x2=x;
              this.y2=y;
              this.terminal=boo;
         public String getName(){return this.name;}
         public int getx(){return this.x2;}
         public int gety(){return this.y2;}
         public int getStringWidth()
              return SwingUtilities.computeStringWidth(Toolkit.getDefaultToolkit().getFontMetrics(new Font(null,Font.BOLD,15)),this.name);
         public boolean isTerminal(){return this.terminal;}
    class OrTerm {
         private String name;
         private int x;
         private int y;
         private int x2;
         private int y2;
         private int x3;
         private int y3;
         private boolean terminal;
         public OrTerm(String name, int x, int y,boolean boo,int x2,int y2,int x3,int y3)
              this.name=name;
              this.x=x;
              this.y=y;
              this.terminal=boo;
              this.x2=x2;
              this.y2=y2;
              this.x3=x3;
              this.y3=y3;          
         public String getName(){return this.name;}
         public int getx(){return this.x;}
         public int gety(){return this.y;}
         public int getx2(){return this.x2;}
         public int gety2(){return this.y2;}
         public int getx3(){return this.x3;}
         public int gety3(){return this.y3;}
         public int getStringWidth()
              return SwingUtilities.computeStringWidth(Toolkit.getDefaultToolkit().getFontMetrics(new Font(null,Font.BOLD,15)),this.name);
         public boolean isTerminal(){return this.terminal;}
         

    Scrollbars will appear when the preferred size of the component is greater than the size of the scroll pane. If you are adding a custom drawn component to the scrollpane then you must set the preferredSize.

  • Why the JScrollPane not scroll?

    I create a dialog,then I put a JScrollPane on the dialog,after this I put a JPanel on the JScrollPane,
    finally I put many checkbox on the JPanel.Due to having many checkboxes, I hope that JScrollPane can scroll,but it cannot scroll .how can I sove this problem?
    the following is my code:
    this.setSize(new Dimension(543, 523));
    this.getContentPane().setLayout(null);
    jButton3.setText("ok");
    jButton3.setBounds(new Rectangle(235, 455, 95, 30));
    jButton4.setText("cancel");
    jButton4.setBounds(new Rectangle(395, 455, 100, 30));
    // jScrollPane1.setBounds(new Rectangle(0, 20, 515, 1195));
    // jScrollPane1.setAutoscrolls(true);
    jPanel1.setBackground(Color.cyan);
    jPanel1.setLayout(null);
    jPanel1.setAutoscrolls(true);
    jPanel1.setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
    jCheckBox1.setText("attrib_manager");
    jCheckBox1.setBounds(new Rectangle(10, 10, 110, 25));
    ������������
    jCheckBox66.setBounds(new Rectangle(205, 1120, 97, 26));
    jCheckBox66.setEnabled(false);
    ������������
    jPanel1.add(jCheckBox66, null);
    jPanel1.add(jCheckBox1, null);
    JScrollPane jScrollPane1 = new JScrollPane(jPanel1);
    jScrollPane1.setBounds(new Rectangle(0, 20, 515, 425));
    jScrollPane1.setAutoscrolls(true);
    jScrollPane1.getViewport().add(jPanel1, null);
    this.getContentPane().add(jScrollPane1, null);
    this.getContentPane().add(jButton4, null);
    this.getContentPane().add(jButton3, null);

    You have to set size of your panel.
    override method getPrefferedSize() of panel. This methd should return correct size of content.
    best regadrs
    Stas

  • JScrollPane not scrolling to the end of JTable

    Hello,
    I put a table in a scroll pane, and add the scroll pane to a panel. The problem is the scroll pane does not scroll to the end of the table, it always lets me view only the first 37 rows of the table, regardless of how many rows the table actually has. Basically, the scroll pane thinks the table has exactly the same height, no matter how many lines it has. Why is this happening?
    The code is something like
    model = new SearchResultTableModel(false, null, null);
    table = new ResultTable(model);
    scrollPane = new JScrollPane(table);
    mainBox.add(scrollPane);
    If this is important, the table is a bit more complicated, I subclass JTable, use a custom TableModel, several types of cell renderers / editors, so maybe this is why it behaves so strange. How could I tell the scroll pane the table is actually larger?
    Thank you very much, any ideas are highly appreciated,
    Regards from Romania,
    Adi

    Hi,
    fireTableDataChanged() is the easiest way to do it, but also that one, that forces JTable to rerender all visible cells, regardless the fact, that they are already displayed and would not need rerendering - if you add a row - for example row 7 - do fireTableRowsInserted(7,7); instead - so JTable will only render this single row if it is visible in the viewport. If you add a couple of rows, for example row 7 to 227, do fireTableRowsInserted(7,227); - always fire only the correct notifications accordingly to the changes you make, in order to keep the performance of JTable high.
    greetings Marsian

  • JScrollPane wont scroll .. pls help

    hi to all,
    I have a scrollpane that i am displaying a graph in, and they will be large graphs, 10000 nodes with about cardinality 10 for each node.
    I can generate the graph output no problems but my scrollbars dont allow me to scroll the pane, and i cant figure out why.
    I'm assuming that i should be doing something with the viewport once i add the graph, but i dont know what.
    can anyone pls help me,
    also can anyone suggest how i go about zooming in and out. im thinking its just resizng the viewport, but i need to work out why i cant scroll before i tackle that.
    package graphappz.ui;
    import java.awt.*;
    import java.awt.geom.*;
    import javax.swing.*;
    import graphappz.graph.Graph;
    import java.util.Iterator;
    import graphappz.graph.Vertex;
    import graphappz.graph.Edge;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    public class GraphWindow
        extends JPanel {
      JEditorPane graphWindow;
      JScrollPane graphView;
      Dimension d = new Dimension();
      Point2D p = null;
      GraphViewer viewer;
      public GraphWindow() {
        graphWindow = new JEditorPane();
        graphWindow.setText("");
        viewer = new GraphViewer();
        graphView = new JScrollPane(viewer);
        graphView.setHorizontalScrollBarPolicy(JScrollPane.
                                               HORIZONTAL_SCROLLBAR_ALWAYS);
        graphView.setVerticalScrollBarPolicy(JScrollPane.
                                             VERTICAL_SCROLLBAR_ALWAYS);
        graphView.getViewport().setBackground(Color.white);
        graphView.setBorder(BorderFactory.createEtchedBorder());
        graphView.setToolTipText("Graph Output Display Window");
        repaint();
      public JScrollPane getGraphView() {
        return this.graphView;
      public Dimension getSize() {
        graphView.setPreferredSize(new Dimension(520, 440));
        return graphView.getPreferredSize();
      class GraphViewer
          extends JPanel {
        public void paintComponent(Graphics g) {
          super.paintComponent(g);
          int nodeWidth = 20;
          int nodeHeight = 20;
          if (graphappz.Main.graph != null) {
            Graph graph = graphappz.Main.graph;
            Iterator iter = graph.edgeIter();
            while (iter.hasNext()) {
              Edge e = (Edge) iter.next();
              Vertex v_0 = e.getv0();
              Vertex v_1 = e.getv1();
              if ( ( (v_0.getLayoutPosition() != null) ||
                    (v_1.getLayoutPosition() != null))) {
                Point2D.Double pos_0 = v_0.getLayoutPosition();
                Point2D.Double pos_1 = v_1.getLayoutPosition();
                // draw the edge
                g.setColor(Color.red);
                g.drawLine( (int) pos_0.x + (nodeWidth / 2),
                           (int) pos_0.y + (nodeHeight / 2),
                           (int) pos_1.x + (nodeWidth / 2),
                           (int) pos_1.y + (nodeHeight / 2));
                // draw the first node
                g.setColor(Color.blue);
                g.drawOval( (int) pos_0.x, (int) pos_0.y, nodeWidth, nodeHeight);
                g.fillOval( (int) pos_0.x, (int) pos_0.y, nodeWidth, nodeHeight);
                // draw the second node
                g.setColor(Color.blue);
                g.drawOval( (int) pos_1.x, (int) pos_1.y, nodeWidth, nodeHeight);
                g.fillOval( (int) pos_1.x, (int) pos_1.y, nodeWidth, nodeHeight);
                // draw the edge
                g.setColor(Color.black);
                g.drawString(v_0.getReference() + "", (int) pos_0.x + 5,
                             (int) pos_0.y + 14);
          else {
            graphappz.util.Debug.debugText.append("\n graph is null, can't draw it");
            //TODO: show new Alert_Dialog
        public GraphViewer() {
          this.setBackground(Color.white);
          this.addMouseListener(new MouseListener() {
            public void mouseClicked(MouseEvent e) {}
            public void mousePressed(MouseEvent e) {}
            public void mouseReleased(MouseEvent e) {}
            public void mouseEntered(MouseEvent e) {}
            public void mouseExited(MouseEvent e) {}
    }

    Scrollbars will appear when the preferred size of the panel is greater than the preferred size of the scrollpane.
    When you add components (JButton, JTextField...) to a panel then the preferred size can be calculated by the layout manager.
    When you draw on a panel the layout manager has no idea what the size of you panel is so you need to set the preferrred size yourself:
    panel.setPreferredSize(...);

  • JScrollPane's scroll bar alignment

    I tried all the suggested methods, and yet I still get the vertical scroll bar aligned somewhere in the middle when the JFrame opens, when top alignment would be preferable... Any suggestion on this is more than welcome. My code is structured with nested components like this:
    JScrollPane scroll
    ---JPanel allJPanels
    ------JPanel a
    ---------JPanel a_1
    ---------JLabel a_2
    ---------JEditorPane a_3
    ------JPanel b
    ---------JPanel b_1
    ---------JLabel b_2
    ---------JEditorPane b_3
    scroll.setViewportView( allJPanels );
    Methods attempted:
    scroll.getVerticalScrollBar().setValue( scroll.getVerticalScrollBar().getMinimum() );
    OR
    scroll.getViewport().setViewPosition( new java.awt.Point( 0, 0 ) );
    OR
    scroll.getVerticalScrollBar().getModel().setValue( 0 );     
    OR
    allJPanels.scrollRectToVisible( new java.awt.Rectangle( 1, 1, allJPanels.getWidth(), allJPanels.getHeight() ) );
    Thanks for any suggestion

    Could you please explain your exact requirement. If you just want whether you have to show the scrollpane or not then there is a policy in JScrollpane in which you can set the vertical scrollbar policy as required.

  • JScrollPane Must Scroll to the END ........

    My problem is :
    I have a JTextArea , and the text inside doesn't fit
    in it. When this happens , the two ScrollBar should
    scroll to the END of the text....
    Like if a have a JTextArea with 10 rows with a JScrollPane, and my text is 20 rows long, then i
    need to see the end of the text(No manual Scrolling)
    Are there any method to control the Scrollbar position ?
    Help....!!!!!!!

    Hi,
    When you move the caret position of your JTextArea, then the scollbars follow. Try this (assuming your JTextArea is called textArea):
    textArea.setCaretPosition(textArea.getLineEndOffset(textArea.getLineCount()-1));This scrolls to the end of the JTextArea.
    Hope this helps,
    Kurt.

  • Positioning HorizontalBar in JScrollPane and scroller

    Hi,
    I have attached a JScrollPane to a text area.
    the code is as follows.
    JScrollPane jsp = new JScrollPane( jtx1 );
    however since the contents in the JTextArea is large horizontally, the text gets displayed in the textarea. However the scroller in the JScrollPane gets positioned towards the end of the text. How do I specify to make sure that the Scroller is always in the start of the text?
    and also i wanted the Vertical ScrollBar to be always visble and what i did was:
    int vpolicy = jsp.getVerticalScrollBarPolicy();
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    The Vertical ScrollBar gets displayed. However I am not ablt to see the scroller in the JScrollPane's vertical bar as I don't have sufficient text vertically. How do i specify that the scroller always be present in my vertical side...irrespective of the contents in the Textarea. i.e i always want to scroll. (I see the ScrollBAr. however am not able to scroll b'coz i have less text.)
    Thanks!
    Karthik.

    Hi,
    I have attached a JScrollPane to a text area.
    the code is as follows.
    JScrollPane jsp = new JScrollPane( jtx1 );
    however since the contents in the JTextArea is large horizontally, the text gets displayed in the textarea. However the scroller in the JScrollPane gets positioned towards the end of the text. How do I specify to make sure that the Scroller is always in the start of the text?
    and also i wanted the Vertical ScrollBar to be always visble and what i did was:
    int vpolicy = jsp.getVerticalScrollBarPolicy();
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    The Vertical ScrollBar gets displayed. However I am not ablt to see the scroller in the JScrollPane's vertical bar as I don't have sufficient text vertically. How do i specify that the scroller always be present in my vertical side...irrespective of the contents in the Textarea. i.e i always want to scroll. (I see the ScrollBAr. however am not able to scroll b'coz i have less text.)
    Thanks!
    Karthik.

  • Stop JScrollPane from scrolling

    Hello, I am trying to improve a special editor i have written. Now I tried to add line numbering to it and got stuck. Here's what I did:
    I have a JScrollPane that contains a JPanel. This JPanel has a BorderLayout and contains a JTextPane (where the editable text is) in the CENTER and a JTextArea (containing the line numbers) in the WEST.
    Everytime the text is edited, I count the lines and update the JTextArea so that the right amount of line numbers is shown. But here's the problem: Everytime I update the line numbers, the JScrollPane scrolls down to the very bottom, so in some cases the caret gets hidden (which is very annoying).
    Can someone tell me how I can tell the JScrollPane (or whoever else is to blame for this) not to scroll when I update the line number JTextArea? Is there an easy way to achieve this?
    Thanks in advance

    Another way to do this:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.*;
    import javax.swing.text.rtf.*;
    class Test extends JFrame
    public Test()
    super("Test");
    JEditorPane edit = new JEditorPane();
    edit.setEditorKit(new MyRTFEditorKit());
    edit.setEditable(true);
    JScrollPane scroll=new JScrollPane(edit);
    getContentPane().add(scroll);
    setSize(300,300);
    setVisible(true);
    public static void main(String a[])
    new Test();
    class MyRTFEditorKit extends RTFEditorKit
    public ViewFactory getViewFactory()
    return new MyRTFViewFactory();
    class MyRTFViewFactory implements ViewFactory
    public View create(Element elem)
    String kind = elem.getName();
    if (kind != null)
    if (kind.equals(AbstractDocument.ContentElementName)) {
    return new LabelView(elem);
    } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
    // return new ParagraphView(elem);
    return new MyParagraphView(elem);
    } else if (kind.equals(AbstractDocument.SectionElementName)) {
    // return new BoxView(elem, View.Y_AXIS);
    return new MySectionView(elem, View.Y_AXIS);
    } else if (kind.equals(StyleConstants.ComponentElementName)) {
    return new ComponentView(elem);
    } else if (kind.equals(StyleConstants.IconElementName)) {
    return new IconView(elem);
    // default to text display
    return new LabelView(elem);
    class MySectionView extends BoxView {
    public MySectionView(Element e, int axis)
    super(e,axis);
    public void paintChild(Graphics g,Rectangle r,int n) {
    if (n>0) {
    MyParagraphView child=(MyParagraphView)this.getView(n-1);
    int shift=child.shift+child.childCount;
    MyParagraphView current=(MyParagraphView)this.getView(n);
    current.shift=shift;
    super.paintChild(g,r,n);
    class MyParagraphView extends javax.swing.text.ParagraphView
    public int childCount;
    public int shift=0;
    public MyParagraphView(Element e)
    super(e);
    short top=0;
    short left=20;
    short bottom=0;
    short right=0;
    this.setInsets(top,left,bottom,right);
    public void paint(Graphics g, Shape a)
    childCount=this.getViewCount();
    super.paint (g,a);
    int rowCountInThisParagraph=this.getViewCount();
    System.err.println(rowCountInThisParagraph);
    public void paintChild(Graphics g,Rectangle r,int n) {
    super.paintChild(g,r,n);
    g.drawString(Integer.toString(shift+n+1),r.x-20,r.y+r.height-3);

  • Preventing JScrollPane from scrolling when contents change

    I have an application where I have a large panel of information that is constantly being updated over time. I found a need to put more information on the panel than I could fit on my screen, so I put everything in a JScrollPane.
    This works to a degree, but I find that as things in the panel get updated (JTextAreas are an example) the JScrollPane scrolls wildly about. I think it is trying to show components that have changed. I would prefer that it NEVER scroll on its own since the whole panel will be updating at any given time.
    Does anyone know if there is a way to turn off this behavior? I set the preferred/minimum/maximum size on the JPanel that goes inside the JScrollPane to keep it a constant size, but that doesn't solve the problem. If someone can help me, I'd really appreciate it. Thanks!

    Off the top of my head, I can think of at least two action events that are fired by a JComboBox, one has to do with selection being made and another is comboBoxEdited. If you want to do something only when an item in the combo box is selected, then you should programmatically ignore the later.
    If you're doing other changes your self, you can always remove the listener from the combobox, make the changes, and then add the listener back.
    ;o)
    V.V.

  • JScrollPane should scroll to max automaticly

    By default the JScrollBar (in a JScrollPane) stays at the current value when the viewport is extended.
    How can I set the JScrollBar that it is at the max value when something ist insertet (So that I don't have to scroll down manually)?
    Thanx
    Martin

    perhaps you'll find an answer here:
    http://developer.java.sun.com/developer/bugParade/bugs/4201999.html
    ;o)
    V.V.

  • Prevent JScrollpane from scrolling... + JTextPane

    hello,
    i've a JScrollPane(JTextPane) which displays html-code provided by the setText()-method. but i'd like the JScrollPane NOT to scroll automatically to the bottom when the programm inserts new html-code with setText(). setting the JScrollBar-Value doesn't work. I need something to prevent the JScrollBar from scrolling....
    by the way, does anyone know a way to append text to a JTextPane (line by line)... JTextPane provides only a setText()-method which overwrites the old content with the new text... i'd like to append it....
    thanks,
    andi

    This has taken me over a year to figure out. I spent lots of time trying to set the viewport back to the top or moving the scroll bar back to the top. I even tried inserting text at the very begining. None of this works. What does work is setting the cursor (caret) to the begining of the text pane after you add the text. Something like this:
    document.insertString(document.getLength(),"...lots of text...",attr);
    textPane.getCaret().setDot(0); << the big secret
    Pretty easy huh?

  • JScrollPane not scrolling, image only flickering

    Hi, guys:
    I have this problem that I used JAI to render an image on a JPanel and then put the JPanel into a JScrollPane. The strangest thing is that when I scroll, the scrollbar is moving but the image just flicker a little, for like 0.1 second it scrolls but quickly back to the original position. I feel that it has something to do with the paintComponent but I can't see what should be done. I will be very thankful if any of you can give me some suggestions!
    David

    Why my question is always ignored???
    I solved the problem by add the JComponent which renders the image to an additional JPanel, and then set the JPanel to opaque by setOpaque(true), and then add the JPanel to the viewport of the JScrollPane.

Maybe you are looking for

  • Add button to transaction ie01,il01,ia01

    Hi All, Does anyone knows how to enhance these transactions(IE03 , IL03 , IA03) i am not able to enhance it. I got an exit ITOB0001 for tecnical objects but not able to see any difference on IE01 transaction. My requirement is to add a button or menu

  • CAST MULTISET using a recursive UDT using REF

    I am trying to create a recursive object and populate it using cast and multiset. However I keep getting the following error: ORA-00932: inconsistent datatypes: expected UDT got CHAR 00932. 00000 - "inconsistent datatypes: expected %s got %s" *Cause:

  • Scheduling of jobs

    Hi Gurus, I have an issue regarding scheduling of jobs: How can we schedule the jobs based upon the colour and raw material structure. The scenario is , today I have to produce a red colour film (which is a sub assembly for a Parent item) and i have

  • Filter to print file names on your clips?

    I'm looking for a way to print the file name of a clip on the clip - similar to the Timecode filter in AfterEffects. Any suggestions? I could use After Effects as well if anyone knows of a suitable filter for that, either...

  • Parameter  CPU_PER_SESSION  and CPU_PER_CALL

    Hi, I created a profile with the following parameters for the new users SESSIONS_PER_USER 3 CPU_PER_SESSION 2000 CPU_PER_CALL 2000 CONNECT_TIME 1 IDLE_TIME 2 My question is: How know if my query is consuming more than 20 seconds processor time? thank