2

Using Cobra, I have a void function which will scroll to a given node of a dom tree or a given pixel of the htmlpane. When I use JFrame.setContentPane() function to set the htmlpane as the container, and I use the scroll() function to scroll the specefic point, it's not working.

Here is the code:

HtmlRendererContext rendererContext = (HtmlRendererContext) new  LocalHtmlRendererContext(htmlPanel, uAgent);
DocumentBuilderImpl builder = new DocumentBuilderImpl(uAgent, rendererContext);
Document document = builder.parse(url);
JFrame frame = new JFrame();
htmlPanel.scroll(500, 300);
//frame.getContentPane().add(htmlPanel);
frame.setContentPane(htmlPanel);

and if you see the following code:

frame.setContentPane(htmlPanel.scroll(500, 300));

it says:

no void function allowed here.

trashgod
  • 203,806
  • 29
  • 246
  • 1,045
lonesome
  • 2,503
  • 6
  • 35
  • 61

1 Answers1

2

I am not familiar with the Cobra API you are using but in most cases GUI components have to lay themselves out before you can scroll. This is because before you add a component to a container it does not know what size it will be. Try delaying the scroll and see if it helps:

frame.setContentPane(htmlPanel);
frame.setVisible(true);
SwingUtilities.invokeLater(new Runnable() {
    @Override
    public void run() {
        htmlPanel.scroll(500, 300);
    }
});
Russ Hayward
  • 5,617
  • 2
  • 25
  • 30
  • where should i put it? before frame.setsize(); or after it? – lonesome Feb 26 '12 at 09:43
  • i copy pasted your code and rerun the program but nothing changed – lonesome Feb 26 '12 at 09:54
  • Try after frame.setVisible(true). – Russ Hayward Feb 26 '12 at 12:55
  • it worked out where ever i put the code, the only fault i did , was to include set.visible(); part of your code in my program then it repeated twicw and then no action, but now it's working, thank you anyway ;) – lonesome Feb 27 '12 at 05:31
  • now the above problem is been solved but there is a new problem arises that you can read about it here [link](http://stackoverflow.com/questions/10377859/scrolling-to-the-other-part-of-the-webpage) just in case if you dont mind :d – lonesome May 02 '12 at 07:55