Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package swing.lista.rozwijana;
- import java.util.Vector;
- /**
- *
- * @author Piotr Zuber
- */
- public class Glowne_okno extends javax.swing.JFrame {
- /**
- * Creates new form Glowne_okno
- */
- public Glowne_okno() {
- initComponents();
- // for(int i=0;i<20;i++)
- //Combo_lista.addItem(String.valueOf(i));
- Dopisz_button.setEnabled(false);
- }
- Vector<String> vect = new Vector<String>();
- /**
- * This method is called from within the constructor to initialize the form.
- * WARNING: Do NOT modify this code. The content of this method is always
- * regenerated by the Form Editor.
- */
- @SuppressWarnings("unchecked")
- // <editor-fold defaultstate="collapsed" desc="Generated Code">
- private void initComponents() {
- Combo_lista = new javax.swing.JComboBox<>();
- Dodaj_Button = new javax.swing.JButton();
- Dopisz_button = new javax.swing.JButton();
- Na_poczatku_check = new javax.swing.JCheckBox();
- Tekstowe_pole = new javax.swing.JTextField();
- jScrollPane1 = new javax.swing.JScrollPane();
- Lista_rozwijana = new javax.swing.JList<>();
- setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
- Combo_lista.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Hello", "world", "is", "a", "better", "place", "się", "nie", "zna", "na", "programowaniu", "ma", "tłuste", "włosy" }));
- Combo_lista.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Combo_listaActionPerformed(evt);
- }
- });
- Dodaj_Button.setText("Dodaj");
- Dodaj_Button.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Dodaj_ButtonActionPerformed(evt);
- }
- });
- Dopisz_button.setText("Dopisz");
- Dopisz_button.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Dopisz_buttonActionPerformed(evt);
- }
- });
- Na_poczatku_check.setText("Na poczatku");
- Na_poczatku_check.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Na_poczatku_checkActionPerformed(evt);
- }
- });
- Tekstowe_pole.addCaretListener(new javax.swing.event.CaretListener() {
- public void caretUpdate(javax.swing.event.CaretEvent evt) {
- Tekstowe_poleCaretUpdate(evt);
- }
- });
- Tekstowe_pole.addActionListener(new java.awt.event.ActionListener() {
- public void actionPerformed(java.awt.event.ActionEvent evt) {
- Tekstowe_poleActionPerformed(evt);
- }
- });
- jScrollPane1.setViewportView(Lista_rozwijana);
- javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
- getContentPane().setLayout(layout);
- layout.setHorizontalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addComponent(Dodaj_Button)
- .addComponent(Dopisz_button)
- .addComponent(Combo_lista, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addComponent(Na_poczatku_check))
- .addGap(31, 31, 31)
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 383, Short.MAX_VALUE)
- .addGap(8, 8, 8))
- .addComponent(Tekstowe_pole))
- .addContainerGap())
- );
- layout.setVerticalGroup(
- layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
- .addGroup(layout.createSequentialGroup()
- .addComponent(Dodaj_Button)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
- .addComponent(Dopisz_button)
- .addGap(18, 18, 18)
- .addComponent(Combo_lista, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
- .addComponent(Na_poczatku_check))
- .addGroup(layout.createSequentialGroup()
- .addContainerGap()
- .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 294, Short.MAX_VALUE)))
- .addGap(18, 18, 18)
- .addComponent(Tekstowe_pole, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
- .addGap(17, 17, 17))
- );
- pack();
- }// </editor-fold>
- private void Dodaj_ButtonActionPerformed(java.awt.event.ActionEvent evt) {
- String temp = new String();
- temp = Tekstowe_pole.getText();
- if(Na_poczatku_check.isSelected())
- {
- String sel_temp = temp;
- temp=(String)Combo_lista.getSelectedItem();
- temp+=sel_temp;
- Tekstowe_pole.setText(temp);
- }
- else
- {
- temp += (String)Combo_lista.getSelectedItem();
- Tekstowe_pole.setText(temp);
- }
- }
- private void Dopisz_buttonActionPerformed(java.awt.event.ActionEvent evt) {
- String tekst = Tekstowe_pole.getText();
- if(!tekst.equals("")){
- vect.add(tekst);
- Lista_rozwijana.setListData(vect);
- Tekstowe_pole.setText("");
- }
- }
- private void Na_poczatku_checkActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void Tekstowe_poleActionPerformed(java.awt.event.ActionEvent evt) {
- }
- private void Combo_listaActionPerformed(java.awt.event.ActionEvent evt) {
- // TODO add your handling code here:
- }
- private void Tekstowe_poleCaretUpdate(javax.swing.event.CaretEvent evt) {
- // TODO add your handling code here:
- // TODO add your handling code here:
- if(!Tekstowe_pole.getText().equals(""))
- {
- Dopisz_button.setEnabled(true);
- }
- else
- {
- Dopisz_button.setEnabled(false);
- }
- }
- /**
- * @param args the command line arguments
- */
- public static void main(String args[]) {
- /* Set the Nimbus look and feel */
- //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
- /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
- * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
- */
- try {
- for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
- if ("Nimbus".equals(info.getName())) {
- javax.swing.UIManager.setLookAndFeel(info.getClassName());
- break;
- }
- }
- } catch (ClassNotFoundException ex) {
- java.util.logging.Logger.getLogger(Glowne_okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (InstantiationException ex) {
- java.util.logging.Logger.getLogger(Glowne_okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (IllegalAccessException ex) {
- java.util.logging.Logger.getLogger(Glowne_okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- } catch (javax.swing.UnsupportedLookAndFeelException ex) {
- java.util.logging.Logger.getLogger(Glowne_okno.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
- }
- //</editor-fold>
- /* Create and display the form */
- java.awt.EventQueue.invokeLater(new Runnable() {
- public void run() {
- new Glowne_okno().setVisible(true);
- }
- });
- }
- // Variables declaration - do not modify
- private javax.swing.JComboBox<String> Combo_lista;
- private javax.swing.JButton Dodaj_Button;
- private javax.swing.JButton Dopisz_button;
- private javax.swing.JList<String> Lista_rozwijana;
- private javax.swing.JCheckBox Na_poczatku_check;
- private javax.swing.JTextField Tekstowe_pole;
- private javax.swing.JScrollPane jScrollPane1;
- // End of variables declaration
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement