java - don't repaint or revalidate -


When the program is running, the button has been made 10X10. I changed the button 20X20 by the modified menu, however, the button is not visible.

Appears when you move the mouse to the button Do not be a repetition, it is not even modified.

  package com.test; Import java.awt.CardLayout; Import java.awt.Dimension; Import java.awt.GridLayout; Import java.awt.Toolkit; Import java.awt.event.ActionEvent; Import java.awt.event.ActionListener; Import javax.swing.JButton; Import javax.swing.JFrame; Import javax.swing.JMenu; Import javax.swing.JenuBar; Import javax.swing.JMenuItem; Import javax.swing.JOptionPane; Import javax.swing.JPanel; Public class MenuTest JFrame (private dimension Dimen, Dimenl; private brick exposed, Waips; private Jebtn [] [] Bitian = null; private Jepinl P; private Gridleaut grid; private Kardleaut cards, personal Int Runm; private Int colnum; private Aianel Level ;;); Public () "Main" () {Super ("Game"); P = New ZipLine (); Grid = New Gridlate (); Card = New CardLayout (); createMenu (); Initially ();} Private Zero BuildManu { Jmurbar bar = new jmur (); setJMenuBar (bar) ; Jemmenu File menu = New Jemanu ( "파일 (F)"); filemenu.setMnemonic ( 'F'); Jemenuitm Start menu = new Jemenuitm ( "게임 시작 (s)"); startmenu.setMnemonic ( 'S'); startmenu. setActionCommand ( "Start"); Startmenu.addActionListener (new MenuActionListener ()); filemenu.add (startmenu); Jemenuitm Maikantemenu = new Jemenuitm ( "변경 (M)"); minecntmenu.setMnemonic ( 'M'); minecntmenu.setActionCommand ( "modified"); MycntmenukaddActionListener (new MenuActionListener ()); Filemenukadd (Minecntmenu); Jemenuitm off = new Jemenuitm ( "닫기 (C)"); CloseksetMnemonic ( 'C'); Filemenu.add (close); Bar.add (FileMenu); // JMenuBar JMenu 부착 // 도움말 메뉴 만들기 -------------------------------- JMMenu helpmenu = new JMNU ("도움말 (D) "); Helpmenu.setMnemonic ('D'); // 단축키 를 Alf + D 로 설정 JMNUITIM help = new gemenuitum ("help (h)"); Help.setMnemonic ('H'); Helpmenu.add (help); Bar.add (helpmenu); } Private class MenuActionListener applies ActionListener {public zero action action (action event e) {if (E.E.Tecations Command). Equal ("start") (), ";} Else if (e.getActionCommand (.) Equals (" modify ")) {modified (); jumppane. Show message dialects (empty," 변경 "," 게임 ", Jopshnpen. YES_NO_OPTION);}}} modify Personal zero () {btn = null; SetRowColnum (20, 20); MapInit (20); Leautset (400, 500);} private void initialize () {setRowColnum (10, 10); MapInit (10); Layout Set (200, 250);} Private Vertical Setwave Colenum (Intra Ronam, Int Conam) {this.rownum = rownum; This.colnum = colnum;} Public static zero main (string [] args ) {// TODO auto generated method stub MenuTest mt = no Received MenuTest ();} public void Leautset (Int Word, Int H) {setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); This.setSize (W, H); Dimen = Toolkit.getDefaultToolkit (). GetScreenSize (); Dimen1 = this.getSize (); Xpos = (int) (dimen.getWidth) / 2 - dimen1.getWidth () / 2); Ypos = (int) (dimen.getHyight () / 2 - dimen1.getHeight () / 2); SetLocation (xpos, ypos); this.setVisible (right); this.setResizable (wrong);} Public Zero MapInit (int minecnt) {P.removeAll (); Set BTN (Ronam, Connam); Card = new card layout (5, 5); This.setLayout (card); Grid = new grid layout (Ronam, colnum, 0, 0); P = new zipal (grid); Int actions_num = 0; (For int i = 0; i  

The original code is when you add / remove components from visible GUI :

Panel. Remove (...); Panel.add (...); ... panel.revalidate (); Panel.reapint ();

After deleting / adding all components you need to do revalidate () to implement layout manager and assign all the components a size and space. Then paint () ensures that the components are painted.


Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -