JWindow - windows L&F


. I have created a JWindow containing a JProgressBar. This is fine as I don't want the min/max/close buttons. But what I want to acheive is to make the win and bar the same as the windows L&F.

I have tried
JProgressBar.setDefaultLookAndFeelDecorated(true);
Posted On: Tuesday 23rd of October 2012 11:30:03 PM Total Views:  248
View Complete with Replies

RELATED TOPICS OF Swing / AWT / SWT PROGRAMMING LANGUAGE




White screens on some windows

We have a multi-window Java application that is able to get itself into a state where it renders white screens. This application makes some external network connections and based on data that's sent over those connections updates the UI, and opens and closes various windows. Naturally this only happens on the production machine, and only when nobody is around to investigate the problem as it is happening. The pattern that has been established via customer reports is that it will not happen for a couple weeks then will happen a few times frequently, eg 2x in 50mins. The customer has been killing the software and restarting the application when it starts showing white screens. We have caught it in action exactly once, and it resolved itself after about 20 minutes. We have three windows that this has been confirmed to happen on. The only thing that these windows have in common is that a) they are triggered by data sent in over the network connection, and b) they are windows that are opened and closed constantly. One of these windows renders two JTextFields, the rest of the screen is blank (and the two fields that are rendered are drawn in the middle of the frame creation). For case A, each window refreshes based on a different type of packet. In one case it is an entirely different socket that is sending the packets. There are three other windows (always open) that are responding to the same data and updating the UI, so we know the packet data is getting around. Case B may leave more clues; it seems to hit a trigger where any windows opened after a certain point are rendered with a white screen. Windows that are already opened continue to update their displays but new windows are useless. We can't confirm this absolutely because the UI goes click-unresponsive; the only windows that can be opened are those that are triggered by the network data, and we can't close any windows either. (Interestingly enough, the customer has reported that there is one set of buttons on a working/rendered window that does work). The CPU usage for the Java process spikes according to performance monitor logs and remains high as long as the white screens are appearing. Interestingly, the Task Manager does not reflect these numbers, reporting 5-10% CPU while the performance monitor reports >100% (dual core pc, max usage = 200%) The heap is capped at 512MB. While displaying white screens, the memory usage as reported by task manager is 186MB, after it resolves itself this jumped to 271MB. Both numbers are what I would consider typical for this application. The software was installed last year, and was working fine until several weeks after an update. The software was compiled under JDK6 and is running on JRE 1.6.0_33. The computer is a Windows 7 Professional x86 OS, dual monitors. I understand it has onboard video and there are generic drivers installed. I haven't been able to find OEM updates for these drivers (the monitors are Samsung E2220X) of our GUI updates are done on the event thread. windows are shown and hidden on the event thread. Because the problem resolves itself (and the windows do not share objects) I do not think this is a deadlock. I've added the Sun options for rendering control based on another thread I found on the internet, these options are -Dsun.java2d.d3d=false and -Dsun.java2d.noddraw=true. Disabling direct draw did not help, I disabled the Direct3D this afternoon and waiting to see if it helps. Has anyone ever seen anything like this before, or have an inkling what might be going on
VIEWS ON THIS POST

94

Posted on:

Sunday 23rd September 2012
View Replies!

I'm trying to learn Swing. I'm self taught. Whats the best way to get a handle on this

. I recently turned my attention to GUI and designing professional looking interfaces. I've got netbeans 7.1.1 and I've been going through the Oracle tutorial pages to get up to speed with Java. When advising users on Swing programming the notes tell you how to operate design options in Netbeans and I have no trouble with that. However when it gives you the code for the Actions that the components on your Frame have it seems to pull them magically out of mid-air without explaining what they do. The following section is more bogged down in detail and looking at the Java docs on the subject ... there is so much content. I don't know how to get to grips with it. Can someone recommend a website that shows the workings of various GUIs in Java so that I can take the code and adapt it to my purposes while I am getting started. Alternatively a good book on learning Swing at beginner to intermediate level would be greatly appreciated. Something I will still need for coding after I have got to grips with the essentials. Many
VIEWS ON THIS POST

148

Posted on:

Tuesday 25th September 2012
View Replies!

getting an object to draw itself - I'm clueless

I'm trying to learn Java, have programmed procedural languages for decades - OO is totally new :0 I'm trying to write a game, I'm using eclipse under windows. I'm writing a tabletop wargame with two armies of different groups of soldiers(squadrons) controlled by two players. I've written a class for a squad of soldiers, which implements the rules for how squadrons will move, fight etc based on numeric values and random numbers. This all works OK, although the algorithms are trivial at present (but that's just simple programming to fix!) I've also written a second class for soldiers with distance weapons (guns, spears...) as a subclass of the first to add additional methods for shooting etc.. This also works OK. I've coded a class to create the window (mostly just cobbled from places I've found), the menu items, the jframe and jpanel - also working. What I now want to do is have each squadron object draw itself when it should (after it moves mainly). I can make no sense of where I put the draw command, and what I need to do to make it work. I have loaded an image into a BufferredImage object (will be based on the squadron name in due course) within the constructor method and started trying to create a draw method within the class, I'm currently using a JLabel object to hold the image. How and where do I create the graphics context, within main() or my window creation class and then how do I pass it to my squadron objects (there may be many at any one time) and I keep seeing classes which extend JPanel - why and how I know this is pretty basic stuff - but after a few days of fruitless searching and getting more confused, I thought I'd try asking for a simple answer I can understand. I have more java projects waiting to be coded, but most will need to create graphics canvases on which objects draw themselves, so I thought it worth finding out the right way early on.
VIEWS ON THIS POST

142

Posted on:

Sunday 30th September 2012
View Replies!

JScrollPane in JInternalframe and JPanel in JScrollPane

I have a class (lets call it MyClass) which extends JPanel. In this class I execute the following method: public void addToInternalFrame(JInternalFrame internalframe){ //[b]this[/b] is the class extending JPanel JScrollPane scrollpane = new JScrollPane(this); internalframe.getContentPane().add(scrollpane, BorderLayout.CENTER); }
VIEWS ON THIS POST

76

Posted on:

Monday 1st October 2012
View Replies!

All images are showing in Eclipse, only half when exported as Runnable Jar

Hi ! I have a very strange problem. And I can't figure out what could be the problem. I am developing my clone of the old game Frogger, I think that everybody knows the game I'm talking about. Well the main reason to develop Frogger is to learn about java games and 2D graphics, anyway this is my problem. When I run my Frogger application in Eclipse, all the images are shown with no problem with the appropriate animation (Logs moving in one direction car in another), then when I export this project as Runnable Jar and start it, I can see all images, except the car images. I know that the missing car images are moving because when I move my frog on the road it gets killed (returns to the start position.) This is my class that loads and holds the required images. the images are in the same folder (source) public class ImageLoader { private static ImageLoader instance; private Map imagesContext = new HashMap(); private Image image; private Toolkit toolkit; private ImageLoader(){ this.toolkit = Toolkit.getDefaultToolkit(); } public static ImageLoader getInstance(){ if(instance == null){ instance = new ImageLoader(); } return instance; } public Image loadImage(ImagesEnum image){ this.image = this.imagesContext.get(image); if(this.image == null){ this.image = this.toolkit.getImage(this.getImageURL(image)); this.imagesContext.put(image, this.image); } return this.image; } private URL getImageURL(ImagesEnum image){ return this.getClass().getResource("/source/" + ImagesEnum.getImageFilename(image)); } }
VIEWS ON THIS POST

150

Posted on:

Monday 1st October 2012
View Replies!

adding container's parent to itself error

Problem code : private void tryM (StyledDocument textPaneU, int integerF, String stringA, SimpleAttributeSet attributesJ) { //This is the method try { textPaneU.insertString(integerF, stringA, attributesJ); } catch(Exception eafff) { eafff.printStackTrace(); } } //Later...This is it being used... StyledDocument fqDOC = new DefaultStyledDocument(); SimpleAttributeSet fqPaneAttrs = new SimpleAttributeSet(); JTextPane fqPane = new JTextPane(fqDOC); fqPaneAttrs.addAttribute(StyleConstants.CharacterConstants.Foreground, Color.green); JScrollPane fqScroll = new JScrollPane(fqPane, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); tryM(fqDOC,0,"Test F&Q", fqPaneAttrs);
VIEWS ON THIS POST

269

Posted on:

Wednesday 17th October 2012
View Replies!

Dragging ftp-link to windows explorer - which dataflavor?

I need to drag a file link (ftp://localhost/foo.zip) to the windows explorer, making it download the file. I'm using: new DataFlavor("text/uri-list;class=java.lang.String");
VIEWS ON THIS POST

107

Posted on:

Wednesday 17th October 2012
View Replies!

JTextField highlighted on windows

On my program I am setting the UIManager to CrossPlatformLookAndFeel. I am running the program on both a Mac and Windows. On the mac as I tab through my JTextFields the text is highlighted and the default text is erased when the user begans typing. On the Windows system the text is not highlighted and the cursor appears at the end of the default text. I would like the Windows system to highlight the text also, I assume I need to change the a property on the UIDefaults, is that correct and which value needs to be changed.
VIEWS ON THIS POST

79

Posted on:

Wednesday 17th October 2012
View Replies!

My Frame is not repainting itself after SWING conversion

Guys, PLEASE HELP!!! Hope you can help me out... been sitting with this problem for a few days now I'm a java rookie. I'm trying to convert this 3D AWT calculator to Swing. So far i managed to change all the AWT components to Swing components. But the problem i have is that everytime i start the application i get a gray screen .The moment i slide my mouse over the gray screen, the buttons start appearing one by one.. what am i doing wrong \t.. the code i'm talking about is attatached to this message. i would really appreciate some help with this. The calculator has 9 classes in it's package.. =============================================== CLASS 1 =============================================== import java.awt.BorderLayout; import java.awt.Color; import java.awt.Font; import java.awt.GridLayout; import java.awt.event.*; //import java.awt.Graphics; import javax.swing.JPanel; public class AwtCalc extends JPanel { //Labels for the number panel of the calculator private String[] numPanelText = { " 1 ", " 2 ", " 3 ", " 4 ", " 5 ", " 6 ", " 7 ", " 8 ", " 9 ", Operator.CLEAR , " 0 ", Operator.DOT }; //Labels for the operator panel of the calculator private String[] operPanelText = { Operator.ADD, Operator.SUBTRACT, Operator.LOGARITHM,Operator.MemoryClear, Operator.MULTIPLY, Operator.DIVIDE, Operator.SINUS,Operator.MemoryRead, Operator.POW, Operator.SQRT, Operator.COSINUS, Operator.MemoryStore, Operator.NEGATE, Operator.EQUALS ,Operator.TANGUS,Operator.MemoryAdd, Operator.MemorySubt,Operator.MemorySpot }; //--------------------------------------------- /** private String[] operPanelText2 = {Operator.LOGARITHM,Operator.MemoryClear, Operator.SINUS,Operator.MemoryRead, Operator.COSINUS, Operator.MemoryStore,Operator.TANGUS,Operator.MemoryAdd }; private Panel mtoetsButtons; */ //-------------------------------------------------- private JPanel numButtonPanel; //used to hold the number buttons private JPanel operButtonPanel; //used to hold the operator buttons private Panel3D displayPanel; //used for the calculator's display private ButtonHandler handler; //action listener for the buttons private CalcDisplay display; //displays the output private Font buttonfont; public AwtCalc() { //Initialize buttonfont = new Font( "Courier", Font.PLAIN, 13 ); setLayout( new BorderLayout() ); setBackground( new Color( 212, 208, 200 ) ); Panel3D mainPanel = new Panel3D( Border3D.EXCLUDE_TOP_BORDER ); numButtonPanel = new JPanel( new GridLayout(5,3, 1, 1) ); operButtonPanel = new JPanel( new GridLayout(5, 5, 1, 1) ); displayPanel = new Panel3D( Border3D.EXCLUDE_BOTTOM_BORDER ); display = new CalcDisplay( 280,26); handler = new ButtonHandler( display ); displayPanel.add( display ); mainPanel.add( createNumberPanel() ); mainPanel.add( createOperPanel() ); add( displayPanel, BorderLayout.NORTH ); add( mainPanel, BorderLayout.CENTER ); mainPanel.setVisible(true); } /* * Method: createNumberPanel * Description: contructs and returns the calculator's number panel */ private JPanel createNumberPanel() { if ( display != null ) { ButtonComponent btn = null; for ( int i = 0; i < numPanelText.length; i++ ) { btn = new ButtonComponent( numPanelText[i] ); btn.addActionListener( handler ); btn.setFont( buttonfont ); numButtonPanel.add( btn ); } } return numButtonPanel; } /** * Method: createOperPanel * Description: contructs and returns the calculator's number panel **/ private JPanel createOperPanel() { ButtonComponent btn = null; for ( int i = 0; i < operPanelText.length; i++ ) { btn = new ButtonComponent( operPanelText[i] ); btn.setFont( buttonfont ); btn.addActionListener( handler ); operButtonPanel.add( btn ); } return operButtonPanel; } }
VIEWS ON THIS POST

167

Posted on:

Wednesday 17th October 2012
View Replies!

Get x,y coords outside of windows/screen using mouselook technique

When you move your mouse all the way to the left - it hits the left edge of the screen and stops - even if the user keeps moving his mouse to the left. In Java, there doesn't appear to be any way to detect that the user keeps moving his mouse "left". Basically, if the current mouse coords are 50,100 and I move my mouse 10 feet to the left on my desk Java will still only report the position as 0,100. My problem is, not only do I have to detect that the user moved the mouse to location -32535235,100 I also have to detect that position accurately. In order to accomplish this, I'm doing the following: 1) Use robot class to forcefully move the cursor to the center of the screen. 2) Detect relative mouse movements and some Point which keeps track of the total movement 3) Repeat - go back to step 1 The code I'm using is basically straight out of a Java game development book "Developing Games in Java". This technique appears to work well for reporting simple changes in the relative x,y movement. It does not appear to be accurate in reporting actual x,y coordinates. So my test case is this: 1) Start the application. 2) Move the mouse 1 foot to the left (left side of desk) - record the X location 3) Move the mouse 2 feet to the right (right side of desk)- record the X location. 4) Finally, move the mouse back to the left side of the desk and ensure it is the same (or very close) to the location recorded in step 2. Currently when I do this, it's way off by hundreds of pixels. Is there a simple error in the code that I'm missing Any ideas on how I can accomplish this Here's the code: import java.awt.BorderLayout; import java.awt.Point; import java.awt.Robot; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionListener; import javax.swing.JComponent; import javax.swing.SwingUtilities; public class SimpleRecenterTest extends JComponent implements MouseMotionListener { private Point location; // location relative to where the mouse cursor starts private Robot robot; // use robot to recenter cursor private Point centerLocation; // center of this component private Point lastActualLocation; // last actual x y coords private boolean isRecentering; public SimpleRecenterTest() { location = new Point(); centerLocation = new Point(); lastActualLocation = new Point(); try { robot = new java.awt.Robot(); } catch (java.awt.AWTException ex) { ex.printStackTrace(); } } public void mouseDragged(MouseEvent e) { mouseMoved(e); } public void mouseMoved(MouseEvent e) { // If the cursor reached the center, stop recentering... if (isRecentering && centerLocation.x == e.getX() && centerLocation.y == e.getY()) { isRecentering = false; } else { int dx = e.getX() - lastActualLocation.x; int dy = e.getY() - lastActualLocation.y; location.x += dx; location.y += dy; System.out.println("Location X,Y: " + location.x + "," + location.y); recenterMouse(); } lastActualLocation.x = e.getX(); lastActualLocation.y = e.getY(); } public void init() { centerLocation.x = getWidth() / 2; centerLocation.y = getHeight() / 2; recenterMouse(); addMouseMotionListener(this); } private synchronized void recenterMouse() { if (robot != null) { isRecentering = true; Point p = new Point(centerLocation); SwingUtilities.convertPointToScreen(p, this); robot.mouseMove(p.x, p.y); // robot moves cursor using scren coordinates } } // Test it public static void main(String[] args) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { SimpleRecenterTest srt = new SimpleRecenterTest(); javax.swing.JFrame f = new javax.swing.JFrame(); f.setLayout(new BorderLayout()); f.getContentPane().add(srt, BorderLayout.CENTER); f.setSize(800, 600); f.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE); f.setVisible(true); srt.init(); } }); } }
VIEWS ON THIS POST

113

Posted on:

Wednesday 17th October 2012
View Replies!

how to create window in frame and drag windows like eclipse

Hi Everyone I am learning to create the program editor which is similar like Crimson Editor. I noticed there are windows in the frame. There are directory window and output window and main window. The window could be dragged and moved. Could anyone kindly tell me what kind of API or component could be used to make window in frame and dragged freely I appreciate if anyone could reply ASAP.
VIEWS ON THIS POST

84

Posted on:

Thursday 18th October 2012
View Replies!

Best strategy for handling actions across multiple windows?

I am writing an application at the moment and want to know the best way (if there is any) of what the subject bar says. I have a main JFrame window with a bunch of 'option windows' that pop up when I want to confirm an action on the main window. For example, the main window has a tab section using jtabbedpane where I can add and remove tabs on the pane with buttons. Each tab is named in order ie. tab 1, tab 2, tab 3, etc and i can add more on the fly with an 'add tab' button on the main window. When I go to remove a tab I use a 'remove tab' button on the main window that pops up another window (another jframe) as a 'select the number of the tab you want to remove and confirm removal (or cancel)' window. Everytime I remove a tab I have to rename all the tabs so they are in order again. If I remove tab 3 out of a group of 5 tabs the list will read incorrectly ie tab 1, tab 2, tab 4, tab 5. I have them renaming properly but I am just questioning my method. I use a static void method from the main window in the pop up window class therefore not having to worry about passing all the tabs across to the pop up window to rename the tabs every time I remove one. I cant call the 'renameTabs' method in the main window because everytime i click remove tab (in the pop up windows action performed method) I have to rename all the tabs after every removal. I hope that makes sense! Edit: I might as well share some code with you! public void actionPerformed(ActionEvent ae) { if(ae.getSource()==cancelBtn){ this.dispose(); } if(ae.getSource()==confirmBtn){ int selectedTab = Integer.parseInt(tf.getText());//selected tab is whatever is in the text field try{ GUICode.getTabbedPane().setSelectedIndex(selectedTab-1);//select the tab GUICode.getTabbedPane().remove(GUICode.getTabbedPane().getSelectedIndex());//remove the tab GUICode.tabNum--; }catch(IndexOutOfBoundsException e){ tf.setText(""); tf.setText("No tab" + selectedTab); } GUICode.renameTabs(); } }
VIEWS ON THIS POST

84

Posted on:

Sunday 21st October 2012
View Replies!

Two windows get focus in turn depends on user action?

I am doing a GUI project using SWING, there is a requirement that I am not sure if can be done by swing. 1. When the application start, the main window appears but kind of grey out, on top of the main window there is another small log in window for user to input user name and password, after the user input info and submit it and validation (using web service) is passed, then the login window disappear and the main window become the focus. On main window, there is log out button, when the button is clicked, the main window is grey out again and log in window appear on top of main window. How to accomplish this if it can be done I checked online ( http://java.sun.com/docs/books/tutorial/ui/features/compWin.html ) , is the internal frame the only way to do this How to do it
VIEWS ON THIS POST

100

Posted on:

Monday 22nd October 2012
View Replies!

how to restore jinternalframe to its normal state

hi, In my project i have used setExtendedState(JFrame.Normal) to get the jframe to its normal state which works very much fine. I would like to do the same for JInternalFrame. Is there any method to do so. Plz let me know..
VIEWS ON THIS POST

62

Posted on:

Monday 22nd October 2012
View Replies!

Unsatisfied LinkError: with windows WCanvasPeer setNativeBackgroundErase

, I got a bug which has the following stack trace. java.lang.UnsatisfiedLinkError: sun.awt.windows.WCanvasPeer.setNativeBackgroundErase(Z)V at sun.awt.windows.WCanvasPeer.setNativeBackgroundErase(Native Method) at sun.awt.windows.WCanvasPeer.initialize(WCanvasPeer.java:92) at sun.awt.windows.WCanvasPeer.initialize(WPanelPeer.java:58) at sun.awt.windows.WWindowPeer.initialize(WWindowPeer.java:105) at sun.awt.windows.WDialogPeer.initialize(WDialogPeer.java:48) at sun.awt.windows.WComponentPeer.(WComponentPeer.java:602) at sun.awt.windows.WCanvasPeer.(WCanvasPeer.java:602) ... ... Does anyone know what this error means. I have tried to search in other forums and couldnt find much information.
VIEWS ON THIS POST

79

Posted on:

Monday 22nd October 2012
View Replies!

Connecting two GUI windows

How should I connect two GUI windows Ex: I have window1 (components added to panel1 and panel1 added to frame1) with fields for login id and pwd and a login-button. After I enter data and click the button I want to see window2 (components added to panel2 and panel2 added to frame2) which shows some other information. To get this behavior, till now I used to create a new window2() in action handling part of code for login-button. So I am creating a new frame for every window in the application. A friend said that for security reasons its not the proper way to do. And that you usually should only have one frame for the entire app. And only change the panel you add to the frame depending on what you want to display. Is that true I believe her but want to hear more from ranchers!
VIEWS ON THIS POST

88

Posted on:

Monday 22nd October 2012
View Replies!

How keep window on top but use other windows?

In windows 2K and later, they have the ability to make a window always appear over others even if it loses focus, so it's over another window but you can still use that other window. Is there a way to do this in java Will it work on Linux/Mac
VIEWS ON THIS POST

66

Posted on:

Monday 22nd October 2012
View Replies!

Run NetBeans Application in windows using terminal in linux

i have been create a net beans application using swing and jdbc at windows... and i want to check if it work in linux... is it possible to run it without any net beans in linux\t i want to run it using terminal... so i just only install java in linux or windows... thx
VIEWS ON THIS POST

55

Posted on:

Tuesday 23rd October 2012
View Replies!

JScrollPane that resizes itself

A question for the staff/customers of this excellent saloon. Consider a JScrollPane. When the content resizes (gets very much smaller), the JScrollPane does not resize, and that's what I want. So I think that I'm going to be clever and I make an extra JScrollPane that does just that: //file ResizableJScrollPane.java import java.awt.*; import javax.swing.*; public class ResizableJScrollPane extends JScrollPane { JComponent jComponent = null; public ResizableJScrollPane(JComponent jComponent){ super(jComponent); setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED); setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.jComponent = jComponent; } public Dimension getPreferredSize(){ Dimension dimension = jComponent.getPreferredSize(); int w = dimension.width; int h = dimension.height; return new Dimension(w+3,h+3); } public void validate(){ Dimension dimension = jComponent.getPreferredSize(); int w = dimension.width; int h = dimension.height; setPreferredSize(dimension); getParent().validate();//\t\t\t\t\t\t\t\t } public Dimension getMaximumSize(){return getPreferredSize();} }
VIEWS ON THIS POST

67

Posted on:

Tuesday 23rd October 2012
View Replies!

Dialogs windows not displaying properly

I have a swing app which has a JFrame for a main container on this frame are several components (table, buttons etc). Several of the buttons cause dialog windows to open. One button opens another JFrame (was a separate app, but is now a pop up window in this app). The problem is after pushing the button for that opens this new window (and closing it) the other dialog windows won't paint correctly. Originally the main window wouldn't repaint correctly but I fixed this by passing its frame to the other frame and calling its update method when the secondary/child frame closed. I've looked through the archives here and must not have worded my search properly b/c I can't find much. Is there a tutorial online somewhere about the proper way to deal with multiple windows/frames and the repainting issues with them -Tad
VIEWS ON THIS POST

75

Posted on:

Tuesday 23rd October 2012
View Replies!