Estou iniciando os estudos no JavaFX, vejo muitos vídeos na internet e nunca acho “nada” bom a respeito. A minha dúvida é o seguinte: Como que eu faço para redimensionar todos os meus componentes no JavaFX a medida que eu aumentar a janela? Pois pela janela inicial do JavaFX, isso não é possível.
Dúvidas com redimensionar componentes JavaFX
P
2 Respostas
V
Você pode usar o SpringLayout, tenho um código de java no eclipse que pode te ajudar.
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.SpringLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
public class FormSpringLayout extends JFrame implements ActionListener {
private SpringLayout s = new SpringLayout();
private JLabel lblNome = new JLabel("Nome");
private JTextField txtNome = new JTextField();
private JButton btnFechar = new JButton("Fechar");
public FormSpringLayout() {
this.setLayout(s);
this.add(lblNome);
this.add(txtNome);
this.add(btnFechar);
txtNome.setPreferredSize(new Dimension(200, 25));
s.putConstraint(SpringLayout.NORTH, txtNome, 20, SpringLayout.NORTH, getContentPane());
s.putConstraint(SpringLayout.WEST, txtNome, 80, SpringLayout.WEST, getContentPane());
s.putConstraint(SpringLayout.EAST, lblNome, -5, SpringLayout.WEST, txtNome);
s.putConstraint(SpringLayout.BASELINE, lblNome, 0, SpringLayout.BASELINE, txtNome);
s.putConstraint(SpringLayout.EAST, btnFechar, 0, SpringLayout.EAST, txtNome);
s.putConstraint(SpringLayout.NORTH, btnFechar, 20, SpringLayout.SOUTH, txtNome);
s.putConstraint (SpringLayout.EAST, getContentPane(), 20, SpringLayout.EAST, txtNome);
s.putConstraint (SpringLayout.SOUTH, getContentPane(), 20, SpringLayout.SOUTH, btnFechar);
pack();
setLocationRelativeTo(null);
btnFechar.addActionListener(this);
}
@Override
public void actionPerformed(ActionEvent evento) {
if (evento.getSource() == btnFechar)
dispose();
}
public static void main(String[] args) {
(new FormSpringLayout()).setVisible(true);
}
}

P
Muito obrigado. O problema é que eu venho aprendendo por meio de projetos FXML, não utilizamos a classe Swing. Nós trabalhamos com AnchorPane etc… no scene builder.
Criado 4 de maio de 2019
Ultima resposta 4 de mai. de 2019
Respostas 2
Participantes 2
Alura Git Flow: entenda o que é, como e quando utilizar Entenda o que é Git Flow, como funciona seu fluxo com branches como Master, Develop, Feature, Release e Hotfix, além de vantagens e desvantagens.
Casa do Codigo Apache Kafka e Spring Boot: Comunicacao assincrona entre... Por Eduardo Felipe Zambom Santana — Casa do Codigo