| | |
Questions about Applet and JFrame
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2006
Posts: 116
Reputation:
Solved Threads: 0
So lets say I want a window in the shape of a circle, I need to have that gray undecorated square window to be transparent such that I can draw a circle such that it looks as though the window is in the shape of a circle. So is there a way to A, get what's displayed behind the window and display it or B, make the gray color be transparent.
Ah, okay, got it. No, there isn't a straight-forward way to make transparent frames like that. The following article discusses a way to hack that effect though through use of screen shots:
http://www.onjava.com/pub/a/onjava/e...k41/index.html
http://www.onjava.com/pub/a/onjava/e...k41/index.html
•
•
Join Date: Oct 2006
Posts: 116
Reputation:
Solved Threads: 0
•
•
•
•
Ah, okay, got it. No, there isn't a straight-forward way to make transparent frames like that. The following article discusses a way to hack that effect though through use of screen shots:
http://www.onjava.com/pub/a/onjava/e...k41/index.html
I guess I'll just have to wait for Sun to develop one.
Anyway I'm having some trouble trying draw stuff and have components.
If want to not have the screen clear (turn gray) and display those component, how do I go about it?
So lets say I have a TextFeild, a JFrame, and a JPanel which the TextFeild goes into. I extend the JPanel and have main in it where I do the drawing with graphics. How do I go about it.
•
•
Join Date: Oct 2006
Posts: 116
Reputation:
Solved Threads: 0
•
•
•
•
Are you wanting to custom paint the background on the panel, yet not affect the text field?
Also I don't want the screen to be cleared every time I change the back ground. So if I change the background, the background is drawn first then the textfeild. Basicaly there's going to be an action listener that will be changing the background over an interval of time.
Last edited by Mr.UNOwen; Jan 2nd, 2008 at 7:43 pm.
If you just override paintComponent() for the JPanel, you shouldn't have any problem.
Java Syntax (Toggle Plain Text)
new JPanel(){ public void paintComponent(Graphics g){ paintPanel(g); } };
•
•
Join Date: Oct 2006
Posts: 116
Reputation:
Solved Threads: 0
Thanks
It even worked with paint.
The only issue I'm having now is I need JFrame to always listen to keyboard, but when I add a textfield it's listening only to the textfield. Also my program will be using the keyboard to navigate, so how do I select and deselect a component such that the arrow keys can be listened to and from there move from component to component?
It even worked with paint.
The only issue I'm having now is I need JFrame to always listen to keyboard, but when I add a textfield it's listening only to the textfield. Also my program will be using the keyboard to navigate, so how do I select and deselect a component such that the arrow keys can be listened to and from there move from component to component?
Last edited by Mr.UNOwen; Jan 3rd, 2008 at 12:10 am.
•
•
Join Date: Oct 2006
Posts: 116
Reputation:
Solved Threads: 0
I just swiched TextField for JTextFeild and only the back ground or the Jtextfield only depending on whether I override paint (background shows) or PaintComponent(jtextFeild shows).
EDIT:
Never mind, I just had PaintComponent and not paintComponent.
The only issue I'm having now is I need JFrame to always listen to keyboard, but when I add a textfield it's listening only to the textfield. Also my program will be using the keyboard to navigate, so how do I select and deselect a component such that the arrow keys can be listened to and from there move from component to component?
EDIT:
Never mind, I just had PaintComponent and not paintComponent.
The only issue I'm having now is I need JFrame to always listen to keyboard, but when I add a textfield it's listening only to the textfield. Also my program will be using the keyboard to navigate, so how do I select and deselect a component such that the arrow keys can be listened to and from there move from component to component?
Last edited by Mr.UNOwen; Jan 3rd, 2008 at 12:48 am.
Add your key bindings to the JFrame itself like so
java Syntax (Toggle Plain Text)
JRootPane root = frame.getRootPane(); root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( KeyStroke.getKeyStroke(KeyEvent.VK_UP,0),"UpAction"); root.getActionMap().put("UpAction",new AbstractAction(){ public void actionPerformed(java.awt.event.ActionEvent e){ upAction(); } });
![]() |
Similar Threads
Other Threads in the Java Forum
- Previous Thread: Creation of file types and encryption
- Next Thread: adding a JFrame component to JTabbedPane
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint 2dgraphics android api apple applet application applications arguments array arrays automation bank binary bluetooth chat class classes client code collision component database db development draw eclipse eclipsedevelopment error event exception file fractal game givemetehcodez graphics gui helpwithhomework homework html ide image input integer integration j2me jarfile java javadesktopapplications javafx javaprojects jmf jni jpanel julia learningresources linux list loop map method methods mobile netbeans newbie number object oracle print problem program programming project projectideas recursion researchinmotion scanner screen server service set size sms socket sort sorting sql sqlserver state string swing swt tcp test text-file threads time tree web windows






