Java - Problema con pantallas en monitor dual

 
Vista:
Imágen de perfil de Cherry

Problema con pantallas en monitor dual

Publicado por Cherry (5 intervenciones) el 09/03/2017 16:54:41
Hola! Estoy haciendo un proyecto para pasar el rato y practicar un poco de java. El programa es bien básico, consta de unJFrame que tiene labels que uso como botones para abrir paginas en el navegador y asi tener organizadas las páginas que más uso (se que sería más fácil usar la opción de favoritos, pero es por diversión esto jaja).
Y la idea de este programa, es que siempre quede visible en un monitor, para tenerlo a mano y no tener que estar abriéndolo.
El problema con esto es que uso dos monitores conectados a la compu. Ya logre configurar para que el JFrame se abra siempre en un determinado monitor, pero cuando hago click, por ej en el navegador que se abre en el otro monitor, el JFrame se minimiza.
Probé ponerle que este siempre "OnTop", pero lo único que logré fue que no pueda seleccionar otra ventana más que esa. También probé que cuando pierda el focus vuelva a frente, pero tampoco no funcionó.

Les dejo el código para ver si alguien puede ayudarme con esto. Saludos!!


package view;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import controlador.Assistant;

import javax.swing.JLabel;
import javax.swing.ImageIcon;
import java.awt.Font;
import java.awt.Frame;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.Window;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;

import javax.swing.JTextArea;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowFocusListener;
import java.awt.event.WindowEvent;


public class LinksScreen extends JFrame {

/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private final int fijo=200;

public LinksScreen(Assistant assistant) {
addWindowFocusListener(new WindowFocusListener() {
public void windowGainedFocus(WindowEvent arg0) {

}
public void windowLostFocus(WindowEvent arg0) {
show();
setAutoRequestFocus(false);
setExtendedState(MAXIMIZED_BOTH);
}
});
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//this.setAlwaysOnTop(true);

//setBounds(100, 100, 1280, 760);
Dimension dim = Toolkit.getDefaultToolkit().getScreenSize();
setBounds(100, 100, (int) dim.getWidth(), (int) dim.getHeight());
this.setExtendedState(MAXIMIZED_BOTH);
this.setLocationRelativeTo(null);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);



JLabel btnGoogle = new JLabel("New label");
btnGoogle.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
URL pagina = null;
try {

pagina = new URL("http://www.google.com");


} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
openWebpage(pagina);
contentPane.grabFocus();
}
});


btnGoogle.setBounds(20, 161, fijo,fijo);

ImageIcon iconGoogle = new ImageIcon(LinksScreen.class.getResource("/images/horo_links.png"));
Image imgGoogle = iconGoogle.getImage() ;
Image newimgGoogle = imgGoogle.getScaledInstance( btnGoogle.getWidth(), btnGoogle.getHeight(), java.awt.Image.SCALE_SMOOTH ) ;
iconGoogle = new ImageIcon( newimgGoogle );
btnGoogle.setIcon(iconGoogle);


JLabel Google = new JLabel("Google");
Google.setForeground(new Color(128, 0, 0));
Google.setFont(new Font("Old English Text MT", Font.BOLD, 38));
Google.setBounds(95, 362, 95, 59);

contentPane.add(btnGoogle);

JLabel btnGmail = new JLabel("New label");
btnGmail.setIcon(new ImageIcon(LinksScreen.class.getResource("/images/snow.jpg")));
btnGmail.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
URL pagina = null;
try {
pagina = new URL("https://mail.google.com/");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
openWebpage(pagina);
}
});
btnGmail.setBounds(20, 425, fijo, fijo);

ImageIcon iconGmail = new ImageIcon(LinksScreen.class.getResource("/images/snow.jpg"));
Image imgGmail = iconGmail.getImage() ;
Image newimgGmail = imgGmail.getScaledInstance( btnGmail.getWidth(), btnGmail.getHeight(), java.awt.Image.SCALE_SMOOTH ) ;
iconGmail = new ImageIcon( newimgGmail );
btnGmail.setIcon(iconGmail);

contentPane.add(btnGmail);

JLabel btnTE = new JLabel("New label");
btnTE.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
URL pagina = null;
try {
pagina = new URL("http://www.hotmail.com");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
openWebpage(pagina);
}
});
btnTE.setIcon(new ImageIcon(LinksScreen.class.getResource("/images/fairy tail sleeper 200.png")));
btnTE.setBounds(258, 425, fijo,fijo);

ImageIcon iconTE = new ImageIcon(LinksScreen.class.getResource("/images/fairy tail sleeper 200.png"));
Image imgTE = iconTE.getImage() ;
Image newimgTE = imgTE.getScaledInstance( btnTE.getWidth(), btnTE.getHeight(), java.awt.Image.SCALE_SMOOTH ) ;
iconTE = new ImageIcon( newimgTE);
btnTE.setIcon(iconTE);
contentPane.add(btnTE);



JLabel btn9gag = new JLabel("New label");
btn9gag.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
URL pagina = null;
try {
pagina = new URL("http://www.9gag.com");
} catch (MalformedURLException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
openWebpage(pagina);
}
});
btn9gag.setIcon(new ImageIcon(LinksScreen.class.getResource("/images/Sakura icon2.jpg")));
btn9gag.setBounds(493, 425, fijo,fijo);
ImageIcon icon9gag = new ImageIcon(LinksScreen.class.getResource("/images/Sakura icon2.jpg"));
Image img9gag = icon9gag.getImage() ;
Image newimg9gag = img9gag.getScaledInstance( btn9gag.getWidth(), btn9gag.getHeight(), java.awt.Image.SCALE_SMOOTH ) ;
icon9gag = new ImageIcon( newimg9gag);
btn9gag.setIcon(icon9gag);

contentPane.add(btn9gag);
contentPane.add(Google);

JLabel lblGmail = new JLabel("Gmail");
lblGmail.setForeground(new Color(128, 0, 0));
lblGmail.setFont(new Font("Old English Text MT", Font.BOLD, 38));
lblGmail.setBounds(85, 653, 135, 31);
contentPane.add(lblGmail);

JLabel lblNewLabel = new JLabel("Hotmail");
lblNewLabel.setForeground(new Color(128, 0, 0));
lblNewLabel.setFont(new Font("Old English Text MT", Font.BOLD, 38));
lblNewLabel.setBounds(287, 653, 135, 32);
contentPane.add(lblNewLabel);

JLabel lbl9gag = new JLabel("9gag");
lbl9gag.setForeground(new Color(128, 0, 0));
lbl9gag.setFont(new Font("Old English Text MT", Font.BOLD, 38));
lbl9gag.setBounds(526, 653, 147, 32);
contentPane.add(lbl9gag);



JTextArea txtTitle = new JTextArea();
txtTitle.setEditable(false);
txtTitle.setForeground(new Color(128, 0, 0));
txtTitle.setFont(new Font("Old English Text MT", Font.BOLD, 40));
txtTitle.setText("Somefoxy once told me links\r\n you need "+assistant.getUserActual().getName());
txtTitle.setBounds(35, 24, 623, 111);
txtTitle.setBackground(new Color(0, 0, 0, 0));
contentPane.add(txtTitle);


/*
JLabel lblBackground = new JLabel("New label");
lblBackground.setIcon(new ImageIcon(LinksScreen.class.getResource("/images/HoroBackgroundListo2.jpg")));
lblBackground.setBounds(0, -47, 1280, 800);
contentPane.add(lblBackground);*/


JLabel lblBackground = new JLabel("");
lblBackground.setIcon(new ImageIcon(LinksScreen.class.getResource("/images/HoroBackgroundListo2.jpg")));
lblBackground.setBounds(0, -47, (int) dim.getWidth(), (int) dim.getHeight());


ImageIcon iconBackground = new ImageIcon(LinksScreen.class.getResource("/images/HoroBackgroundListo2.jpg"));
Image imgBackground = iconBackground.getImage() ;
Image newimgBackground = imgBackground.getScaledInstance( (int) dim.getWidth(), (int) dim.getHeight(), java.awt.Image.SCALE_SMOOTH ) ;
iconBackground = new ImageIcon( newimgBackground);
lblBackground.setIcon(iconBackground);
contentPane.add(lblBackground);





//BOTON Y LABEL FIN

}


private static void openWebpage(URI uri) {
Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
try {
desktop.browse(uri);
} catch (Exception e) {
e.printStackTrace();
}
}
}

private static void openWebpage(URL url) {
try {
openWebpage(url.toURI());
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Problema con pantallas en monitor dual

Publicado por Renzo (232 intervenciones) el 09/03/2017 19:45:17
Probaste con setAlwaysOnTop(true);
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Cherry

Problema con pantallas en monitor dual

Publicado por Cherry (5 intervenciones) el 09/03/2017 21:42:13
Si, probé, pero no funcionó :/
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema con pantallas en monitor dual

Publicado por Renzo (232 intervenciones) el 09/03/2017 21:43:59
Prueba esta clase:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.awt.Desktop;
import java.awt.Font;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
 
import javax.swing.JFrame;
import javax.swing.JLabel;
 
 
public class Prueba2 extends JFrame {
 
 
	public Prueba2(){
 
		JLabel l=new JLabel("kenny");
		l.setFont(new Font("Arial",Font.BOLD,35));
		add(l);
 
		setUndecorated(true);
		setVisible(true);
		setBounds(0,0,300,300);
		setLocationRelativeTo(null);
		setAlwaysOnTop(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
	}
 
	public static void main(String[] args) {
		Prueba2 p=new Prueba2();
	}
 
	private static void openWebpage(URI uri) {
		Desktop desktop = Desktop.isDesktopSupported() ? Desktop.getDesktop() : null;
		if (desktop != null && desktop.isSupported(Desktop.Action.BROWSE)) {
		try {
		desktop.browse(uri);
 
		} catch (Exception e) {
		e.printStackTrace();
		}
		}
		}
 
		private static void openWebpage(URL url) {
		try {
		openWebpage(url.toURI());
		} catch (URISyntaxException e) {
		e.printStackTrace();
		}
		}
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Cherry

Problema con pantallas en monitor dual

Publicado por Cherry (5 intervenciones) el 10/03/2017 19:55:52
Gracias por tu respuesta! me sirvió para otra cosa q tenía mal jaja pero sigue pasando lo mismo cuando abro la clase en el segundo monitor. Cuadno pierde el foco, se sigue minimizando :o
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema con pantallas en monitor dual

Publicado por Renzo (232 intervenciones) el 10/03/2017 20:00:27
Lo del segundo monitor es indiferente del comportamiento de las ventanas pues eso lo controla el sistema operativo.
Lo probaste en un único monitor ?

Renzo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Cherry

Problema con pantallas en monitor dual

Publicado por Cherry (5 intervenciones) el 13/03/2017 13:24:12
Acabo de probar en una sola pantalla, y de todas formas se minimiza :/
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema con pantallas en monitor dual

Publicado por Renzo (232 intervenciones) el 13/03/2017 13:27:20
Conocer te decía, el comportamiento es el mismo.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de Cherry

Problema con pantallas en monitor dual

Publicado por Cherry (5 intervenciones) el 13/03/2017 15:02:34
Ya pude encontrar cual era el error jaja Al final el problema está con el método que llama al jframe: setFullScreenWindow. Probé poniendo el jframe visible, en vez de con ese método y funcionó bien. Ahora solo me falta descifrar como usarlo bien ese método jaja pero gracias por la ayuda! =D
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Problema con pantallas en monitor dual

Publicado por Renzo (232 intervenciones) el 13/03/2017 15:15:16
Estamos para ayudar.

suerte
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar