-1

Im going to be brief, I dont know why when I display a JDialog, the tipical java icon in the top left of the window does not appear. I have this: enter image description here

And it has to be like this:

enter image description here

The code of that window is the following:

The relevant parts are this ones:

JFrame f  = new JFrame();
    JDialog d = new JDialog(f,"Nuevo Municipio",true);
    JPanel formularios = new JPanel();
    JLabel codigo, nombre, provincia, altitud, latitud, longitud;
    JTextField fcod,fnom,fal,flat,flong;
    JButton ok,cancelar;
    JPanel botones = new JPanel();
    GridBagConstraints gbc = new GridBagConstraints();
    //Container contenedor = d.getContentPane();

    formularios.setLayout(new GridBagLayout()); 
   //antes:formularios.setLayout(new GridLayout(6,2));
    d.setLayout(new BorderLayout());
    botones.setLayout(new FlowLayout(FlowLayout.CENTER));
d.add(formularios, BorderLayout.CENTER);

    d.add(botones, BorderLayout.SOUTH);
    d.setSize(new Dimension(450, 300));
    d.setLocationRelativeTo(f);
    d.setResizable(false);
    d.setVisible(true);
victor26567
  • 129
  • 9
  • 2
    "_You dont have to read all the code of course, only the first part_" Read about a [mcve]. – takendarkk Mar 30 '18 at 16:30
  • im gonna edit it and puts the pertinent parts – victor26567 Mar 30 '18 at 16:32
  • 2
    `You dont have to read all the code of course` - well your code should be in the form of an [mcve]. That is your question is about the system menu of the JDialog. So you need to create a frame with a button. When you click the button you display a dialog. There is no need for all the components being added top the dialog. First get the code working without components. Then you add a component and retest. We are not going to look at the code you posted to decide what is or isn't relevant. So we should be able to copy/paste/compile/test. – camickr Mar 30 '18 at 16:32
  • 1
    I suspect it has to do with the PLAF. An MCVE will turn suspicions into knowledge though. – Andrew Thompson Mar 30 '18 at 16:35
  • BTW - the recent edit, made after the first two comments suggesting to post an MCVE, is not an MCVE. Did you actually read the information at the link, or are you just guessing? – Andrew Thompson Mar 30 '18 at 16:38
  • I've just taken your original code and (after removing code not relevant to Swing/AWT rendering) having run it, I do see the Java app icon in the top-left of the window. Andrew's comment seems like a good place to investigate: check which Look & Feel your application is using and try a different one. – Bobulous Mar 30 '18 at 16:38
  • Okay, I've just tried all four Look & Feel options available on my machine, and the icon still appears. Could this be a feature of your operating system window manager? Are you using Windows 10? Do other, non-Java, apps show an app in the top-left? – Bobulous Mar 30 '18 at 16:44
  • Its something very strange, camickr was right in one thing, "adding the things in the Jframe not jdialog" with that, the icon appears, but my dialog, that is modal, if i put all the componentes in the jframe, it isnt modal anymore, and I dont want that – victor26567 Mar 30 '18 at 16:49

1 Answers1

0

It is a reported bug on the Oracle Bug Database. You can easily workaround this issue by setting the icon yourself. To do this, you need to download, or get the default Java Icon (or any icon you want) and refer to it when setting the icon.

Like so:

String URL = "https://dl2.macupdate.com/images/icons256/50734.png?d=1516128506";    
d.setIconImage(new ImageIcon(URL).getImage());
OhleC
  • 2,821
  • 16
  • 29
  • This answer could be improved by including a link to the issue in the "Oracle Bug Database" so that future visitors could check to see if the bug had been fixed. The answer seems fine otherwise. – cardiff space man Mar 30 '18 at 19:15
  • https://bugs.java.com/bugdatabase/view_bug.do?bug_id=4284610 Here is the link of the bug report. – Ábel Sárándi Mar 30 '18 at 19:22
  • i think that my case is not a bug, I test a friend program and I tested in my PC and yes it shows the icon, it is for what I said before, the fact of adding components to JDialog and not the parent JFrame where the JDialog comes from – victor26567 Mar 30 '18 at 22:32