Repaint in AWT Component
Could anybody tell me, haw can i do so, that when one component is overlapped by another one, and after that the first component will be visible again, i do not need to repaint (a part of) the first component?
CardLayout can unfortunaly display only one card at the same time. I m talking about my derived classes from JPanel. But i need all my objects be displayd at same time, may be overlapped(they are all dragable). And it were super, if paint(Graphics) would not be called each time, as "closed" object is visible again. Can i do so, that ovelapped area leaves in memory and dont need to be paint again. Or not?
P.S. I am making a Drawing-like Tool, where PDF-rendering is needed. I could render only a PDF-area, that is currently needed. So i can zoom so much as i want without loss of quality. But unfortunaly this is to slaw and i need to optimize that.
Similar Messages
-
Foreground Color of a Disabled AWT Component
How do you change the foreground color of a disabled AWT component?
You would have to write your own renderer that checkes to see if the component is enabled or disabled. Your renderer would then draw the component as you like in both of those states.
-
How to remove the border from an AWT Component (specifically a ScrollPane)
I've been trying to remove the border from an AWT ScrollPane, but having no luck.
I've tried setting the bounds on the ScrollPane to get rid of the border:
ScrollPane scrollPane = new ScrollPane();
scrollPane.setBounds(-2, -2, getSize().width+4, getSize().height+4);
I've also tried overwriting the paint method of the ScrollPane but it didn't draw anything:
private class CustomScrollPane extends ScrollPane
public void paint(Graphics p_g)
super.paint(p_g);
Graphics2D g2 = (Graphics2D)p_g.create();
g2.setColor(Color.MAGENTA); //tried magenta so I could easily see it
g2.drawLine(0, 0, 0, getSize().width);
Is there anything else I should try? (I wish AWT components had a setBorder method)Is there anything else I should try? (I wish AWT components had a setBorder method)Actually this probably isn't possible. One of the main drawbacks of AWT was that since everything is connected to peers, you can't actually draw over or customize the view of your AWT component.
The only recommendation I might make would be that you could try creating Canvases around your ScrollPanel that draw over the border -
dear friends;
i have added menu bar in Jframe which is containes menues.
AWT component is added the the same frame .
problem is:
menues are overlapping with awt component while i clicked the menu bar.
dear friends help me immediately.
thank udear friends help me immediately.It's your own fault or combining Swing and AWT widgets. You're not supposed to do that, as it can lead to strange effects. Like this one.
-
An Awt Component Identifying Its display Status
I am writing a custom Component (one extending java.awt.Component) for a game which would be running under Applet. Is it possible for a Component to identify if the Applet window (the browser) is put into the background, minimised or hidden? The Component.isShowing() call seems to return true regardless of the status of the browser window. I don't want to rely on Applet.start()/Applet.stop() and want each Component to be able to do this. Is it possible?
Edited by: alec_lee_yl on Jan 28, 2010 5:39 PMIf you use a fixed-width font then you will be able to pad the strings with the right number of blanks and get your columns to line up.
-
Synchronization on awt component
I was facing some deadlock issues on the awt component and trying to resolve the problems. I have searched using google and also in this forum but not much information that i can found. Anyone have some good article on sychonization on awt component ?
By the way, I have some question on the synchronization issues on awt component. Questions as below :
1. we should only synchronize out component by synchronized on getTreeLock() ? From what i know is that anything to do which layout and changing the structure of tree of awt component should synchronize the tree lock. Am i correct on this ?
2. since paint() method only being execute by AWT-Thread (correct ?), the paint() method shouldn't be synchonized ? If I was refering to a lot of informations in my paint method when doing painting, how i can make sure those informations/data was synchronized ?
3. It was recommended that any layout process of component should be done by AWT-Thread (Event Dispatching Thread) ? Currently my product have to compatible with jre 1.1. which invokeLater() only introduced in java 1.2. How can I layout my component in AWT-Thread ?Hi!
Sorry to read that. Unfortunately, Firefox Sync is not a back up service and the information is stored in the servers only temporarily so the rest of your devices can get the information. -
How to return the hWND of a JDialog or AWT component?
can anyone help me try and return the handle for a JDialog or a AWT component? I just don't seem to be able to get anything to work, and any references to code all come from 2002 and i'm not sure if it works in Java 1.5
I'm trying to return the handle of a JDialog, could anyone help me do this?
Thank you :)can anyone help me try and return the handle for a
JDialog or a AWT component? I just don't seem to be
able to get anything to work, and any references to
code all come from 2002 and i'm not sure if it works
in Java 1.5
I'm trying to return the handle of a JDialog, could
anyone help me do this?
Thank you :)Do not know what a hWND is. By handle do you mean reference? if that's what you mean just pass the Object. As to the code working in v1.5 ... try it and see. -
hi,all
In my applet, there are many awt component,such as Button,Choice,and many string draw by paint() method.in windows platform,the awt component and the draw string has the same default font size,
but in Mac os x, the awt Compoment's font size is bigger than the draw string's font size,so the user interface is very ugly,
because of large amount of applets,set ervery component or draw string's font size is very difficult.
is there any way to solute this question? someoen has tell me to modified the jvm's parameter of Max os x,
but i cound not find where to setting the font parameter?
please help me! thanks.Call g.setFont(myFont) before DrawString.
You could try to call getFont() on one of your awt components, or code this table:String os=System.getProperty("os.name");
os.indexOf() Font(name)
Macintosh Charcoal
Unix (Dont know)
Windows MS Sans SerifgetFont is preferred. -
Add a AWT component to a SWT widget
Hello,
is it possible to add a AWT component to a SWT widget?
I have a Java3D canvas witch exetends from java.awt.component and i want to display it in my application witch uses SWT, but i can't find a way :-(
Can you help me?
StevIf it only takes other SWT components, then no. If it takes any AWT Component, then yes. But I can't find the API docs to look it up. So if you are using it, presumably you have the API docs and should thus look there for the answer... or try it, as it would've taken less time waiting for this ignorant answer.
-
Hi all,
I have a problem with JSplitPane, I use it with JPanel as right component and an AWT component as left Component, so when I move The Divider of the JSplitPane it hides under the AWT component not on the top of it.
I know that result from problem of heavy weight component and light weight component .. but my question is there any work arround I can do to make the Divider appear on the top of the AWT component??
Thanks,You've been given an idea: DO NOT MIX AWT and SWING Components.
Why do you need to mix them? What is the AWT component?
If it's something you wrote yourself, then you can change it. If it's not, decompile it and change it. Anyone who can't provide a Swing version of their stuff at this point is out of business and shouldn't care what you do with it.
If it's some Canvas subclass, you can make it a Swing component by changing 2 lines: extends JPanel instead of Canvas and change paint() to paintComponent().
is there any work arround I can do to make the Divider appear on the
top of the AWT component??definitely not, unless you make the divider a heavyweight component somehow. -
Changing custom AWT component to Swing component
I created my own AWT component. I'd like to change it to Swing component.
Does anyone know how to change or create a custom Swing component?
Please also provide some framework to develop a custom Swing component.First try to know the difference between SWING & AWT. You can either adopt to SWING or AWT but be specific of what you want to do !
If you like to migrate from AWT to SWING ,then make the necessary changes in your coding.(ie, re frame things like , Frame to JFrame , Button to JButton ,JTextField to JTextField etc..)
For creating custom components ,say a component called MyLabel and you should design a class which extends JLabel and do whatever you like...
eg import javax.swing.*;
public class MyLabel extends JLabel
MyLabel(String title)
this.setTitle(title);
this.setBackground(Color.white);
this.setForeground(Color.blue);
}For more details go to java tutorials. -
Is it possible, and if it is, how can I create completely new gui component using awt?
Sure. Just extend Component and override the paint method to draw it the way you want. Add a mouse listener to capture clicks or drags and do whatever you want with those, etc. I create new Swing components with special behavior all the time. (I don't think I've ever done one in pure AWT, but the principle is the same.) My variations tend to be trivial, like labels with text that wraps to the available space instead of a single line, not stuff that is going to set the computer world on fire. Depening on how complex the new component you want to invent is, this might be far from a trivial task. But it's certainly do-able.
-
Repaint() Issues with component
Hi.
I'm creating a Swing GUI using a JTree component. The particular setup I want is a JSplitPane
containing some functions in the top pane and the actual JTree displaying some data and possibly the resulting changes when any of these functions are used.
The problem I was having was in trying to update the JTree object after the user presses one of the
function JButtons on top. I have a call to repaint() as part of my event-handling code after the JButton's
procedure completes. However, since the JTree is generated using a separate method (i.e. im passing
in a TreeNode), the repaint() doesn't do anything.
The one thing that I've considered is extending the JTree class and overriding its repaint() method to
include that separate method call, but Is there any more elegant or standard way to do this that I'm not seeing?
Thanks in advance.There is paintImmediately() method. You can also try to use
SwingUtilities.invokeAndWait call to let your tree be repainted.
regards,
Stas -
Repaint/Refreshing AWT components
Hi there,
I'm writing a chess game and for the GUI I've added 8x8 panels into a frame with a grid layout. Currently I'm just using labels for the pieces, in the middle of panels. I'm having a problem updating my GUI after a move has been made - a call to repaint() does nothing. I'm just using basic AWT.
I've also tried removeAllComponents() of the frame and adding them again with the updated data, but nothing happens - I just lose all my panels. Can anyone help please?
Many thanks!scsi-boy :
I want to have a more general method of refreshing the
graphics so that later if/when I 'upgrade' to using
images (or whatever) instead of labels I can simplyi believe my suggestion is certainly compatible with that.
adapt it. I would think that calling setText for the
Labels would mean that I would have to give the
location of the panel as a parameter somewhere, and
would also have to remove the label where the piece
was previously (ie if a knight moves, I'd have to
target its destination to setText and remove it from
where it was).here is what i would do, please note that this will work with a variety
of implementations including using all Graphics later on or whatever.
// here we have a bunch of constants that represent the possible status
// of board postions
final int EMPTY_SPACE = 0;
final int B_KING = 1;
final int W_KING = 2;
final int B_QUEEN = 3;
final int W_QUEEN = 5;
final int B_BISHOP = 6;
final int W_BISHOP = 7;
final int B_KNIGHT = 8;
final int W_KNIGHT = 9;
final int B_ROOK = 10;
final int W_ROOK = 11;
final int B_PAWN = 12;
final int W_PAWN = 13;
// the game board is used to store the status of all the postitions in
// a game
int[][] gameBoard;
// the game display is the array of Labels that we use to present the
// board in our GUI
Label[][] gameDisplay;
// in the constructor;
gameBoard = new int[8][8];
for(int i=0;i<gameBoard.length;i++){
for(int j=0;i<8;j++){
gameBoard[i][j] = EMPTY_SPACE;
// here is where you would add the various pieces to gameBoard...
gameDisplay = new Label[8][8];
Now wherever you interaction and logic are you can use a method. You
can call this method repaint(); so that it will be compatible with
what you do later.
public void repaint(){
for(int i=0;i<gameBoard.length;i++){
for(int j=0;j<8;j++){
switch(gameBoard[i][j]){
case B_KING:
gameDisplayj].setText("Black King");
break;
case W_KING:
gameDisplay[i]j].setText("White King");
break;
case B_QUEEN:
gameDisplay[i]j].setText("Black Queen");
break;
// and so on and so forth... until
default:
gameDisplay[i]j].setText("");
anyway the above code is just a sample of how you can build this so you
can seperate out your logic from your GUI so you can change your GUI
later without hassle.
finally i would ask how are you changing the text on the screen. are you
creating new Labels and sticking them in the Panels? i suspect something
like this... don't do that. two reasons, one as you may have noticed it
doesn't work that way or you have to use some sort of hack to get it to
work and two it's more efficient in terms of memory and speed if you
re-use the awt ot Swing components by making use of methods such as
setText rather than creating new objects each time.
i hope you find this helpful. -
Hi all
i have four classes plot , plot3d, plotsurface and test
plot is derived from JPanel and plot3d and plotsurface extend plot class
i am trying to do a very simple operation . just making a tool bar with 2 buttons to switch between plots .
the 2 plot classes plot3d and plotsurface just draw a line on the screen
problem is that when the user clicks one button it doesnot show up on the screen but when the window is resized it does call paint component of the corresponding class
can Any one explain why this is happening......
package test;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
public abstract class plot extends JPanel {
plot()
public void paintComponent(Graphics g)
Graphics2D graphics2D=(Graphics2D)g;
super.paintComponent(g);
package test;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
public class plot3d extends plot {
plot3d(boolean resizable)
public void paintComponent(Graphics g)
Graphics2D graphics2D=(Graphics2D)g;
super.paintComponent(g);
graphics2D.drawLine(200,200,320,320);
package test;
import javax.swing.*;
import java.awt.Graphics;
import java.awt.Graphics2D;
public class plotsurface extends plot {
plotsurface(boolean resizable)
public void paintComponent(Graphics g)
Graphics2D graphics2D=(Graphics2D)g;
super.paintComponent(g);
graphics2D.drawLine(120,120,140,140);
package test;
import java.awt.*;
import javax.swing.*;
import java.awt.Graphics2D.*;
import java.applet.*;
public class Test extends javax.swing.JApplet {
private Container container;
public Rectangle rect;
JPanel toolBar;
JButton contourButton;
JButton surfaceButton;
JPanel toolPanel;
public Graphics g;
public test.plot3d graph3D;
public test.plotsurface graphSurface;
private int plotType=0;
private void graph3D(Graphics2D g2)
graph3D=new plot3d(false);
public void graphSurface(Graphics2D g2)
graphSurface=new plotsurface(false);
private void changeplottoContour()
if(plotType==0)
return;
plotType=0;
g=container.getGraphics();
Graphics2D g2=(Graphics2D)g;
container.removeAll();
repaint();
graphSurface=null;
System.gc();
graph3D(g2);
container.add(toolPanel,BorderLayout.NORTH);
container.add(graph3D,BorderLayout.CENTER);
private void changeplottoSurface()
if(plotType==1)
return;
plotType=1;
g=container.getGraphics();
Graphics2D g2=(Graphics2D)g;
container.removeAll();
repaint();
graph3D=null;
System.gc();
graphSurface(g2);
container.add(toolPanel,BorderLayout.NORTH);
container.add(graphSurface,BorderLayout.CENTER);
private void surfaceButtonActionPerformed(java.awt.event.ActionEvent evt)
changeplottoSurface();
repaint();
private void contourButtonActionPerformed(java.awt.event.ActionEvent evt)
changeplottoContour();
repaint();
public void init()
container=getContentPane();
g=container.getGraphics();
Graphics2D g2=(Graphics2D)g;
Rectangle r1= new Rectangle();
rect=new Rectangle();
//r1=container.getBounds();
toolPanel= new JPanel(new BorderLayout());
toolBar = new JPanel();
contourButton = new JButton("Contour");
toolBar.add(contourButton);
contourButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
contourButtonActionPerformed(evt);
surfaceButton = new JButton("Surface Plot");
toolBar.add(surfaceButton);
surfaceButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
surfaceButtonActionPerformed(evt);
toolBar.setBackground(Color.white);
toolPanel.add(toolBar,BorderLayout.NORTH);
container.add(toolPanel,BorderLayout.NORTH);
Rectangle r2= toolPanel.getBounds();
Dimension appletSize = this.getSize();
int appletHeight= appletSize.height;
int appletWidth= appletSize.width;
rect.setBounds(0,(int)r2.getHeight(),appletWidth,appletHeight-(int)r2.getHeight());
plotType=0;
graph3D(g2);
container.add(graph3D,BorderLayout.CENTER);in your button action listeneres (e.g. contourButtonActionPerformed()) don't only call repaint(), but update(this.getGraphics());
this should help in most cases. other refreshing methods are:
java -Dsun.java2d.noddraw=true HelloWorld
java.awt.Component.repaint()
java.awt.Component.update(Graphics) (e.g. c.update(c.getGraphics());)
java.awt.Component.validate()
javax.swing.JComponent.revalidate()
javax.swing.JComponent.updateUI()
javax.swing.SwingUtilities.updateComponentTreeUI(java.awt.Component)
Maybe you are looking for
-
How to use Logical database in function module?
I will create a function module in HR. but how to use Logical database in function module ? Logical database PNP always show screen.in function (RFC) code , it is a matter.
-
For various reasons we are using W7 but still on IE8. There is an option in IE8 i want to change but i am not able to find out in GPO. The setting is in Internet Explorer > tools > internet options > security tab > internet zone > custom level > la
-
Hi I want to Sort an array elements with help of Row 0 in the order of another array. Thanks Attachments: Array.vi 7 KB
-
How to kill the present data load
Hi All, I am loading data into a masterdata object and found that it is takign too long. The status is still Yellow color. I want to stop this loading and do some changes and then want to load it again. How can I stop the present load? Thanks, RPK.
-
現在.NI cRIO-9012 CompactRIO Real-Time Controllerを利用しております.別の計算機からFTP 及び Measurement & Automation Explorer で9012にアクセスすることはできますが.sshでアクセスすることは可能でしょうか? なお.調べた限りcRIO-9012のOSはVxWorks 6.3のもようです.