I have problem with SWT StyledText. I draw new element on StyledText's GC whenever resize or paint event take place. What's more I also force redraw of the whole StyledText in every second.
My problem is that this redraw is sometimes visible because StyledText sometimes funny "blinks".
My question is, is it somehow possible in SWT to redraw only part of the widget, like it is possible in Swing?
You can call redraw(x, y, width, height, false) on the StyleText control to ask for just a part of the control to be redrawn.
Related
I have an application that uses a JLabel and a JPanel. These components have a MatteBorder. When the components are created, the border is the default. When I click on the components, I set the border to a different thickness to make a select appearance. The problem comes when I want to unselect and I set the border to another thickness. This time the border is not modified and looks the same.
I'm not seeing what the problem is, because the first modification of the border thickness works fine.
Although this might be a hacky approach, try to repaint() the view, sometimes it just glitches.
I read this:
http://docs.oracle.com/javase/tutorial/uiswing/components/border.html
when working on my program.
So I wrote a small program for a class. I designed it as a JApplet inside an undecorated JFrame, not in a browser. Other than that, it's a simple drawing program of sorts. You click two points to draw the selected shapes, then it calls a repaint. The problem I'm having is that when you draw while the program has been moved to my secondary monitor, the entire JApplet seems to disappear, only displaying the drawn shape. It only disappears after the 2nd point is selected, so I presume it does this on repaint().
My secondary monitor is using the exact same brand and resolution, even color profile.
Any other technical details, I'm using Java 1.7 (Can't recall which update off the top of my head), Windows 8 Enterprise 64x, using Eclipse's Run button to test.
Thanks in advance for any help!
I am indeed calling getGraphics(); in the init() method of the JApplet..
That is the problem. The Graphics object is a transient thing that will be repainted the very next time the JVM thinks there is any need to do so. That might be triggered by:
Changing the size or location of the window.
Covering it with another program and then removing the covering app.
Adding new components or changing values that are displayed.
See Performing Custom Painting for more details on how to do what you are attempting to achieve. OTOH Swing has a JLabel that can show a BufferedImage. You can use the BufferedImage in the way you want. When it is updated, call repaint() on the label to see the effect.
I was wondering if there is a quick and easy way of trying to position an image at a particular position in GUI. In addition to this is it possible to put Jlables/Buttons on this picture. That picture should only form a section of the JFrame. I know you can use setbounds(width, height, width, height); but this takes alot of accuracy and very hard to get perfectly right.
Don't call setBounds, which implies that you are using a null layout. Always use a layout manager.
One approach would be to add a custom JPanel that overrides paintComponent and calls drawImage(Image, x, y, width, height, ...). JLabels/JButtons, etc. can still be added to the panel.
Don't forget to call super.paintComponent—this will ensure that your child components get painted.
Also, have a look at Background Panel.
I have a JPanel that contains a bunch of Swing JComponents, including some JSeparators that may be only one or two pixels wide. I want to let my users drag the items around, but it can be rather difficult to hit a one or two pixel wide line. Is there a way that I can give those JSeparators a wider "target" region for mouse clicks? The only thing I've been able to think of is to have my mouse handler listen for clicks on the JPanel, and if it gets any, run through the list of JSeparators, looking to see if any of them are within a couple of pixels of the mouse click.
Should that work? Is there a better way?
Add a fat EmptyBorder to the component.
If it already has a border, you can set a compound border using the current border then the empty border, or simpler, add the empty border (and listener) to a panel that contains the component. The latter will work better for components such as JButton, which have borders that change according to state and focus.
I have a shell that contains a canvas, which in turn draws some text in its PaintListener. The problem is, when I dynamically reduce size of the shell with its setBounds method (this is going to happen every once in a while), the text doesn't get redrawn. In fact, the canvas' PaintListener doesn't get called again.
Is there a way to force repaint? I've tried calling canvas.redraw() but this does not work.
Hmm, it appears that I did not set a layout on the shell. After setting a FillLayout, it works.