Foros del Web » Programación para mayores de 30 ;) » Java »

Como aplicar Herencia de una jtoolbar en varios jinternalframe

Estas en el tema de Como aplicar Herencia de una jtoolbar en varios jinternalframe en el foro de Java en Foros del Web. Buenas a todos su ayuda, tengo una aplicacion que quiero que una jtoolbar la hereden varios jinternalfrema, pero en cada JIframe se pueda modificar el ...
  #1 (permalink)  
Antiguo 31/10/2014, 20:35
Avatar de gacsnic75  
Fecha de Ingreso: septiembre-2012
Mensajes: 25
Antigüedad: 11 años, 7 meses
Puntos: 0
Como aplicar Herencia de una jtoolbar en varios jinternalframe

Buenas a todos

su ayuda, tengo una aplicacion que quiero que una jtoolbar la hereden varios jinternalfrema, pero en cada JIframe se pueda modificar el desempeño de los botones que se mantenga tamaño y iconos de los botones pero que no se modifiquen los botenes
este es el codigo del internalframe

Código:
package gsinv;

import java.awt.Frame;
import java.awt.event.ActionEvent;


public class frmfactura extends javax.swing.JInternalFrame {

    /**
     * Creates new form factura
     */
    public frmfactura() {
        initComponents();
         }

/*private void  cmdclosed(java.awt.event.ActionEvent evt){
    this.dispose();
         } 
*/
    /**
     * 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() {

        jtbstandar = new clases.jtbarbase();

        setTitle("Factura");

        jtbstandar.setRollover(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jtbstandar, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jtbstandar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 226, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>                       

       
}
este el codigo del jtoolbar

Código:
package gsinv;

import java.awt.Frame;
import java.awt.event.ActionEvent;

public class frmfactura extends javax.swing.JInternalFrame {

    /**
     * Creates new form factura
     */
    public frmfactura() {
        initComponents();
         }

/*private void  cmdclosed(java.awt.event.ActionEvent evt){
    this.dispose();
         } 
*/
    /**
     * 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() {

        jtbstandar = new clases.jtbarbase();

        setTitle("Factura");

        jtbstandar.setRollover(true);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jtbstandar, javax.swing.GroupLayout.DEFAULT_SIZE, 500, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jtbstandar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 226, Short.MAX_VALUE))
        );

        pack();
    }
          
}
estoy trabajando con netbeans 8.0 para linux, cuando agrego el jtoolbar al jiframe no puedo modificar los botones , no puedo agregar métodos de ejecución.

buscando por la red me encontré este código, pero no se como implementarlo a lo que estoy haciendo ya que no encuentro información SmallButton


Código:
import java.awt.BorderLayout;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;

public class SimpleToolbar extends JFrame {

  public static final String FontNames[] = { "Serif", "SansSerif", "Courier" };

  protected Font fonts[];

  protected JFileChooser fileChooser = new JFileChooser();

  protected JToolBar toolBar;

  protected JComboBox cbFonts;

  protected SmallToggleButton bBold;

  protected SmallToggleButton bItalic;

  public SimpleToolbar() {
    super();
    setSize(450, 350);

    fonts = new Font[FontNames.length];
    for (int k = 0; k < FontNames.length; k++)
      fonts[k] = new Font(FontNames[k], Font.PLAIN, 12);

    WindowListener wndCloser = new WindowAdapter() {
      public void windowClosing(WindowEvent e) {
        System.exit(0);
      }
    };
    addWindowListener(wndCloser);
    createToolBar();
    setVisible(true);
  }

  protected void createToolBar() {
    ImageIcon iconNew = new ImageIcon("file_new.gif");
    Action actionNew = new AbstractAction("New", iconNew) {
      public void actionPerformed(ActionEvent e) {
        ;
      }
    };
    ImageIcon iconOpen = new ImageIcon("file_open.gif");
    Action actionOpen = new AbstractAction("Open...", iconOpen) {
      public void actionPerformed(ActionEvent e) {
      }
    };
    ImageIcon iconSave = new ImageIcon("file_save.gif");
    Action actionSave = new AbstractAction("Save...", iconSave) {
      public void actionPerformed(ActionEvent e) {
      }
    };
    Action actionExit = new AbstractAction("Exit") {
      public void actionPerformed(ActionEvent e) {
        System.exit(0);
      }
    };
    toolBar = new JToolBar();
    JButton bNew = new SmallButton(actionNew, "New text");
    toolBar.add(bNew);

    JButton bOpen = new SmallButton(actionOpen, "Open text file");
    toolBar.add(bOpen);

    JButton bSave = new SmallButton(actionSave, "Save text file");
    toolBar.add(bSave);

    ActionListener fontListener = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      }
    };

    toolBar.addSeparator();
    cbFonts = new JComboBox(FontNames);
    cbFonts.setMaximumSize(cbFonts.getPreferredSize());
    cbFonts.setToolTipText("Available fonts");
    ActionListener lst = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        int index = cbFonts.getSelectedIndex();
        if (index < 0)
          return;
      }
    };
    cbFonts.addActionListener(lst);
    toolBar.add(cbFonts);

    toolBar.addSeparator();

    ImageIcon img1 = new ImageIcon("font_bold1.gif");
    ImageIcon img2 = new ImageIcon("font_bold2.gif");
    bBold = new SmallToggleButton(false, img1, img2, "Bold font");
    lst = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      }
    };
    bBold.addActionListener(lst);
    toolBar.add(bBold);

    img1 = new ImageIcon("font_italic1.gif");
    img2 = new ImageIcon("font_italic2.gif");
    bItalic = new SmallToggleButton(false, img1, img2, "Italic font");
    lst = new ActionListener() {
      public void actionPerformed(ActionEvent e) {
      }
    };
    bItalic.addActionListener(lst);
    toolBar.add(bItalic);

    getContentPane().add(toolBar, BorderLayout.NORTH);

  }
  public static void main(String[] a){
    new SimpleToolbar();
     
    }

}
class SmallButton extends JButton implements MouseListener {
  protected Border m_raised;

  protected Border m_lowered;

  protected Border m_inactive;

  public SmallButton(Action act, String tip) {
    super((Icon) act.getValue(Action.SMALL_ICON));
    m_raised = new BevelBorder(BevelBorder.RAISED);
    m_lowered = new BevelBorder(BevelBorder.LOWERED);
    m_inactive = new EmptyBorder(2, 2, 2, 2);
    setBorder(m_inactive);
    setMargin(new Insets(1, 1, 1, 1));
    setToolTipText(tip);
    addActionListener(act);
    addMouseListener(this);
    setRequestFocusEnabled(false);
  }

  public float getAlignmentY() {
    return 0.5f;
  }

  public void mousePressed(MouseEvent e) {
    setBorder(m_lowered);
  }

  public void mouseReleased(MouseEvent e) {
    setBorder(m_inactive);
  }

  public void mouseClicked(MouseEvent e) {
  }

  public void mouseEntered(MouseEvent e) {
    setBorder(m_raised);
  }

  public void mouseExited(MouseEvent e) {
    setBorder(m_inactive);
  }
}

class SmallToggleButton extends JToggleButton implements ItemListener {
  protected Border raised;

  protected Border lowered;

  public SmallToggleButton(boolean selected, ImageIcon imgUnselected,
      ImageIcon imgSelected, String tip) {
    super(imgUnselected, selected);
    setHorizontalAlignment(CENTER);
    setBorderPainted(true);
    raised = new BevelBorder(BevelBorder.RAISED);
    lowered = new BevelBorder(BevelBorder.LOWERED);
    setBorder(selected ? lowered : raised);
    setMargin(new Insets(1, 1, 1, 1));
    setToolTipText(tip);
    setRequestFocusEnabled(false);
    setSelectedIcon(imgSelected);
    addItemListener(this);
  }

  public float getAlignmentY() {
    return 0.5f;
  }

  public void itemStateChanged(ItemEvent e) {
    setBorder(isSelected() ? lowered : raised);
  }
}

Etiquetas: clase, herencia, jinternalframe, netbeans, string
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 04:05.