Simplifying, I have this structure
Form {
tab=Container(BoxLayout.y());
other stuff
}
The Form is not scrollable (and it is not supposed to be), tab is.
At some point I want to redraw the Form to keep it up to date with some new info added, and I do that creating a new one and showing it.
But I want to scroll down the Container tab to its predecessor's Y-coordinate.
I can easily save the Y coordinate in a static variable using
scrolledToY=tab.getScrollY();
But I can't find a way to set it back when I create the new form.
setScrollY seems to be protected, and indeed if I try to run the program using it, I get an error
error: setScrollY(int) has protected access in Component
tab.setScrollY(scrolledToY);
What is the correct function to use, instead?
Thanks.
You can use scrollRectToVisible().
FYI you can just modify the container and call revalidate to update the UI. This will prevent a nasty refresh problem you might experience. Also check out InfiniteContainer which might be what you're really looking for.
Related
Using Apache Batik,
Trying to get the JSVGComponent to update (repaint) after adding a new svg element to the DOM. I know about ALWAYS_DYNAMIC, and that is set. The new element(s) are successfully added to the document, but the only way I can get the component to repaint is to resize the view. Upon resize, the new elements pop (appear) into place. I have also tried to add the elements via a Runnable using the UpdateManager and the RunnableQueue. Again, the elements are successfully added, but don't appear until the component is resized (by resizing the housing frame). I have also tried invoking the repaint via a RunQ Runnable, but that also does not work (tho the repaint is actually called).
I think I may have to actually go into the GVT bridge, but I'd sure rather not.
Help extraordinarily appreciated. Thx.
Almost same problem for me : I had to dynamically modifiy the background of boxes (polygon node).
According to MelodyBibi, it works with setSVGDocument(doc); but the SVG flashes during refresh. It's not very appreciable.
My (better) solution is to call
svgCanvas.getCanvasGraphicsNode().fireGraphicsNodeChangeCompleted();
after modifying the DOM model using polygonElement.setAttribute("fill", "red"); on the appropriate Node.
I also added JSVGCanvas.ALWAYS_DYNAMIC before the first loading of the document.
Now my SVG refreshes in realtime, without blinking.
Hoping this will help you.
You can do
svgCanvas.setDocument(doc);
It's works for an JSVGCanvas, may be it will works for you.
You can also try method :
setSVGDocument(doc);
I found this :
There are two common causes for this. The first is that the JSVGCanvas doesn’t know it’s a dynamic document. Normally Batik detects this by looking for script elements but when you modify the document from Java it can’t tell. So call myJSVGCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC); before loading the document (with setURI, setDocument, setSVGDocument, etc.).
The second common reason is that the changes aren’t made in the UpdateManager ’s thread. You can run code in the UpdateManager ’s thread with the following: UpdateManager um = JSVGCanvas.getUpdateManager(); um.getUpdateRunnableQueue().invokeLater(Runnable); NOTE: The update manager only becomes available after the first rendering completes. You can be notified when this happens by registering a GVTTreeRendererListener.
But i don't try this yet.
I am writing a browser based application using GWT and making use of websql (yes, I know it is deprecated). I have created a custom table widget (based on FlexTable) and enabled it to scroll with the help of some CSS trickery. What I am striving to achieve (without much success) is that when the user scrolls to the start/end of the current data in the table, an event is fired and the next subset of X rows is returned from the websql DB and replaces the data currently in the table. In order for this to work, I need to keep track of the data offset in the table widget so that I can pass this to the query and use the limit and offset functions of SQL to return the required data. However, I just cannot seem to get the logic right to implement the data offset tracker within the widget. Another complication is that I need the table to be able to scroll 'into the past' (so to speak), so that it can retrieve data from before the initial start point when the table loads.
I have been at this for a number of days now and just cannot seem to get it right. So I was wondering/hoping that someone might be able to point me in the right direction (PLEASE!).
Thanks in advance
Tim
I am not sure why this is causing a problem.
int page = 0;
// when you hit the bottom
page++;
loadData(page);
// when you hit the top
if (page > 0) {
page--;
loadData(page);
}
Tim I think it is not a good idea controlling the scroll with CSS trickery.
I have done something similar soon and controlling all the logic (pagination, scroll positions,...).
What I suggest to use is a gwt's scrollPanel, a HasData widget (like a cellList) your custom AbstractCell (class which is rendered for each row of your list) and asyncDataProvider ( which gives you the onRangeChange handler for asking to your server when the range data display has changed).
You can force/fire that event when in scrollPanel.addScrollHandler detects you are arriving to the end.
If you want to see all of this in action have a look into (click on source code): http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellList
EDIT [according comment below]:
A. If you want to override the data (in the example is X+X+X...) with the new retrieved just maintain always the same range of data displayed [display.setVisibleRange(0, newPageSize);], and start from 0 when you render the new data (on your RangeChange listener).
B. If you need to have control over up and down scrolls instead of taking advantage of the used events internally on the cellList (basically onRangeChange), you can create your custom events and fire them (this option could be easier for your colleagues for understanding everything). And do not worry about controlling up and down scrolls, inside the ShowMorePagerPanel.java you can see a simple example of knowing up and down controls.
Anyway, I did not explain more detailed because I did not see you very convinced to use CellList approach (and I was using my tablet :D ).
If you change your mind, just let me know and I write for you a proper example step by step (this part could be tricky, so if you are lost it is normal ;) ).
I'm currently attempting to use the openoffice API to display a powerpoint presentation from Java - I've got a fair way in that I've managed to open a presentation and display it. However, there's a couple of things that I'd like to be able to do I can't figure out with the API as it stands:
I don't want the main Impress window to appear, just the presentation window. Now, I can start it minimized no problem with a property, but then the actual presentation window is minimised as well, which I don't want. I can also grab the window and call setVisible(false) on it, but it's still visible for a second or so while it's loading.
I want to be able to control the monitor which the presentation appears on (I'm using it in a multi-monitor setup.) I thought I might be able to grab the Window of the presentation and move it around that way as I need to, but I can't see how - for the main window I can do something like:
XModel xModel = UnoRuntime.queryInterface(XModel.class, xDrawDoc);
xModel.getCurrentController().getFrame().getContainerWindow().blah();
...but I haven't yet found a way to get the presentation Window. I'd like to be able to set the bounds of the window directly (x, y, width, height) rather than just being constrained by positioning on a single monitor.
I can live with the first point, the critical one I need to solve for my use case is the second.
Any ideas on the above? I'm an experienced Java programmer but new to UNO.
Seems the second point can be solved, ish, with the display property:
public void start() {
try {
xPresentation.setPropertyValue("Display", 1);
}
catch (Exception ex) {
ex.printStackTrace();
}
xPresentation.start();
}
Note however a few of things - firstly the display index is base 1, not 0. Secondly, trying to set the properties in an array and passing them to xPresentation on creation didn't seem to have any effect - it only worked for me setting the property later as above. Thirdly, it doesn't allow fine grained control over the window as I wanted, just control of the display the presentation appears on.
I have a custom component based on the JSlider. It's essentially the same thing only it has 2 thumbs, which I named a DualSlider.
I need to change the maximum value of the slider once in a while, so every time I do, I call updateUI to reflect this.
public void updateUI() {
this.setUI(new DualSliderUI(this));
this.updateLabelUIs();
}
However, the maximum value of the DualSlider when I try to use it is still set at the original value no matter how many times I try to change it while using my program. I can confirm with a few println statements that a new DualSliderUI is being made with the slider that has the new max value, but for whatever reason the original DualSliderUI I initialized the slider with is the one that is in use.
What other things do I have to make sure I do when I update a property so I can avoid this?
1) I can't see reason for usage updateUI() this should be done once time, only when you built this JSlider, never do that repeately
2) you have look at BoundedRangeModel, maybe
I'm trying to get data for my application from a form set in an external window (getDataWindow extends javax.swing.JFrame). The problem is that functions are executed before form is filled in.
getDataWindow dataW=new getDataWindow();
dataW.setVisible(true);
size=dataW.returnSize();
I've tried also adding additional boolean variable to getDataWindow
getDataWindow dataW=new getDataWindow();
dataW.setVisible(true);
while(!dataW.checkIfReady()){wait();}
size=dataW.returnSize();
But it makes also the window wait (it appears but it's black inside and nothing happens).
I think i should create some threads for that - I've tried to call a window making function getDataWindow in java.awt.EventQueue.invokeLater(new Runnable()) but I had to initialize dataW earlier so dataW.checkIfReady() could be called, so it is a catch 22.
Have you tried adding a listener in form contained fields ? I know you don't have full control over that class, but, well, it's some java code ! Run it in your debugger, and you'll see the code organization for that DataWindow. Then, you'll be able to add a Key/Action/Anything/Listener to trigger your code execution.