mKorbel 274

  • for why reason(s) there is/are two arrays, models, ArrayList and DefaultTableModel

  • add records from database to DefaultTableModel directly, then to add model to JTable

  • search for TableFromDatabase, ResultSetTableModel

mKorbel 274

secondary

  • put all graphics objects to the List

  • inside paintComponent loop inside array of Objects

important

  • don't to call anything from paintComponent - GeneralPath mouthAndTeeth = new GeneralPath(); those object must be prepared before, storred in array of painting,

  • paintComponent is designated for custom painting, events are repeatly called, is very insensive,

  • not good idea to create an amination this way (remove every code GeneralPath from painting)

  • 1st. code line inside paintComponent should be super.paintComponent (reseting background, previous painting, ....)

mKorbel 274

I was looking for a few tips on where to get started?

  • is possible define MAPDATA as enum

  • depends of design I'm miss there tileCount == U32 and U32 == tileCount

mKorbel 274

  • I'm disagree with java.util.Timer in Java7/8 for AWT/Swing based GUI

  • it could be possible by to call firePropertyChange from java.util.Timer

  • standard is (inaccurate) Swing Timer

  • (OP wrote) "I started rezing evrything by screen width, example" its about getPreferredSize and together with stopping to use draw() instead of paint/paintComponent in 21th. century

mKorbel 274

quite disagree with @JamesCherrill

  1. for Java animation is to use a java.util.Timer scheduleAtFixedRate == not is about Swing Timer with repaint

or it should be from any more accurate timer (doesn't matter - java.util.Timer), but events are out of EDT in Java7/8 (removed all thread safe methods, incl. a few issues with repaint() & EDT)

  1. to update the state of the model, then invalidate the GUI state to force a re-draw. == by using PropertyChangeListener/Support

mKorbel 274

mKorbel 274

  • code (skeleton, logics) is correct,
  • not reason to setContentType("text/html"); at runtime

mKorbel 274

mKorbel 274

  1. Why is there AbstractTableModel (works only for methods that are override and if is the correct way), to use DefaultTableModel

  2. Why is there used POJO (public class Product {), two models for the same thing (sure if Product is major model then it make me the sence)

  3. read Oracle tutorial - How to use Tables, part ComboBox as editor, for working code example

  4. why custom editor and renderer for basics stuff, is there some advantage to see painted JComboBox in the JTables cell, I'm really doubt in..

  5. why are there two renderers

  6. (as where mentioned in this thread) don't use renderer for another job as cells decorating, painting is (your renderer can to add 1K rows per one minute from simple mouse events over the JTables view)

  7. is very confusing to add a new row from selection made by (JComboBox as) TableCellEditor,

  8. etc :-)

mKorbel 274

aaaach :-)

My guess is that when the cell is rendered it adds the row, which causes the table to be re-drawn - which renders the cell again - ... loop

The cell renderer isn't a good place to do this. It's just part of the painting, and could get called any time.

yes, exactly

I would try adding a listener to the combo box(es) and using that to add the row etc when the user selection changes in the combo box.

use events implemented in JTables API, e.g. setValueAt is very good start point, easier, direct, without something moreover, nor code, why lots of expensive code lines

mKorbel 274

TableCellRenderer is called from all (could be very intensive, short period and repeatly)

  • Mouse Events inside JTable

  • Key Events

  • events implemented in rellated APIs

mKorbel 274

  • JTable with KeyListener hasn't someting (never, doesn't react to) with KeyEvents in the TableCellEditorr, this is separate JComponent

  • fpr more informations about to read Oracle tutorial HOw to use Tables, part - Concepts: Editors and Renderers

  • never to use low level KeyListener for Swing JComponents, every JComponents has implementer poper listener for every of events

mKorbel 274

  • good catch by @JamesCherrill "use this JLabel in a JTextPane"?,

  • use JEditorPane, without using JLabel as container for image (is possible but there couldn't be real reason for ...),

  • or JLabel (without parent from JTextComponents) is correct way to do that too

mKorbel 274

mKorbel 274

(isn't my cup of java) but you have to set for Scene size (if I'm remember correctly)

mKorbel 274

  1. read Initial Thread

  2. create JFrame as local variable

  3. where going code line menuPanel.setLocation(0, 0);, because JFrame has BorderLayout in API

  4. mode code lines from private void initGUI() and private void addGUIComponents() to constructor public PokeBase()

  5. put LineBorder to JPanel for testing purposes

  6. JTree should be inside JScrollPane

  7. nobody knows (reason for debugging) what is/are wrong in Pokemon class

mKorbel 274

  • most of JComponents has own model then for ButtonModel are accesible the same XxxListener as for AbstractButton

  • from ButtonModel (exclusivelly by using ChangeListener only) is possible to get all mouse & key events from/for/over JButton

mKorbel 274

Or is it something that with time I will just know?

-yes you have to accept that some XxxListener firing only one events, another two

mKorbel 274

@JamesCherrill OT - (Xxx)Map isn't good underlaying array for Swing, missing internal index, must be indexed as key, e.g. you can lost indexing in JTable (view v.s. model and vice versa)

mKorbel 274

agree with Java8 docs for Swing APIs, there weren't significant changes (excluding bridges/APIs between JavaFX8 and Swing)

mKorbel 274

  • (FileIO, JDBC) Socket are long and hard actions,

  • Swing in single threaded and updates to already visible Swing GUI must be done on Event Dispatch Thread, code from hard and long running events by default never to notify EDT, as you can see in your code, every notification to Swing GUI are never updated, are caled out of EDT,

  • there are two options

    1. by using SwingWoker (isn't reusable, is designated for single event)

    2. output from Workers Thread would be wrapped into invokeLater, not whole methods, just single method (e.g. code line txtmsgarea.append(line.substring(8) + "\n"); should be inside invokeLater)

    3. more about EDT in Oracle trail - Concurency in Swing

mKorbel 274

nothing clear from posted question

  • your question is about AWT, GWT, JavaFX, Swing etc...

mKorbel 274

  • wrong, not (enless loop = while), you have to add counter inside ActionPerformed,

  • there to a) increase counter, and b) getText from e.getSource,

  • if(counter == 3) to test if(passCode.equals(input)),

mKorbel 274

  • use JToggleButtons in loop, add ActionListener (already used)

  • you created a new Scanner in every..., how did you want to put that together, remove every code lines in ActionListener, only append String value from e.getSource, there no need to test for every Objects, don't to complicate simple things, create void unlock and if counter raised 3 then to call this void (current JVM should be terminated on success), if success to call

  • create local int variable as counter, and String variable for unlock (there isn't requirement to parse to the integer:-)

  • test for correctness (isSelected) after counter/three JToggleButtons ...., remove all code lines inside, there isn't important to otherwise to 1. reset all JToggleButtons (setSelected(false)) and 2. counter to default value, unlock to "", 4. then to show JOptionPane

  • up to 50 code lines incl. impelmenting a Initial Thread in main class, theoretically you can to use JButtons instead JToggleButtons

mKorbel 274

  • use JFormattedTextField with input mask or add DocumentFilter with Regex to JTextField instead of plain vanilla JTextField

  • you have an issue with Concurency in Swing, your code block a Swing GUI untill all events ended (there is possible to lost part of events for Swing GUI), use Runnable#Thread or SwingWorker for Socket, FileIO, JDBC, etc (moving hard and long running code to WorkersThreads), meaning every code inside ActionListeners should be moved to WorkersThread

  • all updates must be done on EDT (updates to JTextArea), should be wrapped into invokeLater (1st aid in this case, see my descirption in previous point)

  • use standard for moving in JScrollPane for JTextComponents (doesn't works if updates are out of EDT)

    DefaultCaret caret = (DefaultCaret) messageArea.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

  • login.setEnabled(false); and logout.setEnabled(true); shouldn't be works correctly without special woodoo, have to split to two separate events, e.g. another Swing Action (setEnabled is possible to dedicate to the childs/parents)

mKorbel 274

depends on....

  • if current parent JFrame/JDialog/JWindow for JButton quit = new JButton(); or not (not possible to suggest something based on your code and description),

  • if yes, then don't extend JFrame/JDialog/JWindow, create this Object as local variable, use this variable e.g. myWindow.setVisible(false) btw equals for JVM resources setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE/HIDE_ON_CLOSE) at runtime, you can to re_use this window for another action (myWindow.setVisible(true))

mKorbel 274

what's the problem when the whole code for the listener is just like

  • there isn't some, any issue, in this and given form, maybe should be delayed in invokeLater()

... it doesn't need to get the source, or the DocumentEvent, or reference the document or the text area(s) in any way.

  • for real validations you would need to know that, for an answer to the forum, to this question, you are right doesn't matter

mKorbel 274

Do you have any links or refernces I can follow up re problems in sharing a DocumentListener? -- no only experiences, but there is very simple way to confirm, how do you want to get JTextComponent from DocumentWhatever, in most of Listener is event.getSource(e.i.), there is only getDocument, do you have to traversing throught Components tree, not it isn't shareable, but source is testable (my love and very usefull) by get/put(Client)Property only,

edit

get/put(Client)Property for arrays of (e.g.) JButton without needs to put that to the array, this method haven't limits, any nor numbers of, one of ways for PropertyChangeListener

edit (e.g. ), again don't do that, nor chaining Document or add/append document, part of Document or simgle char (KeyTyped) from one JTextComponent to another in the case that are member of one DocumentWhatever

textField = new JTextField(20);
textField.setFont(new Font("Dialog", Font.BOLD, 24));
textField.addActionListener(new MyTextActionListener());
textField.getDocument().addDocumentListener(new MyDocumentListener());
textField.getDocument().putProperty("name", "Text Field");
textArea = new JTextArea();
textArea.setFont(new Font("Dialog", Font.BOLD, 24));
textArea.getDocument().addDocumentListener(new MyDocumentListener());
textArea.getDocument().putProperty("name", "Text Area");

class MyDocumentListener implements DocumentListener {

    final String newline = "\n";

    @Override
    public void insertUpdate(DocumentEvent e) {
        updateLog(e, "inserted into");
    }

    @Override
    public void removeUpdate(DocumentEvent e) {
        updateLog(e, "removed from");
    }

    @Override
    public void changedUpdate(DocumentEvent e) {
        //Plain text components don't fire these events.
    }

    public void updateLog(DocumentEvent e, String action) {
        Document doc = (Document) e.getDocument();
        int changeLength = e.getLength();
        displayArea.append(changeLength + " character"
                + ((changeLength == 1) ? " " : "s ")
                + action + " " + doc.getProperty("name") + "."
                + newline + "  Text ...

mKorbel 274

  • again:-) your GUI will freeze in the case that you'll add more JTextComponents to one DocumentListener/Filter, is quite heavy in some cases is required usage of invokeLater(delaying to the end of EDT), nor that there is orders of JTextComponents in DocumentWhatever,

  • I'll search for real workaround (described in English Language), there isn't another way (my view)

edit:

mKorbel 274

there is one simple way (invoked by - What's the problem with ChangeListener) usage of PropertyChangeListener, every JComponents are accesible for PropertyChangeSupport, then every JComponents will call only one Swing Action/ActionListener by firePropertyChange(mySwingAction, oldValue, newValue) ... done!!! (in the case that user will fills JComponents from top left to the right bottom, otherwise there must runs validation for all required JComponents, every time, when/after user moving with focus)

I can't see any reason why all the text fields cannot call the same one-line listener? == simple this is not possible (API and decision by Swing Team), and DocumentListener is heavy listener, potential performance issue to add/remove one DocumentListener on runtime, forgot to add one DocumentListener to List you can to freeze current Swing GUI (never debugged this issue, too lazy),

What's the problem with ChangeListener for JRadioButton? == you have to override and fireChangeEvent programatically, maybe this is advantage (too lazy bothering with, easiest /number of used chars/ is to test for SELECTED/DESELECTED from ItemListener, I'm suggest to use this listener always for JComboBox, JToggleButton, JRadioButton, JCheckBox)