JWindow
hallo,
I want to create JWindow with a border what is to do ???
thanks
Sorry, JWindow myWindow = new JWindow();
JPanel myPanel = new JPanel();
myPanel.setBorder(BorderFactory.createLineBorder(Color.black));
myWindow.getContentPane().add(myPanel);
myWindow.setLocation(500,500);
myWindow.setSize(100,100);
myWindow.show();
Similar Messages
-
Preload an image before JWindow appears
is this accomplished with a thread?
threads are the one territory im afraid to wander in, haha.
I have a JWindow that is opening with only one image in it.
However, as it is now the JWindow coems up immediately
and there it is a LONG time before the image appears.
any suggestions? thanks!
i have this as a class variable
static Image image = Toolkit.getDefaultToolkit().getImage("img/MercLogo.jpg");
i open the Jwindow, put in a JPanel then drawImage.How about not putting the image loading as part of a static field. Instead do something like
public void openWindow() {
java.awt.image.BufferedImage bigImage = javax.imageio.ImageIO.read(resource);
// jwindow stuff
}ImageIO.load is a synchronous method, only returning when the entire image data is bufferred in memory. The Toolkit method returns an asynchronous image which loads its data when requested. -
Display image in JWindow..
please tell me how can i display and jpg image on JWindow.
BufferedImage img = ImageIO.read(new FileInputStream("img.jpg"));Or better yet, load it from the classpath rather than relying on the file being in a particular directory relative to where your app started.
Change:
new FileInputStream("img.jpg")
To:
getClass().getResourceAsStream("/img.jpg")
And make sure the directory containing img.jpg is included in the classpath. -
How can I make a default border for a JWindow?
I have a JWindow object that is created when a button is pressed in a JFrame. I want the JWindow to have the same type of border as the JFrame from which it's created. However, the JWindow is not created automatically with a border as the JFrame is, so I don't know how to set the border abstractly so that whatever border is used for the JFrame, per he default L&F, will also be used for the JWindow.
I tried grabbing the border object from the JFame instance itself, but there is no such field in JFrame or any of its ancestor classes. I looked at UIDefaults, but I have no idea how this class can be used to get what I want. For example, if I use UIDefaults.getBorder(Object obj), what do I specify for the argument?
I'd be happy with an abstract or a concrete solution. That is, either using the default Border for top level containers in the current L&F, or by grabbing an actual Border instance from a JFrame object.
-MarkAlso, I'm curious why you said that JFrame is not a swing component.A Swing component extends JComponent. Basically this means that all the painting of the component is done in Java. You can add Borders to any Swing component. It is called a light weight component. A light weight component cannot exist by itself on the window desktop.
JFrame, JDialog and JWindow are top level components. They can exist on their own on the windows desktop because essentially they are Windows native components. They have been fancied up to make it easy for you to access and add other Swing components to it which is why they are found in the swing package.
A Windows border is not the same thing as a Swing Border and there is no way to access the native windows border and use it in a Swing application (that I know of anyway). Swing Borders are not used in a normal JFrame, the Windows border is used. You can however, turn off the use of Windows decorations and use Swing painted decorations. Read the tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/components/frame.html#setDefaultLookAndFeelDecorated]Specifying Windows Decorations. However, this doesn't really help you with your Border problem. If you look at the source code for the FrameBorder, you will find that the "blue" color of the Border is only painted for "active" windows and a JWindow can never be the active window, only the parent JFrame or JDialog is considered active.
Here is a simple program for you to play around with:
import java.awt.*;
import javax.swing.*;
import javax.swing.border.*;
public class FrameDecorated
public static void main(String[] args)
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation( JFrame.DISPOSE_ON_CLOSE );
frame.setSize(300, 300);
frame.setVisible(true);
Border border = frame.getRootPane().getBorder();
// Border border = UIManager.getBorder( "RootPane.frameBorder" );
System.out.println( border );
JWindow window = new JWindow(frame);
JPanel contentPane = (JPanel)window.getContentPane();
contentPane.add(new JTextField(), BorderLayout.NORTH);
contentPane.setBorder( border );
window.setSize(300, 300);
window.setLocationRelativeTo( null );
window.setVisible( true );
System.out.println("Window:" + window);
Window ancestor = SwingUtilities.getWindowAncestor(contentPane);
System.out.println("Ancestor:" + ancestor);
System.out.println(ancestor.isActive());
System.out.println(frame.isActive());
} -
How to close JWindow and keep it front
my main opens a fullscreen jframe and then a smaller Jwindow.
i called toFront but the Jwindow is always hidden behind
the jframe. how do i keep jwindow in front ALWAYS.
also, i have a mouselistener in the jwindow (that works fine)
and im calling
window.setVisible(false);
window.dispose();
but the jwindow is never disappearing.
anybody have any suggestions? thanks!I can't reproduce your problems. Here's my code.import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Test3 extends JFrame implements ActionListener {
JWindow jw = new JWindow(this);
JButton jb = new JButton("Show");
public Test3() {
jw.setBounds(100,100,100,100);
jw.getContentPane().add(new JLabel("I am Window!", JLabel.CENTER));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Container content = getContentPane();
content.add(jb, BorderLayout.SOUTH);
content.setBackground(Color.pink);
jb.addActionListener(this);
setSize(300,300);
setVisible(true);
public void actionPerformed(ActionEvent ae) {
if (jb.getText().equals("Show")) {
jw.setVisible(true);
jb.setText("Hide");
} else {
jw.setVisible(false);
jb.setText("Show");
public static void main(String[] args) { new Test3(); }
} -
Urgent Help jdk 1.4.2 JWindow and Text Field
Go thgh this code pls
import java.awt.*;
import javax.swing.*;
class Test1 extends JWindow
TextField tf;
public Test1()
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
tf = new TextField(10);
contentPane.add(tf);
public class Test extends Test1
public static void main(String[] args)
Test1 t = new Test1();
t.setSize(300,200);
t.show();
when the above application is compiled and run using jdk1.4 0r above the text field gets disabled. ie nothing gets entered in the text field.
However if i extend JFrame instead of JWindow then everything is fine.
Also note that the same code compiles and runs perfectly on 1.3.1 ie even if i extend JWindow i am able to enter text in text field.
Pls help asapthis works because theres an owner frame behind the window:import java.awt.*;
import javax.swing.*;
class Test extends JWindow
static TextField tf;
public Test(JFrame owner)
super(owner);
Container contentPane = getContentPane();
contentPane.setLayout(new FlowLayout());
tf = new TextField(10);
contentPane.add(tf);
public static void main(String[] args)
JFrame frame = new FrameForWindow();
Test t = new Test(frame);
t.setSize(300, 200);
frame.setVisible(true);
t.setVisible(true);
class FrameForWindow extends JFrame{}regards,
Tim -
Hi all,
I have a very important question....
I created a small application and when i launch it, i'd like to have a JWindow displayed on my screen only during 5 seconds.... So i run my application, my JWindow is displayed during 5 seconds and then the application "really" begins.
But how do i have to proceed to have my JWindow displayed only during 5 seconds and then close automatically???
Thanx very much for helping....import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.Timer;
public class SplashWindow
public static void main(String[] args)
JFrame f = new JFrame();
showSplash(f);
JPanel panel = new JPanel();
panel.setBackground(Color.red);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().add(panel);
f.setSize(400,300);
f.setLocationRelativeTo(null);
private static void showSplash(final Component c)
JLabel label = new JLabel("hang on, it's coming...", JLabel.CENTER);
final JWindow w = new JWindow();
w.getContentPane().add(label);
w.setSize(200,200);
w.setLocationRelativeTo(null);
w.setVisible(true);
final Timer timer = new Timer(5000, new ActionListener()
public void actionPerformed(ActionEvent e)
w.dispose();
c.setVisible(true);
timer.setRepeats(false);
timer.start();
} -
JWindow, JPopupMenu and flicker.
I've trawled through earlier posts to these forums and found problems which, from their description, appear similar, but I haven't been able to find any answers that work for me. I would be very grateful for any assistance.
I have a JWindow sized to fill the entire screen. This JWindow contains a subclass of JPanel which draws a diagram. The user clicks on elements of the diagram and pops up a JPopupMenu to select actions. JPopupMenu.show() is called with the JPanel as the invoker argument and x and y coords calculated so that it is always contained within the JPanel. As the JPopupMenu is shown and hidden there is a very noticable flicker.
However, when the JPanel is contained in a JFrame there is no flicker.
At first I thought this was a double buffering problem, but this doesn't seem to be the case.
Any thoughts?
Thanks.Try to call the JPopupMenu on a new Thread.
Noah -
Jpopupmenu visibility problem with JWindows
Hello,
BACKGROUND:
I am attempting to implement a feature similar to one found in the netbeans IDE for a programming editor I am helping to write. The feature is an autocomplete/function suggestion based on the current word being typed, and an api popup for the selected function.
Currently a JPopupMenu is used to provide a list of suggested functions based on the current word being typed. EG, when a user types 'array_s' a JPopupMenu pops up with array_search, array_shift, array_slice, etc.
When the user selects one of these options (using the up/down arrow keys) a JWindow (with a jscrollpane embedded in it) is made visible which displays the api page for that particular function.
PROBLEM:
The problem is that when a user scrolls down the JWindow the JPopupmenu disappears so he user cannot select another function.
I have added a ComponentListener to the JPopupMenu so that when componentHidden is called I can do checks to see if it should be visible and make visible if necessary. However, componentHidden is never called.
I have added a focuslistener to the JPopupMenu so that when it loses focus I can do the same checks/make visible if necessary. This function is never called.
I have added a popupMenuListener but this tells me when it is going to make something invisible, not actually when it's done it, so I can't call popup.setVisible(true) from popupMenuWillBecomeInvisible because at that point the menu is still visible.
Does anyone have any suggestions about how I can scroll through a scrollpane in a JWindow whilst still keeping the focus on a separate JPopupMenu in a separate frame?
CheersThe usual way to do popup windows (such as autocomplete as you're doing) is not to create a JPopupMenu, but rather an undecorated (J)Window. Stick a JList in the popup window for the user to select their choice from. The problem with using a JPopupMenu is just what you're experiencing - they're designed to disappear when they lose focus. Using an undecorated JWindow, you can control when it appears/disappears.
See this thread for information on how to do this:
http://forum.java.sun.com/thread.jspa?threadID=5261850&messageID=10090206#10090206
It refers you to another thread describing how to create the "popup's" JWindow so that it doesn't steal input focus from the underlying text component. Then, further down, it describes how you can forward keyboard actions from the underlying text component to the JWindow's contents. This is needed, for example, so the user can keep typing when the autocomplete window is displayed, or press the up/down arrow keys to select different items in the autocomplete window.
It sounds complicated, but it really isn't. :) -
I created a splash screen with a JWindow so that the user can't close it while it's being displayed. Here is my code:
GraphicsEnvironment ge = GraphicsEnvironment.
getLocalGraphicsEnvironment();
GraphicsDevice gs = ge.getDefaultScreenDevice();
JPanel panel = (JPanel)window.getContentPane();
panel.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
panel.setBackground(Color.black);
if (show)
JProgressBar progressBar = new JProgressBar(JProgressBar.HORIZONTAL);
progressBar.setIndeterminate(true);
progressBar.setForeground(Color.blue);
panel.setLayout(new BorderLayout());
panel.add(new JLabel(new ImageIcon("marstotal.gif")), BorderLayout.NORTH);
panel.add(progressBar, BorderLayout.SOUTH);
gs.setFullScreenWindow(window);
window.pack();
window.show();
mainMenu();
}My code works full screen in Windows XP, but does not work in Linux or Windows 98,ME, or 2000. Anyone know how to fix this? OR how I can restructure my code so that it will work on all operating systems?Thanx guys. I finally got my window (although now it's an undecorated JFrame) to get focus. Well, kinda. It says it has focus. However, whenever I press a key, it doesn't fire a KeyEvent. My class implements a KeyListener interface. I defined all the methods (obviously, otherwise it wouldn't compile). In each of the KeyListener methods, I put System.out.println ("Whatever method reached."). It doesn't print anything out, although the window has focus and I'm pressing like a thousand buttons.
-
Minimize/Maximize a JWindow
Hi everyone,
I created an application that derives JWindow instead of the usual JFrame as the parent class of the application. This works fine but I have a following problems listed below that I have not solved yet.
1. Is it possible to implement Maximize/Minimize to a JWindow-derived application?
2. Is it possible to add a Taskbar button that will be displayed in the taskbar area of Windows OS once the application is run?
Thank you in advance.
Regards,
FerdieHi everyone,
I created an application that derives JWindow instead
of the usual JFrame as the parent class of the
application. This works fine but I have a following
problems listed below that I have not solved yet.
1. Is it possible to implement Maximize/Minimize to a
JWindow-derived application?to the best of my knowledge, no, not directly
>
2. Is it possible to add a Taskbar button that will be
displayed in the taskbar area of Windows OS once the
application is run?to the best of my knowledge, no, not directly
I had a problem similar to this before, and what I did was to have a small JFrame that was always behind the JWindow. This causes a button to show up in the taskbar of Windows. also when you have a button on the JWindow for say minimizing it, what you actually do is minimize the JFrame behind it and set the JWindow so its not visible. Then when you want to restore the JWindow from the taskbar, the JWindow is set visible again and the JFrame is placed behind it on the screen. You'll also have to track the user moving the JWindow and move the JFrame behind it accordingly so it is always behind it...
hope that helps you.... -
JTextField in a FullScreen JWindow jdk1.4
I have a problem that must have a simple solution I hope.
I have a JWindow wich I run in fullscreen mode, the contentPane of the JWindow contains a JPanel wich contains JButtons, JLabels and JTextFields I have no problem with the JButtons and JLabels, but the JTextFields get no cursor when clicked and it is therefore impossible to enter text into them.
I tried using the same JPanel in an ordinary JFrame (not fullscreen) and it worked just as it should.
What am I missing?
The JPanel (shortened)
import java.awt.*;
import java.awt.image.*;
import java.awt.event.*;
import javax.swing.*;
class TheMainMenuPanel extends JPanel
private BufferedImage background;
private Graphics2D g2;
private JButton exitButton=new JButton("Exit Game");
private JTextField portField=new JTextField(5);
private JLabel portLabel=new JLabel("Port of game");
public TheMainMenuPanel()
Image tmp=new ImageIcon("Graphics\\MainMenuBack.gif").getImage();
background=ImageUtilities.makeBufferedImage(tmp);
exitButton.addActionListener(new ActionListener()
public void actionPerformed(ActionEvent e)
System.exit(0);
add(portLabel);
add(portField);
add(exitButton);
public void paintComponent(Graphics g)
g2=(Graphics2D)g;
g2.drawImage(background,0,0,null);
I'd be happy for any answerI got the same problem with a JTextArea and a JWindow in fullscreen mode.
How did you got in fullscreen with a JFrame?
did you found an other solution?
thanks for your help
Thomas. -
How to gain focus to a JTextField in a Jwindow
Hi Friends
I am trying to create a Login screen which covers the entire desktop using a Jwindow.
I have one JTextfield and JPassword field in the Jwindow but i am not able to gain focus to those text fields and not able to type anything in those fields...
I am using java 1.4.2
This is my program...
public class Login implements ActionListener
JWindow fs;
JTextField tx1;
JPasswordField tx2;
public Login ()
fs= new JWindow(new JFrame());
tx1= new JTextField(12);
tx2= new JPasswordField(12);
JButton jb = new JButton();
fs.getContentPane().setLayout(new FlowLayout());
fs.getContentPane().add(tx1);
fs.getContentPane().add(tx2);
fs.getContentPane().add(jb);
fs.setSize(300,300);
fs.setVisible(true);
fs.show();
fs.toFront();
public void actionPerformed (ActionEvent e)
System.out.println("User id "+tx1.getText()+" and Password is : "+tx2.getText()):
public static void main(String[] args)
new Login();
Can some one help me in solving this issue with JWINDOW... Plz dont suggest JFrame , since i am not willing to use that header....
Thanks in advance
Ur Friend.Swing releated questions should be posted in the Swing forum.
Check out this posting, found in the Swing forum:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=675445
Plz dont suggest JFrame , since i am not willing to use that header....
JFrame.setDefaultLookAndFeelDecorated(false); -
Trouble during dragging JWindow with my own title bar!
Hello Everyone!
While I drag window something like a conture remains behind, aspecially on white background.
Similar code in VB works perfectly.
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
class NoTitleBar extends JWindow
JLabel label = new JLabel("Title Bar ");
public static void main(String[] args)
new NoTitleBar();
public NoTitleBar()
getContentPane().setLayout(null);
label.setHorizontalAlignment(JLabel.CENTER);
label.setBounds(0,0,400,25);
label.setOpaque(true);
label.setBackground(Color.blue);
label.setForeground(Color.white);
label.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED,new Color(100,100,255),new Color(0,0,100)));
BevelBorder bb = new BevelBorder(BevelBorder.RAISED, Color.blue,Color.blue);
getContentPane().setBackground(Color.pink);
getContentPane().add(label);
setBounds(0,0,400,400);
setVisible(true);
label.addMouseListener(new labelListener());
label.addMouseMotionListener(new labelMotionListener());
addMouseListener(new MouseAdapter(){
public void mouseReleased(MouseEvent me){
dispose();
System.exit(0);
boolean moved = false;
int coorX, coorY;
class labelListener extends MouseAdapter
public void mousePressed(MouseEvent me)
moved = true;
coorX = me.getX();
coorY = me.getY();
public void mouseReleased(MouseEvent me)
moved = false;
class labelMotionListener extends MouseMotionAdapter
public void mouseDragged(MouseEvent me)
if (moved){
Point p = getLocation();
setLocation((int)p.getX()+ me.getX()-coorX,(int)p.getY()+ me.getY()-coorY);Works ok on my platform: NT 4, JDK 1.3.1_02. What are you running on/with?
-
JWindow blocking mouse wheel event?
I have created a custom JPanel that acts as a container for another custom component that needs to receive mouse wheel events. When I place the custom JPanel in a JWindow the mouse wheel events do not get invoked, all though other mouse events work just fine. If I place the JPanel in a JFrame the mouse wheel events are invoked just fine (along with other mouse events).
To keep things simple the JPanel handles the mouse listeners. Any idea why it would work when in a JFrame but not a JWindow?
Edited by: skip1899 on Sep 21, 2009 7:20 AMThe below sample code exhibits the behavior I am talking about on my system (1.6.0_16 on XP). Does it work for you? Is there something I am missing?
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseWheelEvent;
import java.awt.event.MouseWheelListener;
import javax.swing.JFrame;
import javax.swing.JWindow;
public class TestWindow extends JWindow implements
MouseWheelListener,MouseListener {
public TestWindow() {
setSize(200,200);
addMouseWheelListener(this);
addMouseListener(this);
public static void main(String args[]) {
JFrame frame = new JFrame();
frame.setSize(300,300);
frame.setVisible(true);
TestWindow win = new TestWindow();
win.setVisible(true);
public void mouseWheelMoved(MouseWheelEvent e) {
System.out.println("Mouse Wheel Moved!");
public void mouseClicked(MouseEvent arg0) {
System.out.println("Mouse Clicked!");
public void mouseEntered(MouseEvent arg0) {
System.out.println("Mouse Entered!");
public void mouseExited(MouseEvent arg0) {
System.out.println("Mouse Exited!");
public void mousePressed(MouseEvent arg0) {
System.out.println("Mouse Pressed!");
public void mouseReleased(MouseEvent arg0) {
System.out.println("Mouse Release!");
-
Jwindow behaves differently in jdk1.5
Hi,
I created a splash screen using jwindow. In the earlier versions of jdk the splash screen (Jwindow component) can be moved back and i was able to switch to other applications. But when i used jdk 1.5 the Jwindow stays on top and even if i switch to other applications it remains on top. how can i resolve this ??? Is there any change in the behavior of the JWindow in jdk 1.5. This is urgent can any one help???
Regards,
Jonnyif having the app show up in the task bar is not a problem, you could use a
JFrame, then setUndecorated(true); so it will look like a JWindow.
Otherwise, this is just a stab in the dark, but worth a try
(uses a JFrame parent, but doesn't show in the task bar)
import javax.swing.*;
class Testing
public static void main(String[] args)
JWindow window = new JWindow(new JFrame(){
public boolean isShowing(){return true;}});
window.getContentPane().add(new javax.swing.JLabel("Hello World"));
window.setLocation(400,300);
window.setSize(200,200);
window.setVisible(true);
}
Maybe you are looking for
-
PO Qty and GR Qty is not coming for 2LIS_06_INV
Hi Expert, I am trying to load data on 2lis_06_inv datasource but after filling the datasource, PO Qty(BSMNG) and GR Qty(WEMNG, BPWEM) fields does not contain any data but the invoice fields are contain data. Thanks and Regards Lalit
-
== Issue == Firefox is crashing or closing unexpectedly == Description == Problem: When I start FF in Linux, it crashes after the cursor is jumping for half a minute. Nothing is displayed. When I start FF from the command line, I get the prompt back
-
Unable to do Allocation with Reference to Sales Order For SAP AFS
Dear Experts Error is showing while doing Allocation for Sales Order . Our Business Scenario is ( Sales Order ( VA01)- Allocation Run(J3AT) - Delivery (VL01N) - Invoice ( VF01). Yesterday a user C
-
Turn off chunked transfer-encoding
Hi. I have to interface with another company's client that has a broken implementation of http/1.1 and does not understand chunked transfer encoding. Is there some way I can tell Weblogic not to use chunked encoding for a particular servlet response?
-
In BOX R2 Universe how to create External Function in C++??
Hi All, Can any one tell me how to create dynamic SQL Query in BOXI R2 Universe, I heard that we can create c++ custom external functions. i know the procedure for using Oracle functions but that is taking more time to generate report. I want to crea