Sou novo aqui no GUJ e estou precisando da ajuda de vocês ... estou criando um programa para minha faculdade utilizando a ferramenta Jigloo. Apesar de muito boa ela gera códigos que são posicionados meio que diferentes de outros editores (VEP por exemplo).
Problema: O real problema é até que simples porém eu não consigo resolver ... gostaria de colocar um JScrollPane na minha jList1 e não estou conseguindo ... no código abaixo está uma tentativa (em vão) ... por isso peço a ajuda de vocês.
Segue o código:
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;
import javax.swing.GroupLayout;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.LayoutStyle;
import javax.swing.SwingConstants;
import javax.swing.*;
import java.awt.*;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class frmPratos extends JFrame {
private JList lstMenu,jList1=null;
private JScrollPane ScrollPed;
private JLabel jLabel2;
private JLabel lblResultUm;
private JLabel jLabel1;
private JLabel lblTotUm;
private JButton jButton1;
private JButton jButton5;
private JButton jButton4;
private JButton jButton3;
private JButton jButton2;
private JLabel lblTituloP;
private String ere[]={"1" , "2"};
private DefaultListModel listModel = null;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
frmPratos inst = new frmPratos();
inst.setLocationRelativeTo(null);
inst.setVisible(true);
}
});
}
public frmPratos() {
super();
initGUI();
}
private void initGUI() {
try {
setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
getContentPane().setBackground(new java.awt.Color(255,255,255));
GroupLayout thisLayout = new GroupLayout((JComponent)getContentPane());
getContentPane().setLayout(thisLayout);
this.setTitle("Cardápio Virtual - Pratos");
this.setVisible(false);
listModel = new DefaultListModel();
{
lstMenu = new JList(ere);
lstMenu.setBorder(BorderFactory.createTitledBorder("Cardápio"));
lstMenu.setFont(new java.awt.Font("Tahoma",1,12));
}
{
jList1 = new JList(listModel);
jList1.setBorder(BorderFactory.createTitledBorder("Pedidos"));
jList1.setFont(new java.awt.Font("Tahoma",1,12));
jList1.setBounds(3, 3, 175, 200);
jList1.setVisibleRowCount(3);
jList1.getPreferredScrollableViewportSize();
}
{
ScrollPed = new JScrollPane(jList1);
}
{
}
{
lblTotUm = new JLabel();
lblTotUm.setText("TOTAL:");
lblTotUm.setFont(new java.awt.Font("Tahoma",1,16));
}
{
jLabel1 = new JLabel();
jLabel1.setText("TOTAL:");
jLabel1.setFont(new java.awt.Font("Tahoma",1,16));
}
{
lblResultUm = new JLabel();
lblResultUm.setFont(new java.awt.Font("Tahoma",1,18));
}
{
jLabel2 = new JLabel();
jLabel2.setFont(new java.awt.Font("Tahoma",1,18));
}
{
jButton1 = new JButton();
jButton1.setText("INCLUIR");
jButton1.setFont(new java.awt.Font("Tahoma",1,14));
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
}
{
jButton3 = new JButton();
jButton3.setText("INFORMAÇÕES");
jButton3.setFont(new java.awt.Font("Tahoma",1,14));
}
{
jButton4 = new JButton();
jButton4.setText("EXCLUIR");
jButton4.setFont(new java.awt.Font("Tahoma",1,14));
jButton4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
}
{
jButton5 = new JButton();
jButton5.setText("CONFIRMAR");
jButton5.setFont(new java.awt.Font("Tahoma",1,14));
}
{
lblTituloP = new JLabel();
lblTituloP.setText("Pratos");
lblTituloP.setHorizontalAlignment(SwingConstants.CENTER);
lblTituloP.setFont(new java.awt.Font("Tahoma",1,20));
}
{
jButton2 = new JButton();
jButton2.setText("VOLTAR AO MENU");
jButton2.setFont(new java.awt.Font("Tahoma",1,14));
jButton2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent evt) {
jButton2ActionPerformed(evt);
}
});
}
thisLayout.setVerticalGroup(thisLayout.createSequentialGroup()
.addGap(6)
.addComponent(lblTituloP, GroupLayout.PREFERRED_SIZE, 20, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lstMenu, GroupLayout.PREFERRED_SIZE, 152, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jButton2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
.addComponent(jButton1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
.addComponent(jButton3, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE))
.addGap(22)
.addComponent(jList1, GroupLayout.PREFERRED_SIZE, 85, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(thisLayout.createParallelGroup()
.addGroup(GroupLayout.Alignment.LEADING, thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jButton4, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE)
.addComponent(lblTotUm, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
.addComponent(jButton5, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 28, GroupLayout.PREFERRED_SIZE))
.addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
.addGap(7)
.addComponent(lblResultUm, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
.addGap(7)))
.addPreferredGap(LayoutStyle.ComponentPlacement.UNRELATED)
.addGroup(thisLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
.addComponent(jLabel1, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 24, GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, GroupLayout.Alignment.BASELINE, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)));
thisLayout.setHorizontalGroup(thisLayout.createSequentialGroup()
.addContainerGap()
.addGroup(thisLayout.createParallelGroup()
.addComponent(lblTituloP, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 536, GroupLayout.PREFERRED_SIZE)
.addComponent(lstMenu, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 536, GroupLayout.PREFERRED_SIZE)
.addComponent(jList1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 536, GroupLayout.PREFERRED_SIZE)
.addGroup(thisLayout.createSequentialGroup()
.addGroup(thisLayout.createParallelGroup()
.addComponent(jButton1, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 170, GroupLayout.PREFERRED_SIZE)
.addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
.addComponent(jLabel1, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel2, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
.addGap(23))
.addComponent(jButton4, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 170, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(thisLayout.createParallelGroup()
.addComponent(jButton3, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 176, GroupLayout.PREFERRED_SIZE)
.addComponent(jButton5, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 176, GroupLayout.PREFERRED_SIZE))
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addGroup(thisLayout.createParallelGroup()
.addComponent(jButton2, GroupLayout.Alignment.LEADING, GroupLayout.PREFERRED_SIZE, 170, GroupLayout.PREFERRED_SIZE)
.addGroup(GroupLayout.Alignment.LEADING, thisLayout.createSequentialGroup()
.addPreferredGap(jButton2, lblTotUm, LayoutStyle.ComponentPlacement.INDENT)
.addComponent(lblTotUm, GroupLayout.PREFERRED_SIZE, 63, GroupLayout.PREFERRED_SIZE)
.addPreferredGap(LayoutStyle.ComponentPlacement.RELATED)
.addComponent(lblResultUm, GroupLayout.PREFERRED_SIZE, 78, GroupLayout.PREFERRED_SIZE)
.addGap(11)))
.addGap(10)))
.addContainerGap());
pack();
this.setSize(568, 428);
} catch (Exception e) {
e.printStackTrace();
}
}
private void jButton2ActionPerformed(ActionEvent evt) {
frmMain de = new frmMain();
de.setVisible(true);
this.setVisible(false);
}
private void jButton1ActionPerformed(ActionEvent evt) {
String temp = (String)lstMenu.getSelectedValue();
listModel.addElement(temp);
//TODO add your code for jButton1.actionPerformed
}
private void jButton4ActionPerformed(ActionEvent evt) {
String temp = (String)jList1.getSelectedValue();
listModel.removeElement(temp);
//TODO add your code for jButton4.actionPerformed
}
}
Aguardo a resposta ...
Frelee