Skip to main content
import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; import javax.swing.JToggleButton; import javax.swing.JTextPane; import java.awt.Font; import java.awt.Color; import java.awt.SystemColor; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.SwingConstants;

public class pantalla_frame extends JFrame {

import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.JToggleButton;
import javax.swing.JTextPane;
import java.awt.Font;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.SwingConstants;

public class pantalla_frame extends JFrame {

    private JPanel contentPane;
    private JTextField txtUsuari2;
    private JTextField textField;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    pantalla_frame frame = new pantalla_frame();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public pantalla_frame() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 995, 670);
        contentPane = new JPanel();
        contentPane.setBackground(SystemColor.text);
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
                    
        JTextPane txtUsuari = new JTextPane();
        txtUsuari.setText("USUARI");
        txtUsuari.setBackground(SystemColor.controlHighlight);
        txtUsuari.setFont(new Font("Tahoma", Font.PLAIN, 30));
        txtUsuari.setBounds(317, 71, 284, 96);
        txtUsuari.setEditable(false);       
        StyledDocument doc = txtUsuari.getStyledDocument();
        SimpleAttributeSet center = new SimpleAttributeSet();
        StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
        doc.setParagraphAttributes(0, doc.getLength(), center, false);
        contentPane.add(txtUsuari);
        
        txtUsuari2 = new JTextField();
        txtUsuari2.setHorizontalAlignment(SwingConstants.CENTER);
        txtUsuari2.setBounds(317, 178, 284, 38);
        contentPane.add(txtUsuari2);
        txtUsuari2.setColumns(10);
        
        JTextPane txtpnPassword = new JTextPane();
        txtpnPassword.setText("PASSWORD");
        txtpnPassword.setBackground(SystemColor.controlHighlight);
        txtpnPassword.setFont(new Font("Tahoma", Font.PLAIN, 30));
        txtpnPassword.setBounds(317, 227, 284, 96);
        txtpnPassword.setEditable(false); 
        contentPane.add(txtpnPassword);
        StyledDocument doc2 = txtpnPassword.getStyledDocument();
        SimpleAttributeSet center2 = new SimpleAttributeSet();
        StyleConstants.setAlignment(center2, StyleConstants.ALIGN_CENTER);
        doc2.setParagraphAttributes(0, doc2.getLength(), center2, false);
        contentPane.add(txtpnPassword);
        
        textField = new JTextField();
        textField.setHorizontalAlignment(SwingConstants.CENTER);
        textField.setBounds(317, 334, 284, 45);
        contentPane.add(textField);
        textField.setColumns(10);
        
        JButton btn_aceptar = new JButton("ACEPTAR");
        btn_aceptar.setFont(new Font("Tahoma", Font.PLAIN, 17));
        btn_aceptar.setBounds(317, 434, 284, 45);
        contentPane.add(btn_aceptar);
        
        JTextPane txtpnGamnificacioc = new JTextPane();
        txtpnGamnificacioc.setFont(new Font("Segoe Script", Font.PLAIN, 24));
        txtpnGamnificacioc.setText("GamnificacIOC");
        txtpnGamnificacioc.setBounds(0, 0, 208, 71);
        contentPane.add(txtpnGamnificacioc);
    

    
    
 }
}

}

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; import javax.swing.JToggleButton; import javax.swing.JTextPane; import java.awt.Font; import java.awt.Color; import java.awt.SystemColor; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.SwingConstants;

public class pantalla_frame extends JFrame {

private JPanel contentPane;
private JTextField txtUsuari2;
private JTextField textField;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                pantalla_frame frame = new pantalla_frame();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public pantalla_frame() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 995, 670);
    contentPane = new JPanel();
    contentPane.setBackground(SystemColor.text);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);
                
    JTextPane txtUsuari = new JTextPane();
    txtUsuari.setText("USUARI");
    txtUsuari.setBackground(SystemColor.controlHighlight);
    txtUsuari.setFont(new Font("Tahoma", Font.PLAIN, 30));
    txtUsuari.setBounds(317, 71, 284, 96);
    txtUsuari.setEditable(false);       
    StyledDocument doc = txtUsuari.getStyledDocument();
    SimpleAttributeSet center = new SimpleAttributeSet();
    StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
    doc.setParagraphAttributes(0, doc.getLength(), center, false);
    contentPane.add(txtUsuari);
    
    txtUsuari2 = new JTextField();
    txtUsuari2.setHorizontalAlignment(SwingConstants.CENTER);
    txtUsuari2.setBounds(317, 178, 284, 38);
    contentPane.add(txtUsuari2);
    txtUsuari2.setColumns(10);
    
    JTextPane txtpnPassword = new JTextPane();
    txtpnPassword.setText("PASSWORD");
    txtpnPassword.setBackground(SystemColor.controlHighlight);
    txtpnPassword.setFont(new Font("Tahoma", Font.PLAIN, 30));
    txtpnPassword.setBounds(317, 227, 284, 96);
    txtpnPassword.setEditable(false); 
    contentPane.add(txtpnPassword);
    StyledDocument doc2 = txtpnPassword.getStyledDocument();
    SimpleAttributeSet center2 = new SimpleAttributeSet();
    StyleConstants.setAlignment(center2, StyleConstants.ALIGN_CENTER);
    doc2.setParagraphAttributes(0, doc2.getLength(), center2, false);
    contentPane.add(txtpnPassword);
    
    textField = new JTextField();
    textField.setHorizontalAlignment(SwingConstants.CENTER);
    textField.setBounds(317, 334, 284, 45);
    contentPane.add(textField);
    textField.setColumns(10);
    
    JButton btn_aceptar = new JButton("ACEPTAR");
    btn_aceptar.setFont(new Font("Tahoma", Font.PLAIN, 17));
    btn_aceptar.setBounds(317, 434, 284, 45);
    contentPane.add(btn_aceptar);
    
    JTextPane txtpnGamnificacioc = new JTextPane();
    txtpnGamnificacioc.setFont(new Font("Segoe Script", Font.PLAIN, 24));
    txtpnGamnificacioc.setText("GamnificacIOC");
    txtpnGamnificacioc.setBounds(0, 0, 208, 71);
    contentPane.add(txtpnGamnificacioc);
    

    
    
 
}

}

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.JToggleButton;
import javax.swing.JTextPane;
import java.awt.Font;
import java.awt.Color;
import java.awt.SystemColor;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.SwingConstants;

public class pantalla_frame extends JFrame {

    private JPanel contentPane;
    private JTextField txtUsuari2;
    private JTextField textField;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    pantalla_frame frame = new pantalla_frame();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public pantalla_frame() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 995, 670);
        contentPane = new JPanel();
        contentPane.setBackground(SystemColor.text);
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);
                    
        JTextPane txtUsuari = new JTextPane();
        txtUsuari.setText("USUARI");
        txtUsuari.setBackground(SystemColor.controlHighlight);
        txtUsuari.setFont(new Font("Tahoma", Font.PLAIN, 30));
        txtUsuari.setBounds(317, 71, 284, 96);
        txtUsuari.setEditable(false);       
        StyledDocument doc = txtUsuari.getStyledDocument();
        SimpleAttributeSet center = new SimpleAttributeSet();
        StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
        doc.setParagraphAttributes(0, doc.getLength(), center, false);
        contentPane.add(txtUsuari);
        
        txtUsuari2 = new JTextField();
        txtUsuari2.setHorizontalAlignment(SwingConstants.CENTER);
        txtUsuari2.setBounds(317, 178, 284, 38);
        contentPane.add(txtUsuari2);
        txtUsuari2.setColumns(10);
        
        JTextPane txtpnPassword = new JTextPane();
        txtpnPassword.setText("PASSWORD");
        txtpnPassword.setBackground(SystemColor.controlHighlight);
        txtpnPassword.setFont(new Font("Tahoma", Font.PLAIN, 30));
        txtpnPassword.setBounds(317, 227, 284, 96);
        txtpnPassword.setEditable(false); 
        contentPane.add(txtpnPassword);
        StyledDocument doc2 = txtpnPassword.getStyledDocument();
        SimpleAttributeSet center2 = new SimpleAttributeSet();
        StyleConstants.setAlignment(center2, StyleConstants.ALIGN_CENTER);
        doc2.setParagraphAttributes(0, doc2.getLength(), center2, false);
        contentPane.add(txtpnPassword);
        
        textField = new JTextField();
        textField.setHorizontalAlignment(SwingConstants.CENTER);
        textField.setBounds(317, 334, 284, 45);
        contentPane.add(textField);
        textField.setColumns(10);
        
        JButton btn_aceptar = new JButton("ACEPTAR");
        btn_aceptar.setFont(new Font("Tahoma", Font.PLAIN, 17));
        btn_aceptar.setBounds(317, 434, 284, 45);
        contentPane.add(btn_aceptar);
        
        JTextPane txtpnGamnificacioc = new JTextPane();
        txtpnGamnificacioc.setFont(new Font("Segoe Script", Font.PLAIN, 24));
        txtpnGamnificacioc.setText("GamnificacIOC");
        txtpnGamnificacioc.setBounds(0, 0, 208, 71);
        contentPane.add(txtpnGamnificacioc);
    }
}
Origen Enlace
Montse Mkd
  • 1.2k
  • 4
  • 14
  • 38

Centrar botones y TxtPane

estoy empezando a usar Eclipse para hacer una aplicación de escritorio y estoy algo pez.

Me gustaría saber como puedo encontrar la forma que al ampliar la pantalla el resto de objetos también se desplacen. Hay alguna forma de hacerlo?

mi código es el siguiente:

import java.awt.BorderLayout;

import java.awt.EventQueue;

import javax.swing.JFrame; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import javax.swing.text.SimpleAttributeSet; import javax.swing.text.StyleConstants; import javax.swing.text.StyledDocument; import javax.swing.JToggleButton; import javax.swing.JTextPane; import java.awt.Font; import java.awt.Color; import java.awt.SystemColor; import javax.swing.JTextField; import javax.swing.JButton; import javax.swing.SwingConstants;

public class pantalla_frame extends JFrame {

private JPanel contentPane;
private JTextField txtUsuari2;
private JTextField textField;

/**
 * Launch the application.
 */
public static void main(String[] args) {
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                pantalla_frame frame = new pantalla_frame();
                frame.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

/**
 * Create the frame.
 */
public pantalla_frame() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 995, 670);
    contentPane = new JPanel();
    contentPane.setBackground(SystemColor.text);
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(null);
                
    JTextPane txtUsuari = new JTextPane();
    txtUsuari.setText("USUARI");
    txtUsuari.setBackground(SystemColor.controlHighlight);
    txtUsuari.setFont(new Font("Tahoma", Font.PLAIN, 30));
    txtUsuari.setBounds(317, 71, 284, 96);
    txtUsuari.setEditable(false);       
    StyledDocument doc = txtUsuari.getStyledDocument();
    SimpleAttributeSet center = new SimpleAttributeSet();
    StyleConstants.setAlignment(center, StyleConstants.ALIGN_CENTER);
    doc.setParagraphAttributes(0, doc.getLength(), center, false);
    contentPane.add(txtUsuari);
    
    txtUsuari2 = new JTextField();
    txtUsuari2.setHorizontalAlignment(SwingConstants.CENTER);
    txtUsuari2.setBounds(317, 178, 284, 38);
    contentPane.add(txtUsuari2);
    txtUsuari2.setColumns(10);
    
    JTextPane txtpnPassword = new JTextPane();
    txtpnPassword.setText("PASSWORD");
    txtpnPassword.setBackground(SystemColor.controlHighlight);
    txtpnPassword.setFont(new Font("Tahoma", Font.PLAIN, 30));
    txtpnPassword.setBounds(317, 227, 284, 96);
    txtpnPassword.setEditable(false); 
    contentPane.add(txtpnPassword);
    StyledDocument doc2 = txtpnPassword.getStyledDocument();
    SimpleAttributeSet center2 = new SimpleAttributeSet();
    StyleConstants.setAlignment(center2, StyleConstants.ALIGN_CENTER);
    doc2.setParagraphAttributes(0, doc2.getLength(), center2, false);
    contentPane.add(txtpnPassword);
    
    textField = new JTextField();
    textField.setHorizontalAlignment(SwingConstants.CENTER);
    textField.setBounds(317, 334, 284, 45);
    contentPane.add(textField);
    textField.setColumns(10);
    
    JButton btn_aceptar = new JButton("ACEPTAR");
    btn_aceptar.setFont(new Font("Tahoma", Font.PLAIN, 17));
    btn_aceptar.setBounds(317, 434, 284, 45);
    contentPane.add(btn_aceptar);
    
    JTextPane txtpnGamnificacioc = new JTextPane();
    txtpnGamnificacioc.setFont(new Font("Segoe Script", Font.PLAIN, 24));
    txtpnGamnificacioc.setText("GamnificacIOC");
    txtpnGamnificacioc.setBounds(0, 0, 208, 71);
    contentPane.add(txtpnGamnificacioc);
    

    
    

}

}