Search Results

Search found 491 results on 20 pages for 'jframe'.

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

  • Outer class jframe is not hiding when calling the inner class jframe

    - by user2909960
    When i am calling the inner jframe, it is called, but outer jframe is not hiding. instead it gets overlapped. so what will be the solution for this. Is there any way to get out of this. As i tried when i am calling the inner class frame, the outer class frame is also called, and it is not hidden. package com.exp.example; import java.awt.Color; import java.awt.Container; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JTextField; @SuppressWarnings("serial") public class A extends JFrame implements ActionListener { JFrame rframe = new JFrame(); JLabel CFirstName; JTextField Cfname; JButton jbsubmit; Container cp; public A() { rframe.setSize(500, 200); rframe.setLocationRelativeTo(null); cp = getContentPane(); cp.setLayout(null); setSize(550, 300); rframe.setTitle("Outer Frame"); cp.setBackground(new Color(140, 180, 180)); CFirstName = new JLabel("First Name"); Cfname = new JTextField(10); jbsubmit = new JButton("PREVIEW"); CFirstName.setBounds(10, 20, 100, 35); Cfname.setBounds(150, 20, 150, 25); jbsubmit.setBounds(190, 110, 92, 25); cp.add(CFirstName); cp.add(Cfname); cp.add(jbsubmit); jbsubmit.addActionListener(this); rframe.add(cp); rframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); rframe.setVisible(true); } public void actionPerformed(ActionEvent ae) { String action = ae.getActionCommand(); if (action == "PREVIEW") { /* Write the code here * When we click on preview button the frame of outer class(class A) gets * deactivated(closed) and inner frame, frame of inner class(class B) gets visible. * it should not be overlapped. */ /* My Code */ new B(); rframe.setVisible(false); } } public class B { JFrame frm = new JFrame(); Container cp; public B() { frm.setSize(500, 200); frm.setLocationRelativeTo(null); cp = getContentPane(); cp.setLayout(null); setSize(550, 300); frm.setTitle("Inner Frame"); cp.setBackground(new Color(140, 180, 180)); JLabel cpn = new JLabel("hello"); cpn.setBounds(10, 20, 100, 35); cp.add(cpn); frm.add(cp); frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frm.setVisible(true); } } public static void main(String[] args) { new A(); } }

    Read the article

  • How to disable main JFrame when open new JFrame

    - by newbie123
    Example now I have a main frame contains jtable display all the customer information, and there was a create button to open up a new JFrame that allow user to create new customer. I don't want the user can open more than one create frame. Any swing component or API can do that? or how can disabled the main frame? Something like JDialog.

    Read the article

  • Java: I can't interact with my JFrame

    - by Wooooo
    Hi, I have a java application (1.4.2) that uses 2 JFrames. The first is Modal=true and appears on top of the second JFrame. The first JFrame allows the user to "open" a file. Once the file is ready to be displayed, the JFrame is set to setModal=false, and this.dispose() 'd of. This leaves only the second JFrame on the screen. However, I can't interact with it. The code does not throw any errors and appears to run perfectly fine. BUT I can;t interact with the second JFrame. The ONLY way to exit the JFrame is to hit the stop button on my development envirnment. I literally cannot stop the JFrame by clicking the close button, because I can't even interact with that portion of the JFrame. Any thoughts?

    Read the article

  • Java: how to register a listener that listen to a JFrame movement

    - by cocotwo
    How can you track the movement of a JFrame itself? I'd like to register a listener that would be called back every single time JFrame.getLocation() is going to return a new value. Here's a skeleton that compiles and runs, what kind of listener should I add so that I can track every JFrame movement on screen? import javax.swing.*; public class SO { public static void main( String[] args ) throws Exception { SwingUtilities.invokeAndWait( new Runnable() { public void run() { final JFrame jf = new JFrame(); final JPanel jp = new JPanel(); final JLabel jl = new JLabel(); updateText( jf, jl ); jp.add( jl ); jf.add( jp ); jf.pack(); jf.setVisible( true ); } } ); } private static void updateText( final JFrame jf, final JLabel jl ) { jl.setText( "JFrame is located at: " + jf.getLocation() ); jl.repaint(); } }

    Read the article

  • JPanel in JFrame in NetBeans

    - by Gaurav
    I have created a Java application (project) in NetBeans, in which I have designed a JFrame with menu bar, and different JPanels. I want these JPanels to appear inside the JFrame on action of different menu items, so that whenever the menu items are clicked different JPanels should appear inside the JFrame. I have designed both JFrame & JPanel separately, but I couldn't link them together. Please help me out friends.

    Read the article

  • Why aren't my coordinates matching my JFrame size?

    - by AsLanFromNarnia
    I want to do some drawing in a JPanel but the enclosing JFrame size doesn't seem to match where I've asked the coordinates to be drawn. In my example code, the JFrame size is set to (700, 700) and the last point is drawn at (600, 600). I would expect this point to be drawn 100 pixels away from the right and bottom edges but it isn't (please see screenshot). Here's the code I'm using: import java.awt.Graphics; import javax.swing.JFrame; import javax.swing.JPanel; public class Scratch extends JPanel { static int frameWidth = 700; static int frameHeight = 700; public static void main(String[] args) { JFrame frame = new JFrame(); frame.setSize(frameWidth, frameHeight); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); Scratch scratch = new Scratch(); frame.getContentPane().add(scratch); frame.setVisible(true); } @Override public void paintComponent(Graphics g) { g.drawRect(100, 100, 1, 1); g.drawString("100", 100, 100); g.drawRect(200, 200, 1, 1); g.drawString("200", 200, 200); g.drawRect(300, 300, 1, 1); g.drawString("300", 300, 300); g.drawRect(400, 400, 1, 1); g.drawString("400", 400, 400); g.drawRect(500, 500, 1, 1); g.drawString("500", 500, 500); g.drawRect(600, 600, 1, 1); g.drawString("600", 600, 600); } }

    Read the article

  • JFrame is not acting as expected!

    - by DasWood
    This is my first time using a JFrame. I can't get the window to display the text areas I've nested inside the JFrame. I am trying to get the text field with my name in it to display above the tabulated results, which I have omitted the formatting for until I can get the JFrame to work. public void printResults(String[] names, int[] temp, int[][] scores, float[] averages, char[] letters){ JTextArea outarea= new JTextArea(5,20); JTextArea name = new JTextArea(5,20); Font font = new Font("Tahoma", Font.BOLD, 48); name.setFont(font); name.setText("Made By Durka Durka"); JFrame window = new JFrame(); window.getContentPane().add(name); window.getContentPane().add(outarea); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.pack(); window.getContentPane().setVisible(true) String out = "twat"; outarea.setText(out); //JOptionPane.showMessageDialog(null,window); }

    Read the article

  • Java JFrame EventQueue

    - by asmo
    In Java, to create and show a new JFrame, I simply do this: public static void main(String[] args) { new JFrame().setVisible(true); } However, I saw many people doing it like this: public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { new JFrame().setVisible(true); } }); } Why? Are there any advantages?

    Read the article

  • "Forwarding" keypresses from an applet to a JFrame

    - by hansengel
    I have a JFrame which contains a JApplet. There are shortcut keys that I have configured for the JFrame that work fine when the focus is on some panel of it, but once I click into the applet, none of the shortcut keys work anymore. Is there any way that I can forward these key presses to the JFrame so that the events are still fired?

    Read the article

  • Why I cannot add a JPanel to JFrame?

    - by Roman
    Here is the code: import javax.swing.SwingUtilities; import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.JLabel; import java.awt.event.*; import java.awt.*; public class GameWindow { private String[] players; private JFrame frame; // Constructor. public GameWindow(String[] players) { this.players = players; } // Start the window in the EDT. public void start() { SwingUtilities.invokeLater(new Runnable() { public void run() { showWindow(); controller.start(); } }); } // Defines the general properties of and starts the window. public void showWindow() { frame = new JFrame("Game"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(600,400); frame.setVisible(true); } // The thread controlling changes of panels in the main window. private Thread controller = new Thread() { public void run() { frame.add(generatePartnerSelectionPanel()); frame.invalidate(); frame.validate(); } }; // Generate the panel for the selection of a partner. private JPanel generatePartnerSelectionPanel() { JPanel panel = new JPanel(); panel.add(new JLabel("Pleas select a partner:")); return panel; } } I should see "Pleas select the partner" and I don't. Why? I suppose that it's because I do not see frame from the run method of the Thread.

    Read the article

  • Best Practice With JFrame Constructors?

    - by David Barry
    In both my Java classes, and the books we used in them laying out a GUI with code heavily involved the constructor of the JFrame. The standard technique in the books seems to be to initialize all components and add them to the JFrame in the constructor, and add anonymous event handlers to handle events where needed, and this is what has been advocated in my class. This seems to be pretty easy to understand, and easy to work with when creating a very simple GUI, but seems to quickly get ugly and cumbersome when making anything other than a very simple gui. Here is a small code sample of what I'm describing: public class FooFrame extends JFrame { JLabel inputLabel; JTextField inputField; JButton fooBtn; JPanel fooPanel; public FooFrame() { super("Foo"); fooPanel = new JPanel(); fooPanel.setLayout(new FlowLayout()); inputLabel = new JLabel("Input stuff"); fooPanel.add(inputLabel); inputField = new JTextField(20); fooPanel.add(inputField); fooBtn = new JButton("Do Foo"); fooBtn.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //handle event } }); fooPanel.add(fooBtn); add(fooPanel, BorderLayout.CENTER); } } Is this type of use of the constructor the best way to code a Swing application in java? If so, what techniques can I use to make sure this type of constructor is organized and maintainable? If not, what is the recommended way to approach putting together a JFrame in java?

    Read the article

  • Getting a JFrame's actual current location

    - by Ian Fellows
    Hello community, I am trying to create a (child) JFrame which slides out from underneath one side of a second (parent) JFrame. The goal is to then have the child follow the parent around when it is moved, and respond to resizing events. This is somewhat related to this question. I have tried using a ComponentListener, but with this method the child only moves once the parent has come to a stop, whereas I would like the child to move as the parent is dragged around the screen. Another option I attempted was to start a new refresher thread that continually updated the child's location using getLocation() or getLocationOnScreen(), but the lag was the same as with ComponentListener. Is there a way to get the true actual location of a JFrame even in the midst of a drag? or if not, is there a way to get the effect of a sheet sliding out from underneath and following the Frame around?

    Read the article

  • Reinstantiating a GUI (JFrame) object

    - by Alex
    Hi guys, basically I want my JFrame to become a completely new JFrame object when an event is triggered. I have some code that basically calls [CODE]GUI gui = new GUI(x, y)[/CODE] the only problem I'm having is that as well as creating the new GUI object, it is not deleting the old window. Can anyone tell me how to get rid of the old window. Thanks.

    Read the article

  • jframe adding own design jinternal frame error

    - by Van Minh
    I designed a title bar color on my JInternal frame. Then I took attempt to add it to my JFrame, but I cannot. Here is the code of my title bar: public class MyIFtitleBar extends BasicInternalFrameTitlePane { public MyIFtitleBar(JInternalFrame jif) { super(jif); } protected void paintTitleBackground(Graphics g){ g.setColor(Color.pink); g.fillRect(0, 0, getWidth(), getHeight()); } } Here is my JInternal frame. I tried running it in its psvm method, that worked! public class FitnessProg_Frame extends javax.swing.JInternalFrame { public FitnessProg_Frame() { initComponents(); this.setUI(new BasicInternalFrameUI(this){ @Override protected JComponent createNorthPane(JInternalFrame jif) { return new MyIFtitleBar(jif); } }); } @SuppressWarnings("unchecked") private void initComponents() { setBackground(new java.awt.Color(255, 255, 255)); setBorder(new javax.swing.border.MatteBorder(null)); setTitle("Fitness Progarm"); setPreferredSize(new java.awt.Dimension(507, 304)); pack(); } } But when I add it to my JFrame I get an error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException Here is my JFrame code: public class NewJFrame extends javax.swing.JFrame { public NewJFrame() { initComponents(); FitnessProg_Frame ff = new FitnessProg_Frame(); ff.setVisible(true); mydes.add(ff); // this line made errors } @SuppressWarnings("unchecked") private void initComponents() { mydes = new javax.swing.JDesktopPane(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); javax.swing.GroupLayout mydesLayout = new javax.swing.GroupLayout(mydes); mydes.setLayout(mydesLayout); mydesLayout.setHorizontalGroup( mydesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 400, Short.MAX_VALUE) ); mydesLayout.setVerticalGroup( mydesLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addGap(0, 300, Short.MAX_VALUE) ); getContentPane().add(mydes, java.awt.BorderLayout.CENTER); pack(); } public static void main(String args[]) { try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(NewJFrame.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new NewJFrame().setVisible(true); } }); } private javax.swing.JDesktopPane mydes; }

    Read the article

  • ToolTip flicker in Java if outside JFrame? [closed]

    - by Skarion
    Hi! I am implementing ToolTip in Java as to make users having an easier time to use the product. Though tooltip that are at the borders of the JFrame and ends up outside the JFrame starts to "flicker". I've tried lots of things (like moving the tooltip so it should be inside the Jframe, controlling the painting so it ends up within the JFrame and so on) though it doesn't work. Anyone got any expertise within the field that know how to avoid this problem? Cheers, Skarion

    Read the article

  • Background image in a JFrame.

    - by thepandaatemyface
    Hi, This question has been asked a lot but everywhere the answers fall short. I can get a JFrame to display a background image just fine by extending JPanel and overriding paintComponent, like so: class BackgroundPanel extends JPanel { private ImageIcon imageIcon; public BackgroundPanel() { this.imageIcon = Icons.getIcon("foo"); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.drawImage(imageIcon.getImage(), 0,0,imageIcon.getIconWidth(),imageIcon.getIconHeight(),this); } } But now, how do you add a component on top of that background? When I go JFrame w = new JFrame() ; Container cp = w.getContentPane(); cp.setLayout(null); BackgroundPanel bg = new BackgroundPanel(); cp.add(bg); JPanel b = new JPanel(); b.setSize(new Dimension(30, 40)); b.setBackground(Color.red); cp.add(b); w.pack() w.setVisible(true) It shows the little red square (or any other component) and not the background, but when I remove cp.setLayout(null);, the background shows up but not my other component. I'm guessing this has something to do with the paintComponent not being called by the null LayoutManager, but I'm not at all familiar with how LayoutManagers work (this is a project for college and the assignment specifically says not to use a LayoutManager) When i make the image the background has to display null (and so, transparant (??)) the red square shows up so it might be that the background is actually above my other components) Does anyone anyone have any ideas? Thanks

    Read the article

  • Having difficulty add a custom icon to a JFrame

    - by Oliver
    Hi, I have been trying to change the icon in the frame. I have virtually tried everything: The icon is 16x16 which is the right size ....doesn't work I've trying PNG,GIF and JPG formats none of them work. Tried different way of setting the icon....doesn't work. I've tried relative (local paths) e.g. "icon.gif" and absolute paths e.g. "c:\work\java\icon.gif" ...doesn't work Here is my code and see if you can figure it out Thanks Oli import javax.swing.*; public class androidDriver { public static void main(String[] args) throws IOException { JFrame f = new JFrame("Android Data Viewer"); f.setResizable(false); f.setSize(300,300); f.setLocationRelativeTo(null); f.setVisible(true); f.setIconImage(new ImageIcon("androidIcon2.gif").getImage()); } }

    Read the article

  • issue about Concept of JFrame, JLabel and ContentPane

    - by Sun Hong Kim
    I just study window programming with awt. I see through several codes but I can not get concepts of JFrame, JLabel and ContentPane. I think JFrame only make outer Frame. ContentPane is container that contain JLabel that has contents(text, button, radio etc...). I don't know this is correct T.T Why I ask this is I failed combine the contents. I can not make TextField and InternalFrame at a time. I want to know the concept. I hope you take my question right.

    Read the article

  • problem in adding image to JFrame

    - by firestruq
    Hi, I'm having problems in adding a picture into JFrame, something is missing probebly or written wrong. here are the classes: main class: public class Tester { public static void main(String args[]) { BorderLayoutFrame borderLayoutFrame = new BorderLayoutFrame(); borderLayoutFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); borderLayoutFrame.setSize(600,600); borderLayoutFrame.setVisible(true); } } public class BorderLayoutFrame extends JFrame implements ActionListener { private JButton buttons[]; // array of buttons to hide portions private final String names[] = { "North", "South", "East", "West", "Center" }; private BorderLayout layout; // borderlayout object private PicPanel picture = new PicPanel(); // set up GUI and event handling public BorderLayoutFrame() { super( "Philosofic Problem" ); layout = new BorderLayout( 5, 5 ); // 5 pixel gaps setLayout( layout ); // set frame layout buttons = new JButton[ names.length ]; // set size of array // create JButtons and register listeners for them for ( int count = 0; count < names.length; count++ ) { buttons[ count ] = new JButton( names[ count ] ); buttons[ count ].addActionListener( this ); } add( buttons[ 0 ], BorderLayout.NORTH ); // add button to north add( buttons[ 1 ], BorderLayout.SOUTH ); // add button to south add( buttons[ 2 ], BorderLayout.EAST ); // add button to east add( buttons[ 3 ], BorderLayout.WEST ); // add button to west add( picture, BorderLayout.CENTER ); // add button to center } // handle button events public void actionPerformed( ActionEvent event ) { } } I'v tried to add the image into the center of layout. here is the image class: public class PicPanel extends JPanel { Image img; private int width = 0; private int height = 0; public PicPanel() { super(); img = Toolkit.getDefaultToolkit().getImage("table.jpg"); } public void paintComponent(Graphics g) { super.paintComponents(g); if ((width <= 0) || (height <= 0)) { width = img.getWidth(this); height = img.getHeight(this); } g.drawImage(img,0,0,width,height,this); } } Please your help, what is the problem? thanks BTW: i'm using eclipse, which directory the image suppose to be in?

    Read the article

  • JFrame the same shape as an Image / Program running in background

    - by Jan Weber
    My question is simple, the solution surely not. I am looking for a way to shape a JFrame the same as an Image it will be displaying. By shape I mean the shape of the pixels that have an alpha != 0. I've already found a working example using a GeneralPath object, but it created ~110000 "nodes" for an Image of about 500*400, so starting the JFrame took more than 2 minutes, which is definitely not the desired effect, the startup should be in under 2 seconds. Thanks for your time.

    Read the article

  • Close resources before exiting JFrame and TCP communication in Java

    - by Oz Molaim
    1. I'm writing a chat based application on TCP communication. I'm using NetBeans and I want to add functionality to the default EXIT_ON_CLOSE when exiting JFrame. The reason of course is because I want to clean resources and end threads safely. How can I call a method that clear resources and only then close the JFrame safely and end the process. 2. I need to implement the server side. The server has List/HashMap/Queue of 'Socket' with their chat nick-names. Is there any simple design pattern to do it correctly because I don't want to re-invent the wheel. thanks.

    Read the article

  • Removing JPanel from a JFrame in netbeans

    - by jt153
    So, I have several JPanels that contain buttons, labels, etc. that I want to switch between from a main JFrame. Currently I am trying to use the this.add(JPanelname); method and this.remove(JPanelname); with the validate(); and repaint(); methods The problem is it will add the panel to the JFrame but it will not remove it. I am not sure how exactly to go about this and any help would be greatly appreciated.

    Read the article

  • JFrame does not refresh after deleting an image

    - by dajackal
    Hi! I'm working for the first time with images in a JFrame, and I have some problems. I succeeded in putting an image on my JFrame, and now i want after 2 seconds to remove my image from the JFrame. But after 2 seconds, the image does not disappear, unless I resize the frame or i minimize and after that maximize the frame. Help me if you can. Thanks. Here is the code: File f = new File("2.jpg"); System.out.println("Picture " + f.getAbsolutePath()); BufferedImage image = ImageIO.read(f); MyBufferedImage img = new MyBufferedImage(image); img.resize(400, 300); img.setSize(400, 300); img.setLocation(50, 50); getContentPane().add(img); this.setSize(600, 400); this.setLocationRelativeTo(null); this.setVisible(true); Thread.sleep(2000); System.out.println("2 seconds over"); getContentPane().remove(img); Here is the MyBufferedImage class: public class MyBufferedImage extends JComponent{ private BufferedImage image; private int nPaint; private int avgTime; private long previousSecondsTime; public MyBufferedImage(BufferedImage b) { super(); this.image = b; this.nPaint = 0; this.avgTime = 0; this.previousSecondsTime = System.currentTimeMillis(); } @Override public void paintComponent(Graphics g) { Graphics2D g2D = (Graphics2D) g; g2D.setColor(Color.BLACK); g2D.fillRect(0, 0, this.getWidth(), this.getHeight()); long currentTimeA = System.currentTimeMillis(); //g2D.drawImage(this.image, 320, 0, 0, 240, 0, 0, 640, 480, null); g2D.drawImage(image, 0,0, null); long currentTimeB = System.currentTimeMillis(); this.avgTime += currentTimeB - currentTimeA; this.nPaint++; if (currentTimeB - this.previousSecondsTime > 1000) { System.out.format("Drawn FPS: %d\n", nPaint++); System.out.format("Average time of drawings in the last sec.: %.1f ms\n", (double) this.avgTime / this.nPaint++); this.previousSecondsTime = currentTimeB; this.avgTime = 0; this.nPaint = 0; } } }

    Read the article

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