Search Results

Search found 1571 results on 63 pages for 'swing'.

Page 3/63 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Image not loading onto JPanel?

    - by None None
    I have been trying to figure out how to add an image to a JPanel as a background, but still have complete control over the placing of JButtons, JLabels, and etc. This is one method I found, but it is crashing and not loading the image or buttons. Here is the code: import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JButton; import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridLayout; public class PanelDemo extends JFrame { private static final long serialVersionUID = 1L; private JButton btn1 = new JButton("EASY"); private JButton btn2 = new JButton("MEDIUM"); private JButton btn3 = new JButton("HARD"); private JButton btn4 = new JButton("High Score"); public PanelDemo() { super("Image Panel Demo"); JPanel panel = new ImagePanel( new FlowLayout(FlowLayout.CENTER, 50, 180)); JPanel panelbtn = new JPanel(new GridLayout(4, 1)); btn1.setBackground(new java.awt.Color(0, 0, 0)); btn1.setFont(new java.awt.Font("Showcard Gothic", 1, 24)); btn1.setForeground(new java.awt.Color(0, 255, 102)); btn2.setBackground(new java.awt.Color(0, 0, 0)); btn2.setFont(new java.awt.Font("Showcard Gothic", 1, 24)); btn2.setForeground(new java.awt.Color(0, 255, 102)); btn3.setBackground(new java.awt.Color(0, 0, 0)); btn3.setFont(new java.awt.Font("Showcard Gothic", 1, 24)); btn3.setForeground(new java.awt.Color(0, 255, 102)); btn4.setBackground(new java.awt.Color(0, 0, 0)); btn4.setFont(new java.awt.Font("Showcard Gothic", 1, 24)); btn4.setForeground(new java.awt.Color(0, 255, 102)); panel.add(panelbtn); panelbtn.add(btn1); panelbtn.add(btn2); panelbtn.add(btn3); panelbtn.add(btn4); add(panel, BorderLayout.CENTER); setSize(640, 480); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public static void main(String... args) { new PanelDemo().setVisible(true); } } ImagePanel.java import java.awt.Graphics; import java.awt.Image; import java.awt.LayoutManager; import javax.swing.ImageIcon; import javax.swing.JPanel; public class ImagePanel extends JPanel { private static final long serialVersionUID = 1L; String imageFile = "/rsc/img/background.jpg"; public ImagePanel() { super(); } public ImagePanel(String image) { super(); this.imageFile = image; } public ImagePanel(LayoutManager layout) { super(layout); } public void paintComponent(Graphics g) { ImageIcon imageicon = new ImageIcon(getClass().getResource(imageFile)); Image image = imageicon.getImage(); super.paintComponent(g); if (image != null) g.drawImage(image, 0, 0, getWidth(), getHeight(), this); } } Error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(Unknown Source) at ImagePanel.paintComponent(ImagePanel.java:27) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at javax.swing.JLayeredPane.paint(Unknown Source) at javax.swing.JComponent.paintChildren(Unknown Source) at javax.swing.JComponent.paintToOffscreen(Unknown Source) at javax.swing.RepaintManager$PaintManager.paintDoubleBuffered(Unknown Source) at javax.swing.RepaintManager$PaintManager.paint(Unknown Source) at javax.swing.RepaintManager.paint(Unknown Source) at javax.swing.JComponent.paint(Unknown Source) at java.awt.GraphicsCallback$PaintCallback.run(Unknown Source) at sun.awt.SunGraphicsCallback.runOneComponent(Unknown Source) at sun.awt.SunGraphicsCallback.runComponents(Unknown Source) at java.awt.Container.paint(Unknown Source) at java.awt.Window.paint(Unknown Source) at javax.swing.RepaintManager$3.run(Unknown Source) at javax.swing.RepaintManager$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.paintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.prePaintDirtyRegions(Unknown Source) at javax.swing.RepaintManager.access$1000(Unknown Source) at javax.swing.RepaintManager$ProcessingRunnable.run(Unknown Source) at java.awt.event.InvocationEvent.dispatch(Unknown Source) at java.awt.EventQueue.dispatchEventImpl(Unknown Source) at java.awt.EventQueue.access$200(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.awt.EventQueue$3.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source) at java.awt.EventQueue.dispatchEvent(Unknown Source) at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source) at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.pumpEvents(Unknown Source) at java.awt.EventDispatchThread.run(Unknown Source) Also, if anyone knows of a better way to put a background image on a JPanel, pease do tell. Thank you in advance.

    Read the article

  • Automated tests for Java Swing GUIs

    - by pauldoo
    What options are there for building automated tests for GUIs written in Java Swing? I'd like to test some GUIs which have been written using the NetBeans Swing GUI Builder, so something that works without requiring special tampering of the code under test would be ideal.

    Read the article

  • Why Java Swing behaves different on different systems?

    - by Tom Brito
    Some swing code I write in my computer behave different on my colleague's computer, and in my PC, and in my notebook. I wonder, is there something I can do to my Swing applications behave the same in every computer? I want to have sure a algorithm I've tested in my computer will work the same way in my clients computers. E.g. Problem to focus JTextField

    Read the article

  • Grouping swing objects

    - by RenegadeAndy
    Hey. I want to make an object I can add to my java swing application. The object when instantiated would contain an image and 2 labels - is there a way to do this using java swing? If there is - can you point me at an example. I.e i want Myobj icon = new MyObj(pic, label , label); window.addComponent(icon); Cheers Andy

    Read the article

  • Memory Leak with Swing Drag and Drop

    - by tom
    I have a JFrame that accepts top-level drops of files. However after a drop has occurred, references to the frame are held indefinitely inside some Swing internal classes. I believe that disposing of the frame should release all of its resources, so what am I doing wrong? Example import java.awt.datatransfer.DataFlavor; import java.io.File; import java.util.List; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.TransferHandler; public class DnDLeakTester extends JFrame { public static void main(String[] args) { new DnDLeakTester(); //Prevent main from returning or the jvm will exit while (true) { try { Thread.sleep(10000); } catch (InterruptedException e) { } } } public DnDLeakTester() { super("I'm leaky"); add(new JLabel("Drop stuff here")); setTransferHandler(new TransferHandler() { @Override public boolean canImport(final TransferSupport support) { return (support.isDrop() && support .isDataFlavorSupported(DataFlavor.javaFileListFlavor)); } @Override public boolean importData(final TransferSupport support) { if (!canImport(support)) { return false; } try { final List<File> files = (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor); for (final File f : files) { System.out.println(f.getName()); } } catch (Exception e) { e.printStackTrace(); } return true; } }); setDefaultCloseOperation(DISPOSE_ON_CLOSE); pack(); setVisible(true); } } To reproduce, run the code and drop some files on the frame. Close the frame so it's disposed of. To verify the leak I take a heap dump using JConsole and analyse it with the Eclipse Memory Analysis tool. It shows that sun.awt.AppContext is holding a reference to the frame through its hashmap. It looks like TransferSupport is at fault. What am I doing wrong? Should I be asking the DnD support code to clean itself up somehow? I'm running JDK 1.6 update 19.

    Read the article

  • create setup in java swing application

    - by adesh
    I am working on java swing application in which i have to give html files to the client to browse them in swing API. Now i want to create the setup for the project so that user could install the software on their computer and i want to include html files , java classes some jar files and ms access database also how could i use the path of directory created after the installation of software. Please suggest the code if possible

    Read the article

  • Plugin support for a Java swing App (like Eclipse)

    - by Sudar
    I need to add Plugin support to a Java Swing App (like in Eclipse). The Plugin should have the ability to add new Menu items and tab components to the swing app. I am looking for frameworks or libraries which support it. So far I have found Java Plugin Framework http://jpf.sourceforge.net/ and planning to use it. Are there any other better alternatives to it?

    Read the article

  • swing syntax highlighter

    - by Simon
    Hi, I need some advice on creating a syntax highligher for java application using swing. The application should allow to edit a file and highlight syntax. I don't know the swing library, what should I look for?

    Read the article

  • How to disable a container and its children in Swing

    - by Fuzzy76
    I cannot figure out a way to disable a container AND its children in Swing. Is Swing really missing this basic feature? If I do setEnabled(false) on a container, its children are still enabled. My GUI structure is pretty complex, and doing a traversion of all elements below the container is not an option. Neither is a GlassPane on top of the container (the container is not the entire window).

    Read the article

  • Swing and handling threads

    - by James P.
    There's a couple questions here on StackOverflow on the subject of threading with the Swing api but things still aren't clear. What is the issue with the EDT, what is the proper way to initiate a Thread with Swing and in what cases should it be used? P.S: Any sources in terms of good practises would be appreciated.

    Read the article

  • Extending a Java Swing class in Clojure

    - by mikera
    I'm trying to extend a Java Swing component in Clojure, i.e. I want to extend a javax.swing.JComponent and add some custom methods implemented in pure Clojure in addition to all the standard inherited methods. I've tried using "proxy" which works great if I just want a single instance (in the same way as an anonymous inner class). However I'd really like a named class so that I can generate an arbitrary number of instances. What's the recommended way of doing this?

    Read the article

  • weird swing heavyweight object lightweight objects problem

    - by Yoav Schwartz
    Hello, We have a problem in our swing based application since we've upgraded our java version from 6u5 to 6u18 (The application runs over WinXP). Our application contains a Canvas object which resides in a JFrame. The application draws things on the canvas. Every time we drag a lightweight swing object (popup or another frame) over the canvas, it has a refresh problem. It blinks - becomes black. The problem only resolves after we move the swing component away from the canvas and click on it again. We think this problem is related to the fact the the canvas is a heavyweight object. And we know there were changes done in the new versions of java on the mixing of heavyweight and lightweight objects issue. Some more details: 1) Our problem reproduces in java 6u14 and 6u16. 2) Everything works fine in java 6u5. Another strange thing: We have 2 types of stations running our application. The first type has a ATI FireGL7100 PCI-E graphics card. The second type has a Matrox G450 PCI graphic card. The problem does not reproduce on the Matrox based station in any java version. One more thing: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6829858 - looks similar to our problem. Is our problem familiar? Do you have any suggestions (workarounds, ideas how the difference in graphics cards is connected to this problem) Hope I was clear enough, Yoav

    Read the article

  • Java swing hold buttons

    - by Simon Charette
    Hi, I'm trying to create a subclass of JButton or AbstractButton that would call specified .actionPerformed as long as the mouse is held down on the button. So far I was thinking of extending JButton, adding a mouse listener on creation (inside constructor) and calling actionPerformed while the mouse is down. So far i came up with that but I was wondwering if I was on the right track and if so, how to correctly implement the "held down" logic. package components; import java.awt.event.ActionEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.Action; import javax.swing.Icon; import javax.swing.JButton; public class HoldButton extends JButton { private class HeldDownMouseListener implements MouseListener { private boolean mouseIsHeldDown; private HoldButton button; private long millis; public HeldDownMouseListener(HoldButton button, long millis) { this.button = button; this.millis = millis; } @Override public void mouseClicked(MouseEvent arg0) { } @Override public void mouseEntered(MouseEvent arg0) { } @Override public void mouseExited(MouseEvent arg0) { } @Override public void mousePressed(MouseEvent arg0) { mouseIsHeldDown = true; // This should be run in a sub thread? // while (mouseIsHeldDown) { // button.fireActionPerformed(new ActionEvent(button, ActionEvent.ACTION_PERFORMED, "heldDown")); // try { // Thread.sleep(millis); // } catch (InterruptedException e) { // e.printStackTrace(); // continue; // } // } } @Override public void mouseReleased(MouseEvent arg0) { mouseIsHeldDown = false; } } public HoldButton() { addHeldDownMouseListener(); } public HoldButton(Icon icon) { super(icon); addHeldDownMouseListener(); } public HoldButton(String text) { super(text); addHeldDownMouseListener(); } public HoldButton(Action a) { super(a); addHeldDownMouseListener(); } private void addHeldDownMouseListener() { addMouseListener(new HeldDownMouseListener(this, 300)); } } Thanks a lot for your time.

    Read the article

  • Java - AWT / Swing - handling the Event Descriptor Thread

    - by waitinforatrain
    Hi, I have a question about the 'Event Descriptor Thread'. I have a Main class that is also a JFrame. It initialises the rest of the components in the code, some of them do not involve Swing and some of them do. Is it enough to simply initialise the Main class using the EDT like this?... public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { new Main(); } }); } This way everything would run on the Event Dispatcher thread.

    Read the article

  • java, swing, Gridlayout problem

    - by josh
    I have a panel with GridLayout But when I'm trying to run the program, only the first button out of 100 is shown. Futhermore, the rest appear only when I move the cursor over them. What's wrong with it? Here's the whole class(Life.CELLS=10 and CellButton is a class which extends JButton) public class MainLayout extends JFrame { public MainLayout() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(650, 750); setLayout(new FlowLayout()); //setResizable(false); final JPanel gridPanel = new JPanel(new GridLayout(Life.CELLS, Life.CELLS)); for (int i=0; i<Life.CELLS; i++) { for (int j=0; j<Life.CELLS; j++) { CellButton jb = new CellButton(i, j); jb.setPreferredSize(new Dimension(jb.getIcon().getIconHeight(), jb.getIcon().getIconWidth())); buttons[i][j] = jb; grid[i][j] = false; gridPanel.add(jb); } } add(gridPanel); } } This is code of CellButton package classes; import javax.swing.JButton; import javax.swing.ImageIcon; import javax.swing.JFrame; public class CellButton extends JButton { private int x; private int y; boolean alive; ImageIcon icon; boolean next; // icons for grids final ImageIcon dead = new ImageIcon(JFrame.class.getResource("/images/image1.gif")); final ImageIcon live = new ImageIcon(JFrame.class.getResource("/images/image2.gif")); public CellButton(int X, int Y) { super(); x = X; y = Y; alive = false; icon = dead; setIcon(icon); } public int getX() { return x; } public int getY() { return y; } public boolean isAlive() { return alive; } public void relive() { alive = true; icon = live; setIcon(icon); } public void die() { alive = false; icon = dead; setIcon(icon); } public void setNext(boolean n) { next = n; } public boolean getNext() { return next; } public ImageIcon getIcon() { return icon; } }

    Read the article

  • Jawa Swing: Dialog with expanding / progressive disclosure?

    - by Electrons_Ahoy
    I've got a dialog in a desktop Java Swing app. What I want is a classic Windows-style Progressive Disclosure dialog, where pressing a "More Options" button opens up a whole extra batch of options on the dialog. (Which can then be hidden again by clicking that same button, which now says something like "Hide".) What's the right way to do this in Swing? I can't seem to google-up anything directly relating to this, and what I have found boils down to "reset the preferred dimensions to 0 and revalidate" which can't possibly be the right way to do this and also causes all kinds of wacky things to happen.

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >