Adapt Java desktop application to any screen

5

Good morning,

I am developing a very simple desktop app to test touch screens.

The thing is that I want an app with 4 buttons that adapt to all screens and that comes out maximized when executed.

Something like that

The rectangles are the 4 buttons and the circle would be an image

Is there a way to lock the logo and that the buttons expand or shrink depending on the screen size?

package javaapplication5;


import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

public class JavaApplication5 {


    public static void main(String[] args) {


        JFrame v=new JFrame();
        v.setExtendedState(JFrame.MAXIMIZED_BOTH);
        JPanel panel=new JPanel();


        JButton btn1=new JButton("Boton 1");
        JButton btn2=new JButton("Boton 2");
        JButton btn3=new JButton("Boton 3");
        JButton btn4=new JButton("Boton 4");
        panel.add(btn1);
        panel.add(btn2);
        panel.add(btn3);
        panel.add(btn4); 




        v.add(panel);

        v.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);






        v.setVisible(true);


         int altoPanel=v.getBounds().getSize().height/2;
         int anchoPanel=v.getBounds().getSize().width;

         int alto=v.getBounds().getSize().height/2;
         int ancho=v.getBounds().getSize().width/2;


            //panel.setPreferredSize(new Dimension(anchoPanel,altoPanel ));

            //tamaño a los botones=1/4 de pantalla

        btn1.setPreferredSize(new Dimension(ancho, alto));
        btn2.setPreferredSize(new Dimension(ancho, alto));
        btn3.setPreferredSize(new Dimension(ancho, alto));
        btn4.setPreferredSize(new Dimension(ancho, alto));
    }

}
    
asked by Sergio Cv 26.10.2016 в 10:23
source

1 answer

2

You could use a border layout for what you need, do not put anything on the top or bottom and place two buttons on the left and right in the center of your image.

link here's an example.

    
answered by 26.10.2016 в 16:25