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.

Similar Messages

  • 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.

  • 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

  • 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

  • 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.

  • 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(...);

  • LayeredPane, validation Icons, JScrollPane should become invisible

    For development of an application we have customized textfields, comboxes etc. The are able to show validation icons, these icons are centered in the down/left corner. Thus a little bit in and outside of the components bounds.
    To add validation icons, I add them (JLabel, with icon) tothe layeredPane of the getRootpane(). Using swingutilitities.getLocationOnScreen I calculate the location where to put the icons.
    However if a textfield is inside a scrollpane, and the textfield is scrolled outside of the visible viewport the icon is still being painted, somewhere outside the scrollpane.
    (I had the same problems with JTabbedPane, buth by check isShowing this was solved, however when component is inside viewPort, the "isShowing" still return "true" ). How can I check, or should I use other way of displaying validation icons.
    Our components need to extend from components and need to be using by visual designer tool.

    //Sorry, went something wrong during previous post
    This is my "special panel":
    @Override
    AddImple(Component comp, Object c, int index){
    if(x instanceof y){   
         //layerUI created somewhere else(examples on your site)
        JxLayer<JComponent>  wrapper = new JXLayer<JComponent>(comp, layerUI);
        super.addImpl(wrapper, c, index)
    }This only goes fine using layoutmanagers which not using the setBounds methods. If using nullLayout, grouplayout etc etc, if have to override setBounds, find out who is invoking, "parent" panel or the JXJayer. Depending on that, in the setbounds if have to invoke setBounds from super or setBounds from layer&super.
    I'm not happy with my implementation yet because: Using special panel(addImpl) and overriding setbounds in component. Further not every visual designer (jFormDesigner, netbeans) deals nice with it.
    I tried creating custom borderUIResource. Overriding getInsets and paintComponent works quite well, however because of custom insets(extra left&down) it's not lined-out perfectly with other default components.Further visual designers paint insets white at design time, not biggest issue yet....
    There are really several ways for painting icons outside bounds, however perfect isn't found yet....
    Maybe using rootpane's layeredpane with custom code for jScrollPane etc isn't so bad at all.
    Edited by: heicovdkamp on Oct 8, 2008 5:15 AM

  • 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.

  • 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.

  • JScrollPane set Scroll Bar at Location

    I'm making a program with a table of contents and I have a JPanel inside a JScrollPane. When the table of contents is clicked, I want it to go to a certain location on the JPanel, in other words scroll down to a specificed location. Can I do this in Java?

    in other words scroll down to a specificed location1) In the future, Swing related questions should be posted in the Swing forum.
    2) You got good help in your last posting but never bothered to read the posting (well at least you never took the time to respond to the posting).
    3) Did you read the API? How difficult is it to search the API? Maybe for a method with the word "scroll" in the method name? If you can think of the words you use in your question then you can think of keywords to use in your search.

  • JScrollPane doesnt Scroll

    Hey..
    first of all... i would like to appologise if this is a report (which im sure it is) so im sorry.
    problem:
    Im trying to add a JScrollPane to a JList but its not playing the way i need it to.
    it adds the scrollpane but never scrolls past a certain point.
    the code is as follows:
                        detailList = new JList(listModel);
                        detailList.setBounds(14, 84, 168, 504);
                        detailList.setFont(new java.awt.Font("SansSerif",0,10));
                        detailList.setBorder(BorderFactory.createTitledBorder(""));
                        detailList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                        detailList.setPreferredSize(new java.awt.Dimension(173, 502));
    //                    detailList.setVisibleRowCount(Math.max(listModel.size(),
    //                              MAX_LIST_VISIBLE));
                        JScrollPane sp = new JScrollPane(detailList, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,J
                                                         ScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                        sp.setLocation(14, 84);
                        sp.setSize(168, 504);
                        getContentPane().add(sp);
                        sp.repaint();
                   }i believe it has something to do with setting te sizes of things etc.
    it also always displays the scrollbars when they are not needed..
    http://img86.imageshack.us/img86/7742/defun6.jpg
    if someone could shine some light on my stupidity i would really appreciate it
    Thanks in advance
    Dave =)
    Message was edited by:
    dgib
    Message was edited by:
    dgib

    Hey..
    first of all... i would like to appologise if this is
    a report (which im sure it is) so im sorry.
    problem:
    Im trying to add a JScrollPane to a JList but its not
    playing the way i need it to.
    it adds the scrollpane but never scrolls past a
    certain point.
    the code is as follows:
                        detailList = new JList(listModel);
                        detailList.setBounds(14, 84, 168, 504);
    detailList.setFont(new
    (new java.awt.Font("SansSerif",0,10));
                        detailList.setBorder(BorderFactory.createTitledBor
    der(""));
                        detailList.setSelectionMode(ListSelectionModel.SIN
    GLE_SELECTION);
    detailList.setPreferredSize(new
    (new java.awt.Dimension(173, 502));
    //                    detailList.setVisibleRowCount(Math.max(listModel
    .size(),
    //                              MAX_LIST_VISIBLE));
    JScrollPane sp = new JScrollPane(detailList,
    ist, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,J
    crollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                        sp.setLocation(14, 84);
                        sp.setSize(168, 504);
                        getContentPane().add(sp);
                        sp.repaint();
                   }i believe it has something to do with setting te
    sizes of things etc.
    it also always displays the scrollbars when they are
    not needed..
    urlhttp://img86.imageshack.us/img86/7742/defun6.jpg[
    /url]
    if someone could shine some light on my stupidity i
    would really appreciate it
    Thanks in advance
    Dave =)
    Message was edited by:
    dgib
    was edited by:
    dgib
    1. Swing questions belong in the Swing forum.
    2. The signature for setVisibleRowCount is
    public void setVisibleRowCount(int visibleRowCount)

  • 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'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.

Maybe you are looking for

  • Acrobat X freezes on OCR during "recognizing text" step

    Acrobat X standard freezes every time I try to OCR a document - it starts through the process but when it gets to the "recognizing text" stage it just freezes - wondows says program not responding.

  • Use iMac as monitor for xbox?

    so i've got a iMac and and xbox 360 i noticed there's a mini-DVI port on the iMac is there any way to hook the xbox up to the iMac so it acts like a monitor?

  • Information on  CRM Value Mapping

    hello....... I need to give presentation on CRM Value Mapping. I would be very thankfull, if any one tell me what is CRM Value mapping? Whats the use of it? If you have any material on CRM Value mapping... Best Regards RAJ

  • How to pre-populate a text form?

    I just created a text form and would like to have it pre-populated with the number 1. can someone help me with this?

  • PDF pinch and zoom, panning bug with latest version?

    I have found stumbled upon something strange with PDF folios with Zoom enabled with the latest version. When you zoom in and pan around if you pan left<->right and then try to pan up<->down without releasing the pan, it is locked in a left<->right pa