JDialog boxes

Hi,
Just a bit curious whats the best way to creat a JDialog box?
I currently have have one main panel, with one button. When the user clicks this button, it brind up the dialog box. I dont think i have done this correctly, as when the dialog box populates, when I move it around on the screen, it erases the contents off the panel that called the dialog (erases the contents when i move the dialog accross the screen.
Can any one help me set out the correct constructors for the DIalog and the panel calling it?
thanks in advance
public public class PanelA extends JPanel {
public class Dialoig Box extends JDialog {
public class GUI {
public () {
//code here to add a jbutton to panelA
//code here to add PanelA to the frame
//inner class here . Action listener for the button
class CheckButtonActionListener
implements ActionListener {
public void actionPerformed(ActionEvent event) {
//Main method here
Main frame = new Main();

import javax.swing.*;
public class Main extends javax.swing.JFrame {
    public Main() {
        initComponents();
    private void initComponents() {
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton();
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Test Dialog Box");
        jButton1.setText("jButton1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
        jPanel1.add(jButton1);
        getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
        java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
        setBounds((screenSize.width-401)/2, (screenSize.height-411)/2, 401, 411);
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
        JDialog dialog = new DialogBox(this,true);
        dialog.setVisible(true);
    public static void main(String args[]) {
        new Main().setVisible(true);
    // Variables declaration - do not modify
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    // End of variables declaration
    public class DialogBox extends javax.swing.JDialog {
        public DialogBox(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            initComponents();
        private void initComponents() {
            jPanel1 = new javax.swing.JPanel();
            jButton1 = new javax.swing.JButton();
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            setTitle("Dialog Box");
            jButton1.setText("jButton1");
            jButton1.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jButtonActionPerformed(evt);
            jPanel1.add(jButton1);
            getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
            java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
            setBounds((screenSize.width-237)/2, (screenSize.height-191)/2, 237, 191);
        private void jButtonActionPerformed(java.awt.event.ActionEvent evt) {
            setVisible(false);
            dispose();
        private javax.swing.JButton jButton1;
        private javax.swing.JPanel jPanel1;
}

Similar Messages

  • Help needed: Creating web link in JDialog Box

    I'm in need of this urgently, any help would be much appreciated. I'm currently display some information in a JDialog box when an item is clicked in a JApplet.
    I need to display a weblink within the dialog box.
    Thanks anyone

    I am using JDeveloper 10.1.3.3.0. Thanks Heaps

  • Focus on JTextfield in JDialog box

    A JDialog box is being opened from a menu.
    There is only one JTextfield on the dialog box and 2 buttons.
    The focus is not on any of the components in the dialog box and I want it on the textfield by default.
    I have tried all the requestFocus(),requestDefaultFocus(),grabfocus() etc and none of them work.
    There is an eventListener added to the JTextfield could this be the problem.

    I am a little supprised that the focus is not given to the text field if that is the only thing on the dialog.
    You could try detecting the display of the dialog and then giving the focus to the text field. Focus will not be given to a component if the component cant be displayed at that time. My guess is that the dialog is still hidden when you are trying to set the focus and that is what is causing the problem.

  • KeyEvent calling JDialog box flickers

    On a JFrame I have a button with an ActionPerformed() method. On pressing the button a dialog box pops up on the screen as it is meant to do. This functionality is also needed to be assigned to the 'F1' key as well. In the same class I have a keyReleased() method that listens when the F1 key is pressed. For the VK_F1 KeyEvent I have put the same lines of code that I put in the ActionPerformed() method of the button. When F1 is pressed, the JDialog appears but it flickers for the first few seconds which is annoying. Does any one know why the JDialog box flickers and how to solve this.

    has any one got any sugguestions how to solve a flickering JDialog box in general???

  • Problem with JDialog box

    Hi Guys,
    I have a problem with the JDialog box. The close button (Cross mark of the box) is not displayed when I was trying to use my custom LookAndFeel and Custom theme. I am pasting the code sample here.
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.Icon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.LookAndFeel;
    import javax.swing.SwingUtilities;
    import javax.swing.UIDefaults;
    import javax.swing.UIManager;
    import javax.swing.plaf.ColorUIResource;
    import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
    import com.jgoodies.looks.plastic.PlasticTheme;
    import com.medplexus.looks.plastic.theme.SkyGreen;
    public class TestTheDialog implements ActionListener {
    JFrame mainFrame = null;
    JButton myButton = null;
    public TestTheDialog() {
    mainFrame = new JFrame("TestTheDialog Tester");
    mainFrame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {System.exit(0);}
    try{
         MyLookAndFeel.setCurrentTheme(new CustomLaF());
         UIManager.setLookAndFeel(new MyLookAndFeel());
         SwingUtilities.updateComponentTreeUI(mainFrame);
         CustomDialog cd = new CustomDialog();
         cd.setDefaultLookAndFeelDecorated(true);
    catch(Exception e){
    myButton = new JButton("Test the dialog!");
    myButton.addActionListener(this);
    mainFrame.setLocationRelativeTo(null);
    mainFrame.getContentPane().add(myButton);
    mainFrame.setSize(200, 150);
    //mainFrame.pack();
    mainFrame.setVisible(true);
    public void actionPerformed(ActionEvent e) {
    if(myButton == e.getSource()) {
    System.err.println("Opening dialog.");
    CustomDialog myDialog = new CustomDialog(mainFrame, true, "Do you like Java?");
    System.err.println("After opening dialog.");
    if(myDialog.getAnswer()) {
    System.err.println("The answer stored in CustomDialog is 'true' (i.e. user clicked yes button.)");
    else {
    System.err.println("The answer stored in CustomDialog is 'false' (i.e. user clicked no button.)");
    static class CustomLaF extends PlasticTheme {
    protected ColorUIResource getPrimary1() {
    return new ColorUIResource(255,128,0);
    public ColorUIResource getPrimary2() {
              return (new ColorUIResource(Color.white));
         public ColorUIResource getPrimary3() {
              return (new ColorUIResource(255,128,0));
    public ColorUIResource getPrimaryControl() {
    return new ColorUIResource(Color.GREEN);
    protected ColorUIResource getSecondary1() {
    return new ColorUIResource(Color.CYAN);
    protected ColorUIResource getSecondary2() {
              return (new ColorUIResource(Color.gray));
         protected ColorUIResource getSecondary3() {
              return (new ColorUIResource(235,235,235));
         protected ColorUIResource getBlack() {
              return BLACK;
         protected ColorUIResource getWhite() {
              return WHITE;
         private Object getIconResource(String s) {
    return LookAndFeel.makeIcon(getClass(), s);
    private Icon getHastenedIcon(String s, UIDefaults uidefaults) {
    Object obj = getIconResource(s);
    return (Icon) ((javax.swing.UIDefaults.LazyValue) obj).createValue(uidefaults);
    static class MyLookAndFeel extends Plastic3DLookAndFeel {
              protected void initClassDefaults(UIDefaults table) {
                   super.initClassDefaults(table);
              protected void initComponentDefaults(UIDefaults table) {
                   super.initComponentDefaults(table);
                   Object[] defaults = {
                             "MenuItem.foreground",new ColorUIResource(Color.white),
                             "MenuItem.background",new ColorUIResource(Color.gray),
                             "MenuItem.selectionForeground",new ColorUIResource(Color.gray),
                             "MenuItem.selectionBackground",new ColorUIResource(Color.white),
                             "Menu.selectionForeground", new ColorUIResource(Color.white),
                             "Menu.selectionBackground", new ColorUIResource(Color.gray),
                             "MenuBar.background", new ColorUIResource(235,235,235),
                             "Menu.background", new ColorUIResource(235,235,235),
                             "Desktop.background",new ColorUIResource(235,235,235),
                             "Button.select",new ColorUIResource(255,128,0),
                             "Button.focus",new ColorUIResource(255,128,0),
                             "TableHeader.background", new ColorUIResource(255,128,0),
                             "TableHeader.foreground", new ColorUIResource(Color.white),
                             "ScrollBar.background", new ColorUIResource(235,235,235),
                             "OptionPane.questionDialog.border.background", new ColorUIResource(Color.gray),
                             "OptionPane.errorDialog.titlePane.foreground", new ColorUIResource(Color.white),
                             "OptionPane.questionDialog.titlePane.background", new ColorUIResource(255,128,0),
                             "InternalFrame.borderColor", new ColorUIResource(Color.gray),
                             "InternalFrame.activeTitleForeground", new ColorUIResource(Color.white),
                             "InternalFrame.activeTitleBackground", new ColorUIResource(Color.gray),
                             "InternalFrame.borderColor", new ColorUIResource(Color.white),
                             "Table.selectionBackground",new ColorUIResource(255,128,0)
                   table.putDefaults(defaults);
    public static void main(String argv[]) {
    TestTheDialog tester = new TestTheDialog();
    package CustomThemes;
    import javax.swing.JDialog;
    import java.awt.event.ActionListener;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    import java.awt.event.ActionEvent;
    public class CustomDialog extends JDialog implements ActionListener {
    private JPanel myPanel = null;
    private JButton yesButton = null;
    private JButton noButton = null;
    private boolean answer = false;
    public boolean getAnswer() { return answer; }
    public CustomDialog(){
    public CustomDialog(JFrame frame, boolean modal, String myMessage) {
    super(frame, modal);
    setTitle("Guess?");
    myPanel = new JPanel();
    getContentPane().add(myPanel);
    myPanel.add(new JLabel(myMessage));
    yesButton = new JButton("Yes");
    yesButton.addActionListener(this);
    myPanel.add(yesButton);
    noButton = new JButton("No");
    noButton.addActionListener(this);
    myPanel.add(noButton);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    pack();
    setLocationRelativeTo(frame);
    setVisible(true);
    public void actionPerformed(ActionEvent e) {
    if(yesButton == e.getSource()) {
    System.err.println("User chose yes.");
    answer = true;
    setVisible(false);
    else if(noButton == e.getSource()) {
    System.err.println("User chose no.");
    answer = false;
    setVisible(false);
    Thanks and Regards
    Kumar.

    Hi All,
    I am using the JGoodies Look and feel (looks2.0.1.jar). I wrote my own custom LookAndFeel and Theme , but the problem with this is the JDialog/JOptionPane dialog boxes are displayed with out the close button (cross button on the titlebar).
    I am pasting the code here.
    import java.awt.Color;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.Icon;
    import javax.swing.JButton;
    import javax.swing.JFrame;
    import javax.swing.LookAndFeel;
    import javax.swing.SwingUtilities;
    import javax.swing.UIDefaults;
    import javax.swing.UIManager;
    import javax.swing.plaf.ColorUIResource;
    import com.jgoodies.looks.plastic.Plastic3DLookAndFeel;
    import com.jgoodies.looks.plastic.PlasticTheme;
    import com.medplexus.looks.plastic.theme.SkyGreen;
    public class TestTheDialog implements ActionListener {
        JFrame mainFrame = null;
        JButton myButton = null;
        public TestTheDialog() {
            mainFrame = new JFrame("TestTheDialog Tester");
            mainFrame.addWindowListener(new WindowAdapter() {
                    public void windowClosing(WindowEvent e) {System.exit(0);}
            try{
                 MyLookAndFeel.setCurrentTheme(new CustomLaF());
                 UIManager.setLookAndFeel(new MyLookAndFeel());
                 //Plastic3DLookAndFeel.setCurrentTheme(new SkyGreen());
                 //UIManager.setLookAndFeel(new Plastic3DLookAndFeel());
                 SwingUtilities.updateComponentTreeUI(mainFrame);
                 CustomDialog cd = new CustomDialog();
                 cd.setDefaultLookAndFeelDecorated(true);
            catch(Exception e){
            myButton = new JButton("Test the dialog!");
            myButton.addActionListener(this);
            mainFrame.setLocationRelativeTo(null);
            mainFrame.getContentPane().add(myButton);
            mainFrame.setSize(200, 150);
            //mainFrame.pack();
            mainFrame.setVisible(true);
        public void actionPerformed(ActionEvent e) {
            if(myButton == e.getSource()) {
                System.err.println("Opening dialog.");
                CustomDialog myDialog = new CustomDialog(mainFrame, true, "Do you like Java?");
                System.err.println("After opening dialog.");
                if(myDialog.getAnswer()) {
                    System.err.println("The answer stored in CustomDialog is 'true' (i.e. user clicked yes button.)");
                else {
                    System.err.println("The answer stored in CustomDialog is 'false' (i.e. user clicked no button.)");
        static class CustomLaF extends PlasticTheme {
            protected ColorUIResource getPrimary1() {
              return new ColorUIResource(255,128,0);
            public ColorUIResource getPrimary2() {
                  return (new ColorUIResource(Color.white));
             public ColorUIResource getPrimary3() {
                  return (new ColorUIResource(255,128,0));
            public ColorUIResource getPrimaryControl() {
              return new ColorUIResource(Color.GREEN);
            protected ColorUIResource getSecondary1() {
              return new ColorUIResource(Color.CYAN);
            protected ColorUIResource getSecondary2() {
                  return (new ColorUIResource(Color.gray));
             protected ColorUIResource getSecondary3() {
                  return (new ColorUIResource(235,235,235));
             protected ColorUIResource getBlack() {
                  return BLACK;
             protected ColorUIResource getWhite() {
                  return WHITE;
             private Object getIconResource(String s) {
                return LookAndFeel.makeIcon(getClass(), s);
            private Icon getHastenedIcon(String s, UIDefaults uidefaults) {
                Object obj = getIconResource(s);
                return (Icon) ((javax.swing.UIDefaults.LazyValue) obj).createValue(uidefaults);
          static class MyLookAndFeel extends Plastic3DLookAndFeel {
                  protected void initClassDefaults(UIDefaults table) {
                       super.initClassDefaults(table);
                  protected void initComponentDefaults(UIDefaults table) {
                       super.initComponentDefaults(table);
                       Object[] defaults = {
                                 "MenuItem.foreground",new ColorUIResource(Color.white),
                                 "MenuItem.background",new ColorUIResource(Color.gray),
                                 "MenuItem.selectionForeground",new ColorUIResource(Color.gray),
                                 "MenuItem.selectionBackground",new ColorUIResource(Color.white),
                                 "Menu.selectionForeground", new ColorUIResource(Color.white),
                                 "Menu.selectionBackground", new ColorUIResource(Color.gray),
                                 "MenuBar.background", new ColorUIResource(235,235,235),
                                 "Menu.background", new ColorUIResource(235,235,235),
                                 "Desktop.background",new ColorUIResource(235,235,235),
                                 "Button.select",new ColorUIResource(255,128,0),
                                 "Button.focus",new ColorUIResource(255,128,0),
                                 "TableHeader.background", new ColorUIResource(255,128,0),
                                 "TableHeader.foreground", new ColorUIResource(Color.white),
                                 "ScrollBar.background",  new ColorUIResource(235,235,235),
                                 "OptionPane.questionDialog.border.background", new ColorUIResource(Color.gray),
                                 "OptionPane.errorDialog.titlePane.foreground", new ColorUIResource(Color.white),
                                 "OptionPane.questionDialog.titlePane.background", new ColorUIResource(255,128,0),
                                 "InternalFrame.borderColor", new ColorUIResource(Color.gray),
                                 "InternalFrame.activeTitleForeground", new ColorUIResource(Color.white),
                                 "InternalFrame.activeTitleBackground", new ColorUIResource(Color.gray),
                                 "InternalFrame.borderColor", new ColorUIResource(Color.white),
                                 "Table.selectionBackground",new ColorUIResource(255,128,0)
                       table.putDefaults(defaults);
        public static void main(String argv[]) {
            TestTheDialog tester = new TestTheDialog();
    import javax.swing.JDialog;
    import java.awt.event.ActionListener;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JButton;
    import java.awt.event.ActionEvent;
    public class CustomDialog extends JDialog implements ActionListener {
        private JPanel myPanel = null;
        private JButton yesButton = null;
        private JButton noButton = null;
        private boolean answer = false;
        public boolean getAnswer() { return answer; }
        public CustomDialog(){
        public CustomDialog(JFrame frame, boolean modal, String myMessage) {
            super(frame, modal);
            setTitle("Guess?");
            myPanel = new JPanel();
            getContentPane().add(myPanel);
            myPanel.add(new JLabel(myMessage));
            yesButton = new JButton("Yes");
            yesButton.addActionListener(this);
            myPanel.add(yesButton);       
            noButton = new JButton("No");
            noButton.addActionListener(this);
            myPanel.add(noButton);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            pack();
            setLocationRelativeTo(frame);
            setVisible(true);
        public void actionPerformed(ActionEvent e) {
            if(yesButton == e.getSource()) {
                System.err.println("User chose yes.");
                answer = true;
                setVisible(false);
            else if(noButton == e.getSource()) {
                System.err.println("User chose no.");
                answer = false;
                setVisible(false);
    }Thanks and Regards
    Kumar.

  • Series of JDialog boxes

    Hi everyone,
    While installing any software we usually come across a series of dialog boxes with 'Back'
    and 'Next' buttons; I have to do something similar in our project. I am generating a series of dialog boxes without any problem using JDialog in Swing. But the problem is
    When the user enters some values in first dialog box and clicks 'Next' button and goes to the
    second dialog box and then comes back to the first dialog box using the 'Back' button in the second dialog box, I have to display the first dialog box with those values which the user entered previously so that he need not enter them again. How to do this?
    Thanks in advance. (I actually did it successfully by using event handling, but is there a better way of doing it like writing the values entered by the user into some text file and then retrieving them from the text file while displaying the dialog box?)

    Here's one way. Your dialog class should implement an interface such as
    public interface InputPage
    public void takeState (Hashtable ht);
    public void giveState (Hashtable ht);
    A "director" class maintains the sequence of InputPage implementations
    and listens for "next" and "back" events. When a page comes into view,
    that director invokes takeState(); and when a page goes out of view, the
    director invokes giveState(). In this way, the pages propogate the data
    back and forth.

  • Displaying JDialog box in front of all windows

    Hi guys,
    I am trying to display a Dialog box with some error message.
    I did it using the following code
    import java.awt.*;
    import javax.swing.*;
    public class JDialog_test {
         public static void main(String args[])
              Frame oframe=new Frame("JDialog Error Message");
              JDialog odialog=new JDialog(oframe,"Praveen",true);
              odialog.setModal(true);
              System.out.println("the modal is set as "+odialog.isModal());
              //odialog.setAlwaysOnTop(true);
              odialog.setVisible(true);
              System.out.println("In displayable is set as "+odialog.isDisplayable());
              odialog.toFront();
    When i run the above code, a dialog box is created successfully.
    But the problem is the dialog box is not displayed in front of all screens.
    Also the dialog box disappears when i open another window.
    Now what i require is???
    ->the dialog box should be displayed on top of all the windows
    ->as long as the dialog box is not closed , i should not be able to access other windows
    Please don put the setModal() method as solution, it isnt working.
    Also i want the solution to be compatible with only java 1.4 compiler.
    Please get back with solutions.

    import java.awt.Dimension;
    import javax.swing.*;
    public class JDialog_test {
         public static void main(String args[])
              JFrame jframe=new JFrame("JFrame");
              jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              jframe.setVisible(true);
              jframe.setSize(new Dimension(200,300));
              JDialog jdialog=new JDialog(jframe,"JDialog",true);
              jdialog.setModal(true);
              jdialog.setSize(new Dimension(100,200));
              jframe.setVisible(true);
              jdialog.setAlwaysOnTop(true); //<-- here's the trick..
              jdialog.setModal(true);
              jdialog.setVisible(true);
              jdialog.toFront();
    }

  • Closing a JDialog box

    Hi,
    I've got a JList inside of a JDialog. When the user selects an item in the JList I would like the JDialog to close automatically instead of requiring the user the manually close the dialog box. Any ideas?
    thanks,
    Roberto Samarone Araujo

    Try something like this:
    JList list = <whatever>;
    JDialog dialog = <whatever?; // may have to be declared final
    // put them together however you want
    list.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            dialog.dispose();
            // do whatever else you want to happen when a selection is made
    });Shaun

  • JDialog box with room to type in a file name or browse files

    Can anyone please tell me how to get a box with the message please choose a file to open, a strip for the user to type a file name into, with a browse button to the right for finding files, and then an ok button underneath.
    Thanks tonnes

    Here's the whole function in its current state:
    public File getOutputFile() throws IOException {
    int result = chooser.showSaveDialog(FileInputFrame.this);
    if(result == JFileChooser.APPROVE_OPTION)
    { String fileName = new String();
    System.out.println(chooser.getSelectedFile());
    fileName = chooser.getSelectedFile().getAbsolutePath();
    System.out.println(fileName);
    File aFile = new File(fileName);
    return aFile;
    else
    return null;
    I'm using JBuilder, so it always says which line the exception is on, and it is always thrown at the first line where chooser.getSelectedFile() is dereferenced, so I'm pretty sure that it is returning null for whatever reason.
    I have the default directory set to "~", so it comes up with a listing of everything in my home directory. Then I just type in a name that does not appear on that list, and poof, exceptions galore.
    OK, here's a really wierd thing. If I use the name of a file that already exists in my home directory but save it in some random subdirectory, there is no problem. But, if I use the name of a file that exists nowhere in that same subdirectory, I get the exception.
    I wonder if it is a system permissions problem, as I do not have admin permissions on this machine, although everything is running out of my home directory, so I should have write permissions. I wonder also if it could be system dependent-- I'm running redhat. I don't have a lot of experience trying to interface with the os/file system, that's why I was so happy to find the JFileChooser class in the first place.
    Thanks for your thoughts on this!

  • JDialog boxes aren't drawing properly

    Hi
    I'm busy designing the front end for my final year project at uni (on Netbeans 5.5, although I doubt the problem is due to that), and I've suddenly started getting some strange problems with dialog boxes (seems to be since updating to Java 1.6 SDK, although this could be a co-incidence. The dialog boxes are displaying, but with holes in them, so you can see right through to the main frame underneath, then moving the dialog box will cause it to disappear completely,. only showing components on it when you go over them with the move, but never the background. I managed to combat most of this but making it run:
    this.update(this.getGraphics());
    every time the dialog box is instantiated and on the component move and shown events. This has solved the problem with holes appearing in the window (even if it does create a rather weird trailing effect), but the title bar and border do not refresh, and both still appear initially with holes, eventually completely disappearing.
    The GUI itself does not do anything weird with the dialog box (well now it does with havign to manually trigger the update), it did use different lookandfeels, but I've commented out that for the moment (to no avail).
    This does seem to be quite a big, but I've not found any help on google for this (ah, the friend of all programmers, surely). I've ran the distribution jar files on multiple computers using multiple version of java (well 1.6 and 1.5), and the problem persists. I've check Netbeans generated code, and I can't fault it. I was just wondering if anyone had any idea of a workaround? Even somehow repainting/updating the title and border as well as the main dialog box, or a cure for the bug? Just so I can get some screenshots.
    Thank you for any assistance you can give me.
    Alex

    Just a quick follow-up in case anyone else runs into this problem (and it may well be a few people do), I had to disable aceleration down to disabling DirectX and Direct3D (so you don't have top disable it full), and seems to suggest that there is a [problem with the way that JAVA works with DirectX (or DirectX works with JAVA I suppose, but as this is a recent problem, I would imagine it may well be JAVA which is at fault IMHO).
    Alex                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to put minimise, maximize buttons on jDialog box

    I have a dialog box whose default option is close button provided at top, i have to put minimize, maximize(Restore) buttons.

    Use JFrame?

  • Displaying one JDialog window at a time

    Hi,
    I'm having some trouble trying to write a code where only one JDialog window appears at one time.
    -so when one jdialog box appears, no other jdialog can appear
    -I was thinking about using a boolean but it didn't work at all
    Here's my code:
    iimport javax.swing.*;
    import java.awt.event.*;
    public class Data extends JFrame
         JMenuItem existingRental;
         JMenuItem newRental;
         boolean one = true;
         public Data(){
              createMainMenu();
              setSize(350, 100);
              setVisible(true);
              setLocationRelativeTo(null);
              setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         public static void main(String[] args){
              new Data();
         private void createMainMenu(){
              JMenuBar mainMenuBar = new JMenuBar();  //notice - used JMenuBar
              setJMenuBar(mainMenuBar);
              JMenu windowMenu = new JMenu("Window");
              windowMenu.setMnemonic('w');
              mainMenuBar.add(windowMenu);
              newRental = new JMenuItem("New Rental");
              newRental.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));
              newRental.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                        new Rental();
                        one = true;
                        if(!one)
                             new ExistingRentals();
              existingRental = new JMenuItem("Existing Rentals");
              existingRental.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.CTRL_MASK));
              existingRental.addActionListener(new ActionListener(){
                   public void actionPerformed(ActionEvent e){
                        new ExistingRentals();
                        one = true;
                        if(!one)
                             new Rental();
              windowMenu.add(newRental);
              windowMenu.add(existingRental);
    }JDialog two
    import javax.swing.*;]
    import java.awt.*;
    public class ExistingRentals extends JDialog
         private JList list;
         private JScrollBar scrollHorizontal;
         public ExistingRentals()
              existingRentalAgreement();
              setTitle("Rental List");
              setSize(200, 500);
              setVisible(true);
              setLocationRelativeTo(null);
         public void existingRentalAgreement()
              Container container = getContentPane();
              container.setLayout(new BorderLayout());
              list = new JList();
              scrollHorizontal = new JScrollBar(JScrollBar.HORIZONTAL);
              add(scrollHorizontal, BorderLayout.SOUTH);
              scrollHorizontal.add(list);
    }

    What if you made your jdialog modal. this can be done by passing a boolean parameter set to "true" to the JDialog super constructor. Here is what I mean with some other minor changes:
    ExistingRentals class ----------------------------------------
    import javax.swing.*;
    import java.awt.*;
    public class ExistingRentals extends JDialog
        private JList list;
        private JScrollBar scrollHorizontal;
        public ExistingRentals(JFrame parent, String title)
            super(parent, true); // true here makes dialog modal.[captain.obvious]false does the opposite[/captain.obvious]
            existingRentalAgreement();
            setTitle(title);
            setSize(200, 500);
            setVisible(true);
            setLocationRelativeTo(null);
        public void existingRentalAgreement()
            Container container = getContentPane();
            container.setLayout(new BorderLayout());
            list = new JList();
            scrollHorizontal = new JScrollBar(JScrollBar.HORIZONTAL);
            add(scrollHorizontal, BorderLayout.SOUTH);
            scrollHorizontal.add(list);
    import javax.swing.*;
    import java.awt.event.*;
    public class Data extends JFrame
        JMenuItem existingRental;
        JMenuItem newRental;
        boolean one = true;
        public Data() {
            createMainMenu();
            setSize(350, 100);
            setVisible(true);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        public static void main(String[] args)
            new Data();
        private void createMainMenu()
            JMenuBar mainMenuBar = new JMenuBar(); // notice - used JMenuBar
            setJMenuBar(mainMenuBar);
            JMenu windowMenu = new JMenu("Window");
            windowMenu.setMnemonic('w');
            mainMenuBar.add(windowMenu);
            newRental = new JMenuItem("New Rental");
            newRental.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N,
                    ActionEvent.CTRL_MASK));
            newRental.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    newRentalAction(e);
            existingRental = new JMenuItem("Existing Rentals");
            existingRental.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E,
                    ActionEvent.CTRL_MASK));
            existingRental.addActionListener(new ActionListener()
                public void actionPerformed(ActionEvent e)
                    existingRentalAction(e);
            windowMenu.add(newRental);
            windowMenu.add(existingRental);
        private void existingRentalAction(ActionEvent e)
            new ExistingRentals(this, "Existing Rental List");
            // one = true;
            // if (!one) new Rental();
        private void newRentalAction(ActionEvent e)
            // one = true;
            // if (!one)
            new ExistingRentals(this, "New Rental List");
            // new Rental();
    }

  • Retrieve 4 inputs from one dialog box at a time

    I have a Jframe and when I click a button I want it to open a new Jdialog box. I want 4 different input fields. Two will be for strings, 1 int, 1 double. But I can't get it to open up a dialog with all of those things. Will I have to accept them all as strings then convert them to double and int? and what will the code for 4 input fields in a dialog box look like? If you need more info just ask... And I'm using Netbeans, if this makes it easier.

    You could design a custom JDialog or whip up something simpler with JOptionPane:
    import java.awt.*;
    import javax.swing.*;
    public class JOptionPaneExample {
        public static void main(String[] args) {
            JPanel p = new JPanel(new GridLayout(2, 2));
            p.add(new JLabel("name:"));
            p.add(new JTextField(10));
            p.add(new JLabel("age:"));
            p.add(new JTextField(10));
            int result = JOptionPane.showConfirmDialog(null, p, "title",
                JOptionPane.OK_CANCEL_OPTION,
                JOptionPane.PLAIN_MESSAGE);
    }

  • Value from JDialog to another class

    Hi:
    I have a trouble with getting my values from a JDialog box to another class.
    Here's what I have:
    This is an ftp application. I have a main frame where if the user selects File->New Connection
    it pops up a Connect dialog box. The connect dialog box has various fields such as profile name, host address, user name, and so on. In addition, there are three buttons, Add, Connect and Cancel.
    After the user types info and clicks Connect, all these information should be sent to the main frame from where it would send the information to another class which would connect to the ftp server.
    I have a class called Profile which is used to wrap these information to be sent to the main frame.
    Now, how can i get this info to the main frame? Here's the code in main frame:
    class MainFrame extends JFrame {
    JMenuItem newconnection = new JMenuItem("New Connection", 'N');
    newconnection.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    Profile p = new Profile();
    ConnectDialog con = new ConnectDialog();
    p = con.getProfile();
    makeNewConnection(p); //this is the method i use to make a new connection
    The problem is that by the time i get to the line p = con.getProfile(),
    con object no longer exists.
    Should i use threads or should i just send the main frame as the parameter to create the Connect dialog. If i use threads, how should i code it, and if i use main frame as the parent frame for connect dialog, how do i get the info to main frame. Please help. Here's the code for ConnectDialog. Also, please advice if ConnectDialog code can be improved since i am new to swing. Thanks for helping a needy student.
    public class ConnectDialog extends JDialog{
    private MainFrame parent;
    private String defaultDownloadPath;
    private static Profile currProfile;
    private JList profileList;
    private JPanel listPanel;
    private JPanel infoPanel;
    private JPanel labelPanel;
    private JPanel buttonPanel;
    private JPanel arrangedComponents;
    private Vector data;
    private JLabel ProfileName;
    private JLabel HostAddress;
    private JLabel Account;
    private JLabel PortNo;
    private JLabel login;
    private JLabel password;
    private JLabel DownLoadPath;
    private JButton addButton;
    private JButton cancelButton;
    private JButton connectButton;
    private JButton browseButton;
    private JButton clearButton;
    private JLabel Anonymous;
    private JCheckBox anonymous;
    private JTextField profileName;
    private JTextField hostAddress;
    private JTextField account;
    private JTextField portNo;
    private JTextField loginName;
    private JTextField passwd;
    private JTextField downloadPath;
    private final int textSize = 20;
    private final int fontSize = 12;
    private Container cp;
    public ConnectDialog(MainFrame main) {
    super(main, true);
    parent = main;
    data = new Vector();
    currProfile = new Profile();
    profileList = new JList(data);
    listPanel = new JPanel();
    labelPanel = new JPanel();
    infoPanel = new JPanel();
    buttonPanel = new JPanel();
    arrangedComponents = new JPanel();
    ProfileName = new JLabel("Profile Name:");
    ProfileName.setForeground(Color.black);
    HostAddress = new JLabel("Host Address:");
    HostAddress.setForeground(Color.black);
    Account = new JLabel("Account:");
    Account.setForeground(Color.black);
    PortNo = new JLabel("Port:");
    PortNo.setForeground(Color.black);
    login = new JLabel("Login:");
    login.setForeground(Color.black);
    password = new JLabel("Password:");
    password.setForeground(Color.black);
    DownLoadPath = new JLabel("Download Path:");
    DownLoadPath.setForeground(Color.black);
    addButton = new JButton("Add");
    addButton.setMnemonic('A');
    addButton.setForeground(Color.black);
    cancelButton = new JButton("Cancel");
    cancelButton.setForeground(Color.black);
    clearButton = new JButton("Clear");
    clearButton.setForeground(Color.black);
    connectButton = new JButton("Connect");
    connectButton.setForeground(Color.black);
    connectButton.setMnemonic('C');
    browseButton = new JButton("Browse");
    browseButton.setForeground(Color.black);
    browseButton.setMnemonic('B');
    Anonymous = new JLabel("Anonymous: ");
    Anonymous.setForeground(Color.black);
    anonymous = new JCheckBox();
    profileName = new JTextField(textSize);
    profileName.setText("");
    profileName.setBorder(BorderFactory.createLoweredBevelBorder());
    profileName.setBorder(BorderFactory.createLineBorder(Color.black));
    profileName.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    hostAddress = new JTextField(textSize);
    hostAddress.setText("");
    hostAddress.setBorder(BorderFactory.createEtchedBorder());
    hostAddress.setBorder(BorderFactory.createLineBorder(Color.black));
    hostAddress.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    account = new JTextField(textSize);
    account.setText("");
    account.setBorder(BorderFactory.createLoweredBevelBorder());
    account.setBorder(BorderFactory.createLineBorder(Color.black));
    account.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    portNo = new JTextField(5);
    portNo.setText("");
    portNo.setText("21");
    portNo.setBorder(BorderFactory.createEtchedBorder());
    portNo.setBorder(BorderFactory.createLineBorder(Color.black));
    portNo.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    loginName = new JTextField(textSize);
    loginName.setText("");
    loginName.setBorder(BorderFactory.createEtchedBorder());
    loginName.setBorder(BorderFactory.createLineBorder(Color.black));
    loginName.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    passwd = new JTextField(textSize);
    passwd.setText("");
    passwd.setBorder(BorderFactory.createEtchedBorder());
    passwd.setBorder(BorderFactory.createLineBorder(Color.black));
    passwd.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    downloadPath = new JTextField(textSize);
    downloadPath.setText("");
    downloadPath.setBorder(BorderFactory.createEtchedBorder());
    downloadPath.setBorder(BorderFactory.createLineBorder(Color.black));
    downloadPath.setFont(new Font("Dialog",Font.PLAIN,fontSize));
    cp = this.getContentPane();
    this.setBounds(200,200,600,300);
    this.setResizable(false);
    cp.setLayout(new BorderLayout());
    setListPanel();
    setLabelPanel();
    setButtonPanel();
    setActionListeners();
    this.setBackground(Color.lightGray);
    this.setVisible(true);
    this.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    public String getDefaultDownloadPath() {
    return defaultDownloadPath;
    // public Profile getProfile() {
    // try {
    // this.wait();
    // } catch (Exception e) {}
    // return currProfile;
    public void setListPanel() {
    profileList.setFont(new Font("Dialog", Font.PLAIN, 12));
    profileList.setBackground(Color.white);
    profileList.setForeground(Color.black);
    profileList.setPrototypeCellValue("MMMMMMMMM");
    listPanel.setPreferredSize(profileList.getPreferredScrollableViewportSize());
    listPanel.setBorder(BorderFactory.createEtchedBorder());
    listPanel.setBorder(BorderFactory.createLineBorder(Color.black));
    listPanel.setBackground(Color.white);
    listPanel.add(profileList);
    cp.add(listPanel, "West");
    public void setLabelPanel() {
    arrangedComponents = new JPanel();
    arrangedComponents.setLayout(new BorderLayout());
    labelPanel = new JPanel();
    labelPanel.setLayout(new BoxLayout(labelPanel, BoxLayout.Y_AXIS));
    labelPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    JPanel row1 = new JPanel();
    row1.add(ProfileName);
    labelPanel.add(row1);
    JPanel row2 = new JPanel();
    row2.add(HostAddress);
    labelPanel.add(row2);
    JPanel row3 = new JPanel();
    row3.add(Account);
    labelPanel.add(row3);
    JPanel row4 = new JPanel();
    row4.add(PortNo);
    labelPanel.add(row4);
    JPanel row5 = new JPanel();
    row5.add(login);
    labelPanel.add(row5);
    JPanel row6 = new JPanel();
    row6.add(password);
    labelPanel.add(row6);
    JPanel row7 = new JPanel();
    row7.add(DownLoadPath);
    labelPanel.add(row7);
    infoPanel.setLayout(new BoxLayout(infoPanel,BoxLayout.Y_AXIS));
    infoPanel.setAlignmentX(JPanel.LEFT_ALIGNMENT);
    row1 = new JPanel();
    row1.add(profileName);
    row1.add(profileName);
    infoPanel.add(row1);
    row2 = new JPanel();
    row2.add(hostAddress);
    row2.add(hostAddress);
    infoPanel.add(row2);
    row3 = new JPanel();
    row3.add(account);
    infoPanel.add(row3);
    row4 = new JPanel();
    row4.setLayout(new FlowLayout());
    row4.add(portNo);
    row4.add(Box.createHorizontalStrut(57));
    row4.add(Anonymous);
    row4.add(anonymous);
    infoPanel.add(row4);
    row5 = new JPanel();
    row5.add(loginName);
    infoPanel.add(row5);
    row6 = new JPanel();
    row6.add(passwd);
    infoPanel.add(row6);
    row7 = new JPanel();
    row7.setLayout(new FlowLayout());
    row7.add(downloadPath);
    row7.add(browseButton);
    infoPanel.add(row7);
    arrangedComponents.add(labelPanel, "West");
    arrangedComponents.add(infoPanel, "Center");
    cp.add(arrangedComponents, "Center");
    public void setButtonPanel() {
    buttonPanel.setLayout(new FlowLayout());
    buttonPanel.add(addButton);
    buttonPanel.add(connectButton);
    buttonPanel.add(cancelButton);
    buttonPanel.add(clearButton);
    cp.add(buttonPanel, "South");
    public void setActionListeners() {
    anonymous.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         if(anonymous.isSelected()) {
         loginName.setText("anonymous");
         passwd.setText("your email here");
         else {
         loginName.setText("");
         passwd.setText("");
    addButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         if(profileName.getText() != "" && !data.contains(profileName.getText())){
         data.add(profileName.getText());
         profileList.setListData(data);
    connectButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         connectButtonPressed();
    cancelButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         JButton b = (JButton) e.getSource();
         ConnectDialog c = (ConnectDialog) b.getTopLevelAncestor();
         c.dispose();
    clearButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         profileName.setText("");
         hostAddress.setText("");
         account.setText("");
         portNo.setText("");
         loginName.setText("");
         passwd.setText("");
         downloadPath.setText("");
    browseButton.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
         JFrame browseFrame = new JFrame("browse for folder");
         browseFrame.setBounds(230,230,200,200);
         JDirectoryChooser fileChooser = new JDirectoryChooser();
         fileChooser.setFileSelectionMode(JDirectoryChooser.DIRECTORIES_ONLY);
         int option = fileChooser.showDialog(browseFrame);
         if(option==JFileChooser.APPROVE_OPTION) {
         File f = fileChooser.getSelectedFile();
         defaultDownloadPath = f.getAbsolutePath();
         downloadPath.setText(defaultDownloadPath);
    public void connectButtonPressed() {
    if(!profileName.getText().equals("") && !hostAddress.getText().equals("") &&
    !loginName.getText().equals("") && !passwd.getText().equals("")) {
    currProfile.setProfileName(profileName.getText());
    currProfile.setHostAddress(hostAddress.getText());
    currProfile.setAcct(account.getText());
    currProfile.setUserName(loginName.getText());
    currProfile.setPassword(passwd.getText());
    currProfile.setDownloadPath(downloadPath.getText());
    parent.setProfile(currProfile);
    this.dispose();
    else {
    JFrame f = new JFrame("Error!");
    JOptionPane.showMessageDialog(f, "Some fields empty!", "", JOptionPane.ERROR_MESSAGE);
    }

    If the dialog is modal then you can just call show and wait for it to close by the user, then grab the info:
    ConnectDialog dialog = new ConnectDialog();
    dialog .show();
    Profile profile = con.getProfile();
    makeNewConnection( profile );

  • Connecting to MySql Database via a JDialog

    Hello,
    I have a JDialog Box that connects the user to a database, the username is taken through a JTextField and passwork through JPassword field the problem is that the password isn't evaluated rightly........... and hence the application ends in an exception. Here is the code of the method which is executed when a button is pressed....
    void UserLogin(ActionEvent e) {
      Connection con;
      user = UserName.getText();
      pass = Password.getPassword().toString();
      try{
       Class.forName("com.mysql.jdbc.Driver");
      catch (Exception se){
      se.printStackTrace();
      try{
       con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test?user="+user+"&password="+Password.getPassword());// I used the variable pass too but it wouldn't work, the variable user is perfect
       System.out.println(con.toString());
       catch (Exception se){
        se.printStackTrace();
       System.out.println(pass);
       this.setVisible(false);
    }Please solve this problem for me!

    Overview Package Class Use Tree Deprecated Index Help
    JavaTM 2 Platform
    Standard Ed. 5.0
    PREV CLASS NEXT CLASS FRAMES NO FRAMES All Classes
    SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
    java.lang
    Class String
    java.lang.Object
    java.lang.String
    All Implemented Interfaces:
    Serializable, CharSequence, Comparable<String>
    public final class Stringextends Objectimplements Serializable, Comparable<String>, CharSequenceThe String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class.
    Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Because String objects are immutable they can be shared. For example:
    String str = "abc";
    is equivalent to:
    char data[] = {'a', 'b', 'c'};
    String str = new String(data);
    Here are some more examples of how strings can be used:
    System.out.println("abc");
    String cde = "cde";
    System.out.println("abc" + cde);
    String c = "abc".substring(2,3);
    String d = cde.substring(1, 2);
    The class String includes methods for examining individual characters of the sequence, for comparing strings, for searching strings, for extracting substrings, and for creating a copy of a string with all characters translated to uppercase or to lowercase. Case mapping is based on the Unicode Standard version specified by the Character class.
    The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the method toString, defined by Object and inherited by all classes in Java.

Maybe you are looking for

  • Does anyone know if the mail on I cloud is down?

    For some reason my mail on Icloud is not connecting. Does anybody know if it is down today?

  • Forum Sticky???

    Is the forum sticky today? Or is it just my neck of the woods ....  

  • JMS Messages

    Hi All To place the asynchronous JMS messages in a receiver system incoming queue what are the configuration steps we need to follow in XI? Is JMS adapter is used to communicate with JMS systems or to generate the JMS messages? If receiver is webserv

  • Creating a crosstab

    It it possible to build your own crosstab? After reading several posts, I believing that there may be a way.  I need more control over my crosstabs, and if there is a way to build your own, I'd suely like to know.  The Crosstab would have to be place

  • Connect vcr to imac

    I have a Toshiba upconverting VCR/DVD that has an HDMI output. To reduce signal losses, eliminate one step before editing, and store files more efficiently, I want to connect it directly to my imac and import them directly rather than create a DVD fi