import java.awt.BorderLayout;
import javax.swing.JPanel;
import javax.swing.JFrame;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JCheckBox;
import org.hsqldb.util.TableSorter;
public class TelaEscalonadorGui extends JFrame {
private JPanel jContentPane = null;
private JScrollPane ScrollProcessos = null;
private JTable TableListProcessos = null;
private JButton ButtonGeraProcessos = null;
private JLabel LabelNameProcesso = null;
private JTextField NomeProcesso = null;
private JCheckBox CheckBoxFilhos = null;
private JLabel LabelFilhos = null;
private TableSorter tableSorter = null; // @jve:decl-index=0:visual-constraint=""
/**
- This is the default constructor
*/
public TelaEscalonadorGui() {
super();
initialize();
}
/**
- This method initializes this
-
@return void
*/
private void initialize() {
this.setSize(911, 626);
this.setContentPane(getJContentPane());
this.setTitle(“JFrame”);
}
/**
- This method initializes jContentPane
-
@return javax.swing.JPanel
*/
private JPanel getJContentPane() {
if (jContentPane == null) {
LabelFilhos = new JLabel();
LabelFilhos.setBounds(new java.awt.Rectangle(420,60,102,31));
LabelFilhos.setText(" Filhos Processo");
LabelNameProcesso = new JLabel();
LabelNameProcesso.setBounds(new java.awt.Rectangle(420,16,120,29));
LabelNameProcesso.setText(" Nome do Processo:");
jContentPane = new JPanel();
jContentPane.setLayout(null);
jContentPane.add(getScrollProcessos(), null);
jContentPane.add(getButtonGeraProcessos(), null);
jContentPane.add(LabelNameProcesso, null);
jContentPane.add(getNomeProcesso(), null);
jContentPane.add(getCheckBoxFilhos(), null);
jContentPane.add(LabelFilhos, null);
}
return jContentPane;
}
/**
- This method initializes ScrollProcessos
-
@return javax.swing.JScrollPane
*/
private JScrollPane getScrollProcessos() {
if (ScrollProcessos == null) {
ScrollProcessos = new JScrollPane();
ScrollProcessos.setBounds(new java.awt.Rectangle(31,18,347,506));
ScrollProcessos.setViewportView(getTableListProcessos());
}
return ScrollProcessos;
}
/**
- This method initializes TableListProcessos
-
@return javax.swing.JTable
*/
private JTable getTableListProcessos() {
if (TableListProcessos == null) {
TableListProcessos = new JTable(30,6);
TableListProcessos.setAutoCreateColumnsFromModel(true);
TableListProcessos.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
TableListProcessos.setName(“Lista de Processos”);
JTable table = new JTable();
JScrollPane scroller = new JScrollPane( table );
table.getTableHeader().getColumnModel().getColumn(0).setHeaderValue(“Pid”);
table.getTableHeader().getColumnModel().getColumn(1).setHeaderValue(“Nome”);
table.getTableHeader().getColumnModel().getColumn(2).setHeaderValue(“Status”);
table.getTableHeader().getColumnModel().getColumn(3).setHeaderValue(“Quantidade”);
table.getTableHeader().getColumnModel().getColumn(4).setHeaderValue(“Prioridade”);
}
return TableListProcessos;
}
/**
- This method initializes ButtonGeraProcessos
-
@return javax.swing.JButton
*/
private JButton getButtonGeraProcessos() {
if (ButtonGeraProcessos == null) {
ButtonGeraProcessos = new JButton();
ButtonGeraProcessos.setBounds(new java.awt.Rectangle(583,92,138,25));
ButtonGeraProcessos.setText(“Gerar Processos”);
}
return ButtonGeraProcessos;
}
/**
- This method initializes NomeProcesso
-
@return javax.swing.JTextField
*/
private JTextField getNomeProcesso() {
if (NomeProcesso == null) {
NomeProcesso = new JTextField();
NomeProcesso.setBounds(new java.awt.Rectangle(554,17,171,2);
}
return NomeProcesso;
}
/**
- This method initializes CheckBoxFilhos
-
@return javax.swing.JCheckBox
*/
private JCheckBox getCheckBoxFilhos() {
if (CheckBoxFilhos == null) {
CheckBoxFilhos = new JCheckBox();
CheckBoxFilhos.setBounds(new java.awt.Rectangle(539,66,21,17));
}
return CheckBoxFilhos;
}
/**
- This method initializes tableSorter
-
@return org.hsqldb.util.TableSorter
*/
private TableSorter getTableSorter() {
if (tableSorter == null) {
tableSorter = new TableSorter();
}
return tableSorter;
}
}
Eu não sei manipular direito o JTable, estou com algumas dúvidas.
º - Usei o able.getTableHeader().getColumnModel().getColumn(0).setHeaderValue()
- Não funcionou ele, tem algo de errado ou preciso fazer mais alguma coisa?
2º - Tentei alterar o tamanho das colunas usando table.getTableHeader().getColumnModel().getColumn(4) que o objeto retornado tem um metodo, que acho que se chama setMaxWidth(), não funcinou. Creio que estou fazendo algo de errado, isso eu tenho certeza.
3º - Tentei usa como este site mostrar http://cadeiras.iscte.pt/lei-lp/JTable2.pdf - Coloquei isso no construtor da tabela private JTable getTableListProcessos() , também não funcionou!
4º - Como e que eu coloco dados na tabela, to me enrolando pra karamba nisso?
5º - Não encontrei como se tira as linhas da tabela.
6º - a Última como e que faço quando marcar o jcheckbox e abrar outro frame?
Ewerton Muniz