mKorbel 274

  1. about last column ( "Accept/Reject" )

    • how can I reject ??? with simple JButton
    • JOptionPane should be always wrapped into invokeLater - moved to the end of EDTs queue
  2. when teacher click a row

    • override isSelected in your Xxx(Table)CellRenderer / prepareRenderer, there is place to create painting for JButton
    • JButton is just illusion created, painted by XxxRenderer
    • JTable has Renderer (painting illusions) and Editor (real, semi, temporarry JComponents)
  3. everything depend of your code, otherwise search for Java + Swing + JTable + JButton + Editor, good JButton as TableCellEditor has Swing Action as accelator,

  4. don't put JButton to the XxxTableModel, there is stored value for editor / renderer, just string "Accept" in your case,

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

there is significant difference WindowListener is designated for add (code block e.g. closing resources before) control the closing JVM processes in comparing with the JFrame.setDefaultClose....

mKorbel 274

my view

  • original Java by Sun was about enthusiasm, tons of API has lack in descriptions (authors of description were inspired by MSDN:-)

  • almost, maybe all methods used for Graphics/Graphics2D, available in paint/paintChildren/paintBorder/paintIcon/paintComponent/paintImmediatelly are abstract, part of them is protected (thats one of reasons to declare the paintComponent protected too), just to avoids against an accesses, narrow the penetration from/to uninialized class, void, methods, variables

  • those methods couldn't be accessed from outside, only inside (e.g.) paintComponent, otherwise (dirty casting from outside is possible) result should be exception from RepaintManager,

  • I think thit is top of the safest implementations in compare with AWT methods draw()

  • paintImmediatelly must be call out of EDT (only if isEventDispatchThread returs false) otherwise RepaintManager can lock current JVM instance, forever

mKorbel 274

@JamesCherrill wrote - Interesting question. A quick Google doesnt reveal any subclasses for Graphics2d - maybe they are private?,

---> not is available only for its parent - Graphics,

@JamesCherrill wrote - Please post the answer here if you do find it!

---> yes, no problem with, e.g. :-)

        @Override // paint Icon (JComboBox, JCheckBox, sort icon for RowSorter....)
        public void paintIcon(Component c, Graphics g, int x, int y) {
            g.translate(x, y);
            if (selected) {
            } else {
            g.translate(-x, -y);


     protected void paintComponent(Graphics g) { //draw a Car
        //g.fillOval(0, 0, 25, 25);
        panelWidth = getWidth(); // better by override getPreferredSize
        panelHeight = getHeight(); //then getWidth() and getHeight() returns proper value 
        //polygon points
        int t_x[] = {x + 10, x + 20, x + 30, x + 40};
        int t_y[] = {y + 10, y, y, y + 10};
        g.fillPolygon(t_x, t_y, t_x.length);
        g.fillRect(x, y + 10, 50, 10);
        //g.fillArc(x + 10, y + 20, 10, 10, 0, 360);
        //g.fillArc(x + 30, y + 20, 10, 10, 0, 360);

mKorbel 274

  • assuming to store value as Date, TimeStampt in database

  • you have to use ResultSet.getDate() instead of little bit crazy parsing and then formatting String instance ...

  • every JDatePickers/JCalendar has setValue/Date(Date/Calendar),

  • every good JDatePickers/JCalendar has own FAQs with code examples

  • SpringLayout isn't good LayoutManager for newbee

  • (major issue) don't to create a new Swing Object in try-catch-finally, and you have to notify (to revalidate and repaint for container == JPanel) LayoutManager (thanks that is not implemented as automatical processing) about changes (new JComponent is removed, added, etc) to already visible Swing GUI

mKorbel 274

crossposted on CodeRanch

mKorbel 274

JOptionPane is designated to returns multiple value from multiple fields two ways as is,

  • primitive array

  • (intialized) variables

in all cases is required to test for (easiest by using if - elseif - else)

switch (result) {
  case JOptionPane.OK_OPTION:// and returns from various JButtons
      // code
  case JOptionPane.CANCEL_OPTION: // can be escaped by ESC key
      // code
  case JOptionPane.EXIT_OPTION: //from X button that came from NativeOS
      // code

can't see reasons for ... :-), by default JPanel with multiple JComponents fits very well as parameter for JOptionPane

    int result = JOptionPane.showConfirmDialog (
         focus null or JComponent,  

    public class MyPanel extends JPanel {
         //my JComponents

mKorbel 274

  1. put number to JTable column, better to play with model only

  2. override getColumnClass for correct datatype (String, Double, Date, Icon...)

  3. loop in concrete column by call getValueAt, result from this loop to add JTextField

mKorbel 274

I need to know .... new version. ---> no one of Insubstantials members is not here active

mKorbel 274


  • put all graphics objects to the List

  • inside paintComponent loop inside array of Objects


  • 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

  1. override getPrefferedSize instead of hunting for pixels perfections e.g. diff.getWidth()/getHeight();

  2. then inintial calculations about Width/Height is missunderstaning, thats should be part of paintComponent where getWidth()/getHeight() returns real pixels perfections at runtime

  3. KeyListener is last of property for animations in Swing, use KeyBindings instead

  4. there isn't reason to swap, anything, whatever, never, it should be part of paintComponent again, swap with content in the concrete Tile, never to moving with (you missing concept with JComponents ZOrder)

  5. revalidate should be always with repaint (standard notifiers for LayoutManager)

  6. don't get idea for why reason is there public void setWindowSize(Dimension windowSize), override getPrefferedSize for this container, the LayoutManager do this job perfectly by itsefl

  7. code is wrong designed with lots of effort for basics optimalizations (if something will be based on this code in the future)

mKorbel 274

  • use methods from SwingUtilities, because there is mouse with 5 buttons

  • AWTEventListener can returns MouseEvents too

  • have to accept that isn't possible to create two events from Mouse or KeyBoard in the same time

mKorbel 274

mKorbel 274

" Does getPreferredSize not return how big you want the component to be in the GUI?"

  • there is only one correct notifier for LayoutManager (for customs too), rest mathods are about multiplications events that descreasing performance and increasing unwanted painting artefacts

"instead of repainting 1000x1000 (100 million) tiles each time you just paint the few that have changed."

  • every (J)Components that implements Scrollable (is possible to add to JPanel too) painting only to the Rectagle equals/reduced with/to the JViewport, as is mentioned correctly by @JamesCherrill isn't good idea painting all Objects and off_screen

"if you remove the super.paintComponent"

  • repaint is still there, but just cumulating previous painting without cleaning background, foreground, etc :-), I'm think that you meaning == there is one method implemented in (J)Components.setIgnoreRepaint

I'd have to search for Tiles in JViewport, which are repainted only in the case that they are visible in the JViewport, you would need, have to wait for

your Q contains 1/4 max 1/3 informations that I'm required for real answer, still is there huge space (bigger than entire Milky Way) for dirty guessing on answerers side, another forums required effort as an SSCCE/MCVE, short, runnable, compilable, with hardcoded value in local variables, much luck

mKorbel 274

override (based on code posted here)

  • getPreferredSize for GridPanel

  • use getHeight/Weight in paintComponent

  • change scroll increment for JScrollBar for natural scrolling

important everything is elsewhere

  • no one knows how, what, where, why a size has JFrame, actual part of JSplitPane, not Dimension from JScrollPane, much luck

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

JComponents API has implemented repaint() as recrusive method, container is (very extensive) repainted from a few events, notifiers,

  • create final arrays of Object (once time e.g. as local variable) outside of paintComponent (each of events created a new painting, refreshed by super.paintComponent( g )), inside paintComponent loop in the prepared arrays of Objects

  • override getPreferredSize for JPanel is about correct value for getWidth/Height();

mKorbel 274

but when I resize the window, the shapes change into new ones.

  • talking about resize from container to call repaint(from methods implemented in API), thats correct

  • create an array of Object, inside paintComponent loop inside this array, instead fo creating a new set of Obejcts, because paintComponent is/can be (automatically) called from all mouse, key events and linked methods implemented in APIs (e.g. resize)

  • override getPreferredSize for JPanel for getWidth/Height();

mKorbel 274

mKorbel 274

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

mKorbel 274

I want to copy TextArea text to a File... == for me (including properties from NativeOS, newline, tab, .....) is JTextArea.write

mKorbel 274

  • JOptionPane can returns number, date, image, string

  • as is mentioned read API/Oracle tutorial - How to use Dialogs - two-three parts about JOptionPane

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

I'm think that is designated for Swing Action