Ver Mensaje Individual
  #2 (permalink)  
Antiguo 03/05/2016, 17:27
tec01
 
Fecha de Ingreso: noviembre-2014
Mensajes: 17
Antigüedad: 9 años, 6 meses
Puntos: 0
Respuesta: ¿Adaptar GUI a diferentes resoluciones de pantalla?

Solucionado, sería aproximadamente así:
Código:
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.GraphicsEnvironment;
import java.awt.Rectangle;
import java.awt.Color;
import java.awt.Toolkit;
import java.awt.Dimension;

public class TestResolution extends JFrame{

		private JPanel contentPane;
		private static Rectangle bounds;
		private JPanel firstPanel;
		private JPanel secondPanel;
		private JPanel cardPanel;
		private JPanel thirdPanel;
		private static float anchuraContentPane = 1024;
		private static float alturaContentPane = 900;
		private static float relacionX;
		private static float relacionY;
		
		public static void main(String[] args) {
			EventQueue.invokeLater(new Runnable() {

				public void run() {
					try {
						
						Toolkit.getDefaultToolkit().getScreenSize();

						GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
						
				        bounds = env.getMaximumWindowBounds();
				        relacionX = ((int)bounds.getWidth()/anchuraContentPane);
				    	relacionY = ((int)bounds.getHeight()/alturaContentPane);
				    	
						TestResolution frame = new TestResolution();
						frame.pack();
						frame.setVisible(true);

						
					} catch (Exception e) {
						e.printStackTrace();
					}
				}
			});
		}

		
		public TestResolution() {
			setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
			setResizable(false);
			contentPane = new JPanel();
			setContentPane(contentPane);
			contentPane.setPreferredSize(new Dimension((int) bounds.getWidth(), (int) bounds.getHeight()));
			contentPane.setLayout(null);
			
			
					
			firstPanel = new JPanel();
			firstPanel.setBounds(5, 5,Math.round(400*relacionX),Math.round(250*relacionY));
			firstPanel.setBackground(Color.blue);
			firstPanel.setLayout(null);
			contentPane.add(firstPanel);
			
			cardPanel = new JPanel();
			cardPanel.setBounds(
					Math.round(firstPanel.getWidth()+10),
					Math.round(5*relacionY),
					Math.round(580*relacionX)+5,
					Math.round(700*relacionY));
			cardPanel.setBackground(Color.black);
			cardPanel.setLayout(null);
			contentPane.add(cardPanel);


			secondPanel = new JPanel();
			secondPanel.setBounds(
					5,
					Math.round((firstPanel.getHeight()+10)),
					Math.round(200*relacionX), 
					Math.round(450*relacionY));
			secondPanel.setBackground(new Color(0, 0, 0));
			secondPanel.setLayout(null);
			contentPane.add(secondPanel);
			
			thirdPanel = new JPanel();
			thirdPanel.setBounds(
					Math.round((secondPanel.getWidth()+10)),
					Math.round((firstPanel.getHeight()+10)),
					Math.round(195*relacionX), 
					Math.round(450*relacionY));
			thirdPanel.setBackground(new Color(0, 0, 0));
			contentPane.add(thirdPanel);
		}
}
Lo que pasa , es que en Windows no me reconoce taskbar, en linux sí.
Intenté usar GraphicsConfiguration pero no supe usarla...

Última edición por tec01; 04/05/2016 a las 03:20