Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I did a really quick test, but because you've not provided us with runnable example, it's not possible to reproduce your problem.</p> <p>What I "suspect" is your <code>for-loop</code> is crashing for some reason (the <code>griddim</code> is null or there's an out bounds exception) which is causing the EDT to become unstable.</p> <p>Until you enlighten use with a repeatable, runnable example, we're never going to be sure</p> <pre><code>public class TestGridLine { public static void main(String[] args) { new TestGridLine(); } public TestGridLine() { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { } JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLayout(new BorderLayout()); frame.add(new GridPane()); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }); } public class GridPane extends JPanel { private boolean gridline; public GridPane() { setLayout(new GridBagLayout()); JButton btn = new JButton("Grid"); btn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { setGridLine(!isGridLine()); } }); add(btn); } @Override public Dimension getPreferredSize() { return new Dimension(200, 200); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); int width = getWidth() - 1; int height = getHeight() - 1; //GridBox g.setColor(Color.BLACK); g.drawRect(0, 0, width - 1, height - 1); g.setColor(Color.WHITE); g.fillRect(1, 1, width - 1, height - 1); //draw grid lines if (gridline) { g.setColor(Color.getHSBColor(150, 150, 200)); //vertical lines for (int v = 0; v &lt; width - 2; v += 10) { g.drawLine(v, 1, v, height - 2); } //horizontal lines for (int v = 0; v &lt; height - 2; v += 10) { g.drawLine(1, v, width - 2, v); } } } //returns boolean gridline public boolean isGridLine() { return gridline; } //set the grid line true or false public void setGridLine(boolean islines) { if (islines != gridline) { gridline = islines; repaint(); } } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload