Example usage for javax.swing JScrollPane repaint

List of usage examples for javax.swing JScrollPane repaint

Introduction

In this page you can find the example usage for javax.swing JScrollPane repaint.

Prototype

public void repaint() 

Source Link

Document

Repaints this component.

Usage

From source file:Main.java

public static void main(String[] args) {
    JPanel panel = new JPanel(new GridBagLayout());
    for (int i = 0; i < 25; i++) {
        JTextField field = new JTextField("Field " + i, 20);
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.gridy = i;/*from  w w w  .  j  a  va 2  s .c  om*/
        panel.add(field, constraints);
    }
    JScrollPane scrollPane = new JScrollPane(panel);
    JButton removeButton = new JButton("Remove Field");
    removeButton.addActionListener(e -> {
        if (panel.getComponentCount() >= 1) {
            panel.remove(panel.getComponentCount() - 1);
            scrollPane.revalidate();
            scrollPane.repaint();
        }
    });
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setSize(640, 480);
    f.setLocation(200, 200);
    f.getContentPane().add(scrollPane);
    f.getContentPane().add(removeButton, BorderLayout.SOUTH);
    f.setVisible(true);
}

From source file:com.googlecode.sarasvati.visual.jung.JungVisualizer.java

@SuppressWarnings("serial")
public static void main(String[] args) throws Exception {
    TestSetup.init();/*from w ww . j a va2s  .  c  o  m*/

    Session session = TestSetup.openSession();
    HibEngine engine = new HibEngine(session);

    JFrame frame = new JFrame("Workflow Visualizer");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setMinimumSize(new Dimension(800, 600));

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    frame.getContentPane().add(splitPane);

    DefaultListModel listModel = new DefaultListModel();
    for (Graph g : engine.getRepository().getGraphs()) {
        listModel.addElement(g);
    }

    ListCellRenderer cellRenderer = new DefaultListCellRenderer() {
        @Override
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);

            Graph g = (Graph) value;

            setText(g.getName() + "." + g.getVersion() + "  ");
            return this;
        }
    };

    final JList graphList = new JList(listModel);
    graphList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    graphList.setCellRenderer(cellRenderer);

    JScrollPane listScrollPane = new JScrollPane(graphList);
    listScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    listScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);

    splitPane.add(listScrollPane);

    //TreeLayout<NodeRef, Arc> layout = new TreeLayout<NodeRef, Arc>();

    DirectedSparseMultigraph<Node, Arc> graph = new DirectedSparseMultigraph<Node, Arc>();

    //final SpringLayout2<HibNodeRef, HibArc> layout = new SpringLayout2<HibNodeRef, HibArc>(graph);
    //final KKLayout<HibNodeRef, HibArc> layout = new KKLayout<HibNodeRef, HibArc>(graph);
    final TreeLayout layout = new TreeLayout(graph);
    final BasicVisualizationServer<Node, Arc> vs = new BasicVisualizationServer<Node, Arc>(layout);
    //vs.getRenderContext().setVertexLabelTransformer( new NodeLabeller() );
    //vs.getRenderContext().setEdgeLabelTransformer( new ArcLabeller() );
    vs.getRenderContext().setVertexShapeTransformer(new NodeShapeTransformer());
    vs.getRenderContext().setVertexFillPaintTransformer(new NodeColorTransformer());
    vs.getRenderContext().setLabelOffset(5);
    vs.getRenderContext().setVertexIconTransformer(new Transformer<Node, Icon>() {
        @Override
        public Icon transform(Node node) {
            return "task".equals(node.getType()) ? new TaskIcon(node) : null;
        }
    });

    Transformer<Arc, Paint> edgeColorTrans = new Transformer<Arc, Paint>() {
        private Color darkRed = new Color(128, 0, 0);

        @Override
        public Paint transform(Arc arc) {
            return "reject".equals(arc.getName()) ? darkRed : Color.black;
        }
    };

    vs.getRenderContext().setEdgeDrawPaintTransformer(edgeColorTrans);
    vs.getRenderContext().setArrowDrawPaintTransformer(edgeColorTrans);

    final JScrollPane scrollPane = new JScrollPane(vs);
    scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);

    splitPane.add(scrollPane);
    scrollPane.setBackground(Color.white);

    graphList.addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }

            final Graph g = (Graph) graphList.getSelectedValue();

            if ((g == null && currentGraph == null) || (g != null && g.equals(currentGraph))) {
                return;
            }

            currentGraph = g;

            DirectedSparseMultigraph<Node, Arc> jungGraph = new DirectedSparseMultigraph<Node, Arc>();

            for (Node ref : currentGraph.getNodes()) {
                jungGraph.addVertex(ref);
            }

            for (Arc arc : currentGraph.getArcs()) {
                jungGraph.addEdge(arc, arc.getStartNode(), arc.getEndNode());
            }

            GraphTree graphTree = new GraphTree(g);
            layout.setGraph(jungGraph);
            layout.setInitializer(new NodeLocationTransformer(graphTree));
            scrollPane.repaint();
        }
    });

    frame.setVisible(true);
}

From source file:com.nvinayshetty.DTOnator.FeedValidator.JsonFeedValidator.java

private void showAlert(JScrollPane exceptionLoggerPane, JLabel exceptionLabel, JSONException ex1) {
    exceptionLoggerPane.setVisible(true);
    exceptionLabel.setVisible(true);/*from   w w  w . ja va2 s  .co m*/
    new ExceptionLogger(exceptionLabel).Log(ex1);
    exceptionLoggerPane.invalidate();
    exceptionLoggerPane.validate();
    exceptionLoggerPane.repaint();
}

From source file:net.sf.mzmine.chartbasics.graphicsexport.GraphicsExportDialog.java

/**
 * Create the dialog.//from w  w w  .  j  a v  a2 s. c om
 */
public GraphicsExportDialog() {
    final JFrame thisframe = this;
    //
    parameters = new GraphicsExportParameters();
    chartParam = new ChartThemeParameters();
    parametersAndComponents = new HashMap<String, JComponent>();

    String[] formats = parameters.getParameter(GraphicsExportParameters.exportFormat).getChoices();
    chooser.addChoosableFileFilter(new FileTypeFilter(formats, "Export images"));
    chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
    //
    setBounds(100, 100, 808, 795);
    getContentPane().setLayout(new BorderLayout());
    contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(contentPanel, BorderLayout.CENTER);
    contentPanel.setLayout(new MigLayout("", "[][][grow]", "[][][][grow]"));
    {
        StringParameter p = parameters.getParameter(GraphicsExportParameters.path);
        StringComponent txtPath = p.createEditingComponent();
        contentPanel.add(txtPath, "flowx,cell 0 0,growx");
        parametersAndComponents.put(p.getName(), txtPath);
    }
    {
        btnPath = new JButton("Path");
        btnPath.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                choosePath();
            }
        });
        contentPanel.add(btnPath, "cell 1 0");
    }
    {
        StringParameter p = parameters.getParameter(GraphicsExportParameters.filename);
        StringComponent txtFileName = p.createEditingComponent();
        contentPanel.add(txtFileName, "cell 0 1,growx");
        parametersAndComponents.put(p.getName(), txtFileName);
    }
    {
        JLabel lblFilename = new JLabel("filename");
        contentPanel.add(lblFilename, "cell 1 1");
    }
    {
        JPanel pnSettingsLeft = new JPanel();
        pnSettingsLeft.setMinimumSize(new Dimension(260, 260));
        contentPanel.add(pnSettingsLeft, "cell 0 3,grow");
        pnSettingsLeft.setLayout(new BorderLayout(0, 0));
        {

            GridBagPanel pn = new GridBagPanel();
            {
                // add unit
                UserParameter p;
                JComponent comp;
                // add unit
                p = (UserParameter) parameters.getParameter(GraphicsExportParameters.unit);
                comp = p.createEditingComponent();
                comp.setToolTipText(p.getDescription());
                comp.setEnabled(true);
                pn.add(comp, 2, 2);
                parametersAndComponents.put(p.getName(), comp);

                int i = 0;
                // add export settings
                Parameter[] param = parameters.getParameters();
                for (int pi = 3; pi < param.length; pi++) {
                    p = (UserParameter) param[pi];
                    comp = p.createEditingComponent();
                    comp.setToolTipText(p.getDescription());
                    comp.setEnabled(true);
                    pn.add(new JLabel(p.getName()), 0, i);
                    pn.add(comp, 1, i, 1, 1, 1, 1);
                    // add to map
                    parametersAndComponents.put(p.getName(), comp);
                    i++;
                }

                // add separator
                pn.add(new JSeparator(), 0, i, 5, 1, 1, 1, GridBagConstraints.BOTH);
                i++;
                // add Apply theme button
                JButton btnApply2 = new JButton("Apply theme");
                btnApply2.addActionListener(e -> applyTheme());
                pn.add(btnApply2, 0, i, 5, 1, 1, 1, GridBagConstraints.BOTH);
                i++;

                // add chart settings
                param = chartParam.getParameters();
                for (int pi = 0; pi < param.length; pi++) {
                    p = (UserParameter) param[pi];
                    comp = p.createEditingComponent();
                    comp.setToolTipText(p.getDescription());
                    comp.setEnabled(true);
                    pn.add(new JLabel(p.getName()), 0, i);
                    pn.add(comp, 1, i, 4, 1);
                    // add to map
                    parametersAndComponents.put(p.getName(), comp);
                    i++;
                }

                // add listener to master font
                JFontSpecs master = (JFontSpecs) parametersAndComponents
                        .get(chartParam.getParameter(ChartThemeParameters.masterFont).getName());
                master.addListener(fspec -> {
                    if (listenersEnabled)
                        handleMasterFontChanged(fspec);
                });
            }

            JScrollPane scrollPane = new JScrollPane(pn);
            scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
            pnSettingsLeft.add(scrollPane, BorderLayout.CENTER);
            scrollPane.getVerticalScrollBar().setUnitIncrement(18);
            scrollPane.revalidate();
            scrollPane.repaint();
        }
    }
    {
        {
            pnChartPreview = new JPanel();
            pnChartPreview.setLayout(null);
            contentPanel.add(pnChartPreview, "cell 1 3 2 1,grow");
        }
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton okButton = new JButton("Save");
            okButton.addActionListener(e -> saveGraphicsAs());
            okButton.setActionCommand("OK");
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            btnRenewPreview = new JButton("Renew Preview");
            btnRenewPreview.addActionListener(e -> renewPreview());
            buttonPane.add(btnRenewPreview);
        }
        {
            btnApply = new JButton("Apply theme");
            btnApply.addActionListener(e -> applyTheme());
            buttonPane.add(btnApply);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(e -> setVisible(false));
            cancelButton.setActionCommand("Cancel");
            buttonPane.add(cancelButton);
        }
    }
    // set all to components
    updateComponentsFromParameters();
}

From source file:modnlp.capte.AlignmentInterfaceWS.java

public void actionPerformed(ActionEvent e) {

    //Handle open button action.
    if (e.getSource() == openButton) {
        int returnVal = fc.showOpenDialog(AlignmentInterfaceWS.this);

        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            //This is where a real application would open the file.
            sourceFile = file.getAbsolutePath();
            log.append("Source File: " + sourceFile + "." + newline);
        } else {//from  w w w. j ava2 s .  c o  m
            log.append("Open command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());

    }
    //deleteSegment
    else if (e.getSource() == deleteSegment) {
        Object[] o;
        String ivalue;
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 1) {

            System.out.println("Please select at least one row");
            JOptionPane.showMessageDialog(edit, "Please select at least one row");
        } else {
            System.out.println("Deleting rows...");
            for (int i = selected.length - 1; i > -1; i--) {
                em.removeRow(selected[i]);
                //update numbers

                System.out.println("Removed row " + selected[i]);
            }
        }
        //Table should update itself automatically
    } else if (e.getSource() == moveUp) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();
        if (selected.length > 1) {
            System.out.println("You can only move one segment at a time!");
            JOptionPane.showMessageDialog(edit, "You can only move one segment at a time!");
        } else if (selected[0] == 0) {
            System.out.println("Can't move up anymore!");
            JOptionPane.showMessageDialog(edit, "Can't move up anymore!");
        } else {
            System.out.println("Moving " + selected[0]);
            em.moveSegmentUp(selected[0]);
            //Table should repaint
        }
    } else if (e.getSource() == moveDown) {

        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();
        if (selected.length > 1) {

            System.out.println("You can only move one segment at a time!");
            JOptionPane.showMessageDialog(edit, "You can only move one segment at a time!");
        } else if (selected[0] == em.getRowCount() - 1) {

            System.out.println("Can't move down anymore!");
            JOptionPane.showMessageDialog(edit, "Can't move down anymore");
        } else {
            System.out.println("Moving " + selected[0]);
            em.moveSegmentDown(selected[0]);
            //Table should repaint
        }
    } else if (e.getSource() == mergeSource) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 2 || selected.length > 2) {

            System.out.println("Please select two rows to merge ");
            JOptionPane.showMessageDialog(edit, "Please select two rows to merge");
        } else if (selected[0] - selected[1] > 1 || selected[0] - selected[1] < -1) {

            System.out.println("Can only merge adjacent rows");
            JOptionPane.showMessageDialog(edit, "Can only merge adjacent rows");
        } else {
            System.out.println("Merging source in rows " + selected[0] + " " + selected[1]);
            em.mergeSource(selected[0], selected[1]);
        }
    } else if (e.getSource() == mergeTarget) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 2 || selected.length > 2) {

            System.out.println("Please select two rows to merge ");
            JOptionPane.showMessageDialog(edit, "Please select two rows to merge");
        } else if (selected[0] - selected[1] > 1 || selected[0] - selected[1] < -1) {

            System.out.println("Can only merge adjacent rows");
            JOptionPane.showMessageDialog(edit, "Can only merge adjacent rows");
        } else {
            System.out.println("Merging target in " + selected[0] + " " + selected[1]);
            em.mergeTarget(selected[0], selected[1]);
        }

    } else if (e.getSource() == newSegment) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 1) {

            System.out.println("Please select a position to insert at:");
            JOptionPane.showMessageDialog(edit, "Please select a position to insert at");
        } else {
            System.out.println("Inserting new segment at " + (selected[0] + 1));
            //insert empty string array
            Object[] sa = new Object[6];
            sa[0] = "";
            sa[1] = "";
            sa[2] = "0.0";
            sa[3] = new Boolean(false);
            sa[4] = "0";
            sa[5] = em.getValueAt((selected[0]), 5) + "(+)";

            em.insertRow(sa, (selected[0] + 1));

        }
    } else if (e.getSource() == lockSelected) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 1) {

            System.out.println("Please select some rows to lock:");
            JOptionPane.showMessageDialog(edit, "Please select some rows to lock:");
        } else {

            //lock selected rows

            for (int i = 0; i < selected.length; i++) {
                em.lockRow(selected[i]);
                System.out.println("Locking row " + selected[i]);

            }

        }
    } else if (e.getSource() == unlockSelected) {
        int[] selected = table.getSelectedRows();
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        if (selected.length < 1) {

            System.out.println("Please select some rows to unlock:");
            JOptionPane.showMessageDialog(edit, "Please select some rows to unlock:");
        } else {

            //lock selected rows
            for (int i = 0; i < selected.length; i++) {
                em.unlockRow(selected[i]);
                System.out.println("Unlocking row " + selected[i]);
            }

        }
    } else if (e.getSource() == reAlign) {
        //  if(true){
        // JOptionPane.showMessageDialog(edit,"This feature is currently disabled");
        // }else{
        reNumber++;
        ExampleTableModel em = (ExampleTableModel) table.getModel();

        // Get list of locked segments
        // Find lowest locked segment
        // Realign from lowest locked segment
        // Join the realigned bit back up with the locked bit
        // refresh the table
        int lowestlock = 0;
        Vector<Object[]> slice = new Vector<Object[]>();
        Vector<Object[]> result = new Vector<Object[]>();
        Vector<Object[]> locked = new Vector<Object[]>();
        Boolean b = new Boolean(true);
        for (int i = 0; i < em.getRowCount(); i++) {
            b = (Boolean) em.getValueAt(i, 3);
            if (b.booleanValue() == true) {
                lowestlock = i;
            }
        }

        //get slice of table for realignment
        System.out.println("The lowest lock point is " + (lowestlock));
        System.out.println("Realigning from row:" + (lowestlock + 1) + " to : " + em.getRowCount());
        System.out.println("Total size of realign array =:" + (em.getRowCount() - (lowestlock)));
        //Get locked bits
        for (int h = 0; h < lowestlock + 1; h++) {

            locked.add(em.getRow(h));
        }
        //Get bits to realign
        for (int j = lowestlock + 1; j < em.getRowCount(); j++) {

            slice.add(em.getRow(j));

        }
        //flush 
        em.flush();
        for (int z = 0; z < locked.size(); z++) {
            em.insertRow(locked.get(z), z);
        }
        // System.out.println("Total size of array after bits removed  = " + (em.getRowCount()));
        //get the directory where the source files came from
        File parent = new File(sourceFile).getParentFile();
        String dir = parent.getAbsolutePath();
        //create files
        File sf = null;
        File tf = null;
        try {
            sf = File.createTempFile("source", "tmp");
            tf = File.createTempFile("target", "tmp");
        } catch (IOException ef) {
            ef.printStackTrace();
        }
        System.out.println("Writing temp file:" + sf.getName());
        System.out.println("Writing temp file:" + tf.getName());
        // File mf = new File("merged.tmp");
        //get absolute paths
        String sourceF = sf.getAbsolutePath();
        String targetF = tf.getAbsolutePath();
        //String alignF = mf.getAbsolutePath();
        //write out source and target to files
        //NEW write files to server and return string
        String alignment = "";
        AlignerUtils.reWriteAlignment(targetF, sourceF, slice);
        try {

            alignment = AlignerUtils.MultiPartFileUpload(targetF, sourceF);

        } catch (IOException es) {
            es.printStackTrace();
        }
        //convert the String to a Vector form
        result = AlignerUtils.StringToData(alignment, true, reNumber);
        // append the resultant file to the table
        //System.out.println("Total size of array before bits inserted  = " + (em.getRowCount()));
        for (int y = 0, z = em.getRowCount(); y < result.size(); y++, z++) {

            em.insertRow(result.get(y), z);
            System.out.println("Inserting at position: " + z);
            System.out.println("Inserting from position: " + y);

        }
        //  System.out.println("Total size of array after bits inserted  = " + (em.getRowCount()));
        // }
    } else if (e.getSource() == saveButton) {
        int returnVal = fc.showSaveDialog(AlignmentInterfaceWS.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            //This is where a real application would save the file.
            targetFile = file.getAbsolutePath();
            log.append("Target File " + targetFile + "." + newline);
        } else {
            log.append("Save command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());
    } else if (e.getSource() == export) {
        int returnVal = fc.showSaveDialog(AlignmentInterfaceWS.this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = fc.getSelectedFile();
            outputFile = file.getAbsolutePath();
            //aserver.writeAlignment(targetFile,data);
            AlignerUtils.writeAlignment(outputFile, data);
            log.append(newline + "Saving " + outputFile + "." + newline);
        } else {
            log.append("Save command cancelled by user." + newline);
        }
        log.setCaretPosition(log.getDocument().getLength());
    } else if (e.getSource() == alignButton) {

        if (sl.getText().length() >= 2 && tl.getText().length() >= 2) {

            log.append("Attempting to align texts");
            sourcel = sl.getText();
            targetl = tl.getText();
            String aligned = "";
            try {
                aligned = AlignerUtils.MultiPartFileUpload(sourceFile, targetFile);
            } catch (IOException ed) {

                ed.printStackTrace();
            }
            //Convert string to alignment format
            data = AlignerUtils.StringToData(aligned, false, 0);

            int i = 0;

            //
            // AlreadyRun = true;
            if (i == 0) {
                //log.setCaretPosition(log.getDocument().getLength());
                log.append("\nAutomatic alignment successful!");
                log.append("\nOpening display window......");
                //Set up the editor window
                JFrame edit = new JFrame("Alignment Editor");
                cols = new Vector<String>();
                cols.add("Source");
                cols.add("Target");
                cols.add("Score");
                cols.add("Lock");
                cols.add("Index");
                cols.add("Orig");

                System.out.println("Size of data array " + data.size());
                System.out.println(data.get(0)[0]);
                ex = new ExampleTableModel(cols, data);
                //ex.addTableModelListener(this);
                table = new JTable(ex);
                table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

                TableColumnModel cmodel = table.getColumnModel();

                cmodel.getColumn(0).setCellRenderer(new TextAreaRenderer());
                cmodel.getColumn(1).setCellRenderer(new TextAreaRenderer());
                cmodel.getColumn(2).setCellRenderer(new TextAreaRenderer());
                cmodel.getColumn(4).setCellRenderer(new TextAreaRenderer());
                cmodel.getColumn(5).setCellRenderer(new TextAreaRenderer());
                TextAreaEditor textEditor = new TextAreaEditor();
                textEditor.addCellEditorListener(this);
                cmodel.getColumn(0).setCellEditor(textEditor);
                cmodel.getColumn(1).setCellEditor(textEditor);
                cmodel.getColumn(2).setCellEditor(textEditor);
                cmodel.getColumn(4).setCellEditor(textEditor);
                cmodel.getColumn(5).setCellEditor(textEditor);
                mergeTarget = new JButton("Merge target");
                mergeSource = new JButton("Merge source");
                export = new JButton("Export to File");
                newSegment = new JButton("Create New Segment");
                deleteSegment = new JButton("Delete Selected");
                moveUp = new JButton("Move Segment Up");
                moveDown = new JButton("Move Segment Down");
                lockSelected = new JButton("Lock Selected");
                unlockSelected = new JButton("Unlock Selected");
                reAlign = new JButton("Realign");
                reAlign.addActionListener(this);
                lockSelected.addActionListener(this);
                unlockSelected.addActionListener(this);
                mergeSource.addActionListener(this);
                mergeTarget.addActionListener(this);
                export.addActionListener(this);
                newSegment.addActionListener(this);
                deleteSegment.addActionListener(this);
                moveUp.addActionListener(this);
                moveDown.addActionListener(this);
                JPanel control = new JPanel();
                JPanel manipulate = new JPanel();
                control.add(moveUp);
                control.add(moveDown);
                control.add(mergeTarget);
                control.add(mergeSource);
                //control.add(export);
                control.add(newSegment);
                control.add(deleteSegment);
                manipulate.add(reAlign);
                manipulate.add(lockSelected);
                manipulate.add(unlockSelected);
                manipulate.add(export);
                edit.add(control, BorderLayout.PAGE_START);
                edit.add(manipulate, BorderLayout.PAGE_END);
                JScrollPane scr = new JScrollPane(table);
                //   JTable rowTable = new FirstRowNumberTable(table);

                //scr.add(table);
                //scr.setRowHeaderView(rowTable);
                //scr.setCorner(JScrollPane.UPPER_LEFT_CORNER, rowTable.getTableHeader()); 
                scr.repaint();
                edit.add(scr, BorderLayout.CENTER);
                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                edit.setSize(screenSize.width - 4, screenSize.height - 50);
                int totwidth = screenSize.width - 50;
                table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
                cmodel.getColumn(0).setPreferredWidth((totwidth / 36) * 15);
                cmodel.getColumn(1).setPreferredWidth((totwidth / 36) * 15);
                cmodel.getColumn(2).setPreferredWidth(totwidth / 36 * 2);
                cmodel.getColumn(3).setPreferredWidth(totwidth / 36 * 2);
                cmodel.getColumn(4).setPreferredWidth(totwidth / 36 * 2);
                cmodel.getColumn(4).setPreferredWidth(totwidth / 36 * 2);
                edit.validate(); // Make sure layout is ok

                //edit.setSize(1024,700);
                edit.setVisible(true);

            } else {
                //log.setCaretPosition(log.getDocument().getLength());
                log.append("\nAutomatic alignment unsuccessful..check error logs");
            }
        } else {
            log.append("Please enter valid two letter language codes");
        }
        log.setCaretPosition(log.getDocument().getLength());

    }
}

From source file:es.emergya.ui.gis.popups.SDSDialog.java

public SDSDialog(Recurso r) {
    super();//from   w  w  w.j  a  va  2 s .  co m
    setAlwaysOnTop(true);
    setResizable(false);
    iconTransparente = LogicConstants.getIcon("48x48_transparente");
    iconEnviando = LogicConstants.getIcon("anim_enviando");
    destino = r;
    setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            super.windowClosing(e);
            cancel.doClick();
        }
    });

    // setPreferredSize(new Dimension(400, 150));
    setTitle(i18n.getString("window.sds.titleBar") + " " + r.getIdentificador());
    try {
        setIconImage(((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getIconImage());
    } catch (Throwable e) {
        LOG.error("There is no icon image", e);
    }

    JPanel base = new JPanel();

    base.setBackground(Color.WHITE);
    base.setLayout(new BoxLayout(base, BoxLayout.Y_AXIS));

    // Icono del titulo
    JPanel title = new JPanel(new FlowLayout(FlowLayout.LEADING));
    final JLabel titleLabel = new JLabel(i18n.getString("window.sds.title"),
            LogicConstants.getIcon("tittleventana_icon_enviarsds"), JLabel.LEFT);

    titleLabel.setFont(LogicConstants.deriveBoldFont(12f));
    title.add(titleLabel);
    title.setOpaque(false);
    base.add(title);

    // Espacio para el mensaje
    sds = new JTextArea(7, 40);
    sds.setLineWrap(true);

    final JScrollPane sdsp = new JScrollPane(sds);

    sdsp.setOpaque(false);
    sdsp.setBorder(new TitledBorder(BorderFactory.createLineBorder(Color.BLACK),
            i18n.getString("Admin.message") + "\t (0/" + maxChars + ")"));
    sds.setDocument(new PlainDocument() {
        @Override
        public void insertString(int offs, String str, AttributeSet a) throws BadLocationException {
            if (this.getLength() + str.length() <= maxChars) {
                super.insertString(offs, str, a);
            }
        }
    });
    sds.getDocument().addDocumentListener(new DocumentListener() {
        @Override
        public void removeUpdate(DocumentEvent e) {
            updateChars(e);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            updateChars(e);
        }

        @Override
        public void changedUpdate(DocumentEvent e) {
            updateChars(e);
        }

        private void updateChars(DocumentEvent e) {
            ((TitledBorder) sdsp.getBorder()).setTitle(
                    i18n.getString("Admin.message") + "\t (" + sds.getText().length() + "/" + maxChars + ")");
            sdsp.repaint();
            send.setEnabled(!sds.getText().isEmpty());
            notification.setForeground(Color.WHITE);
            notification.setText("PLACEHOLDER");
        }
    });
    base.add(sdsp);

    // Area para mensajes
    JPanel notificationArea = new JPanel();

    notificationArea.setOpaque(false);
    notification = new JLabel("TEXT");
    notification.setForeground(Color.WHITE);
    notificationArea.add(notification);
    base.add(notificationArea);

    JPanel buttons = new JPanel();

    buttons.setOpaque(false);
    buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS));
    send = new JButton(i18n.getString("Buttons.send"),
            LogicConstants.getIcon("ventanacontextual_button_enviarsds"));
    send.addActionListener(this);
    send.setEnabled(false);
    buttons.add(send);
    buttons.add(Box.createHorizontalGlue());
    progressIcon = new JLabel(iconTransparente);
    buttons.add(progressIcon);
    buttons.add(Box.createHorizontalGlue());
    cancel = new JButton(i18n.getString("Buttons.cancel"), LogicConstants.getIcon("button_cancel"));
    cancel.addActionListener(this);
    buttons.add(cancel);
    base.add(buttons);
    getContentPane().add(base);
    pack();

    int x;
    int y;
    Container myParent;
    try {
        myParent = ((BasicWindow) GoClassLoader.getGoClassLoader().load(BasicWindow.class)).getFrame()
                .getContentPane();
        java.awt.Point topLeft = myParent.getLocationOnScreen();
        Dimension parentSize = myParent.getSize();

        Dimension mySize = getSize();

        if (parentSize.width > mySize.width)
            x = ((parentSize.width - mySize.width) / 2) + topLeft.x;
        else
            x = topLeft.x;

        if (parentSize.height > mySize.height)
            y = ((parentSize.height - mySize.height) / 2) + topLeft.y;
        else
            y = topLeft.y;

        setLocation(x, y);
    } catch (Throwable e1) {
        LOG.error("There is no basic window!", e1);
    }
    this.addWindowListener(new WindowAdapter() {
        @Override
        public void windowOpened(WindowEvent arg0) {
            deleteErrorMessage();
        }

        @Override
        public void windowClosed(WindowEvent arg0) {
            deleteErrorMessage();
        }

        private void deleteErrorMessage() {
            SwingWorker<Object, Object> sw = new SwingWorker<Object, Object>() {
                @Override
                protected Object doInBackground() throws Exception {
                    if (bandejaSalida != null) {
                        MessageGenerator.remove(bandejaSalida.getId());
                    }

                    bandejaSalida = null;

                    return null;
                }

                @Override
                protected void done() {
                    super.done();
                    SDSDialog.this.sds.setText("");
                    SDSDialog.this.sds.setEnabled(true);
                    SDSDialog.this.sds.repaint();
                    SDSDialog.this.progressIcon.setIcon(iconTransparente);
                    SDSDialog.this.progressIcon.repaint();
                    SDSDialog.this.notification.setText("");
                    SDSDialog.this.notification.repaint();
                }
            };

            sw.execute();
        }
    });
}

From source file:interfazGrafica.loginInterface.java

private void consultarUsuariosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_consultarUsuariosActionPerformed
    // TODO add your handling code here:
    panelConsultas.removeAll();/*from w w w  .  j  ava  2  s  .c  o  m*/
    String consultaSQL = "SELECT id_usuario, nombre_usuario, tipo_usuario, estado_usuario FROM usuarios;";
    ResultSet tabla = new OperacionesBD().consultas(consultaSQL);

    try {
        int count = 0;
        while (tabla.next()) {
            count++;
        }

        String[][] data = new String[count][4];
        int i = 0;
        tabla = new OperacionesBD().consultas(consultaSQL);
        while (tabla.next()) {
            data[i][0] = "" + tabla.getInt(1);
            data[i][1] = tabla.getString(2);
            data[i][2] = tabla.getString(3);
            if ("true".equals("" + tabla.getBoolean(4))) {
                data[i][3] = "Activo";
            } else {
                data[i][3] = "Inactivo";
            }
            i++;
        }
        String[] nombreColumnas = { "Identificador", "Nombre", "Rol", "Estado" };
        JTable tablaUsuario = new JTable(data, nombreColumnas);
        BorderLayout bl = new BorderLayout();
        panelConsultas.setLayout(bl);
        JScrollPane jsp = new JScrollPane(tablaUsuario);
        panelConsultas.add(jsp, BorderLayout.CENTER);
        jsp.setBackground(new Color(255, 255, 255));
        panelConsultas.setBackground(new Color(255, 255, 255));
        gerenteJFrame.getContentPane().add(panelContenedor);
        //gerenteJFrame.pack();
        //panelContenedor.setVisible(true);
        cl.show(panelContenedor, "Consultas");
        panelContenedor.repaint();
        panelConsultas.repaint();
        jsp.repaint();
        panelConsultas.setSize(780, 813);

    } catch (SQLException exc) {
        JOptionPane.showMessageDialog(null, "Error al acceder a la base de datos");
        exc.printStackTrace();
    }

}