swingutilities

Updating the LAF of a different class

帅比萌擦擦* 提交于 2019-12-25 14:42:05
问题 In a "Battleship" program I wrote, I included the possibility to change the "look and feel" of a program to SystemDefault, "Metal" (Java Default) or "Motif" (also included in Java). If you choose the desired LAF from a JComboBox (--> changes a predefined String, lookFeel ) and press a confirm button, UIManager.setLookAndFeel(lookFeel) is called, and also SwingUtilities.updateComponentTreeUI(this) and the method updateUI() with the following code: public static void updateUI() { /

Scrolling to the other part of the webpage

懵懂的女人 提交于 2019-12-24 14:54:52
问题 I am rendering a webpage and trying to scroll to a location within it. However, the scrolling doesn't work. This is my code... import org.lobobrowser.html.*; import org.lobobrowser.html.gui.HtmlPanel; import org.lobobrowser.html.parser.*; import org.lobobrowser.html.test.*; import org.w3c.dom.*; import org.xml.sax.*; public class finall { Node goTo; public void show(URL url,Node theFinalNode) throws MalformedURLException, IOException, SAXException { goTo = theFinalNode; String uri=url

SwingUtilities.windowForComponent(JFrame) returns null

倖福魔咒の 提交于 2019-12-23 18:02:18
问题 frame is the only JFrame in my Swing app. Since JFrame extends Window I have believed from description and method name that the code should return the frame itself. SwingUtilities.windowForComponent(frame) public static Window windowForComponent(Component aComponent) Return aComponent's window But it returns null , because implementation is like this public static Window windowForComponent(Component c) { return getWindowAncestor(c); } public static Window getWindowAncestor(Component c) { for

What is SwingUtilities.invokeLater [duplicate]

亡梦爱人 提交于 2019-12-18 03:19:09
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: What does SwingUtilities.invokeLater do? SwingUtilities.invokeLater I have seen this little piece of code hundreds of times: public static void main(String[] args) { javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run() { createAndShowGUI(); } }); } Now my question is: what does invokeLater() do? What kind of bad things will happen if I just create and show my GUI inside the main thread? 回答1:

Java/Swing: Obtain Window/JFrame from inside a JPanel

岁酱吖の 提交于 2019-12-17 10:25:44
问题 How can I get the JFrame in which a JPanel is living? My current solution is to ask the panel for it's parent (and so on) until I find a Window: Container parent = this; // this is a JPanel do { parent = parent.getParent(); } while (!(parent instanceof Window) && parent != null); if (parent != null) { // found a parent Window } Is there a more elegant way, a method in the Standard Library may be? 回答1: You could use SwingUtilities.getWindowAncestor(...) method that will return a Window that

Change Font at runtime

拥有回忆 提交于 2019-12-17 06:16:09
问题 Please is there another way how to change Font at runtime as using FontUIResource, for the whole AWT/Swing GUI, without any knowledge / interest about if there are local variables and type of JComponents import java.awt.*; import java.awt.event.*; import java.util.Locale; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; import javax.swing.plaf.FontUIResource; import javax.swing.plaf.basic.BasicComboBoxRenderer; public class SystemFontDisplayer extends

java - string return method is called before any value is assigned to string

两盒软妹~` 提交于 2019-12-13 09:39:27
问题 My application is supposed to read and write to a Serial Port. The data is read in the EventListener of the PortReader class. I wish to assign this data to a global String variable (private String sPortReaderString) for further use. The global string variable should return its value by using a method called getPortReader() which simply returns the string sPortReaderString. In the application's JFrame I open the serial port connection, send a command for which I automatically receive a reply

'SwingUtilities.updateComponentTreeUI(this)' removes custom Document from JComboBox

早过忘川 提交于 2019-12-12 05:18:36
问题 I have an editable JComboBox and JTextField. Both with custom Documents. Here is the code: import java.awt.*; import javax.swing.*; import javax.swing.text.AttributeSet; import javax.swing.text.BadLocationException; import javax.swing.text.PlainDocument; public class SwingUtilStrangeBehav extends JFrame { public SwingUtilStrangeBehav() { JComboBox<String> combo = new JComboBox<>(new String[]{"a", "b", "c"}); combo.setEditable(true); ((JTextField)combo.getEditor().getEditorComponent())

Java Swing ProgressBar update while computing

房东的猫 提交于 2019-12-12 03:45:32
问题 There are some example for similar question (Progress Bar Java) and (Java uploading percentage progressbar thread) but didn't understand how to make it work for my code. My main has 2 panels one over the other (one of which is a tabbedPane with 2 tabs) public class MainIRH { public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException |

html files encryption for client side

泪湿孤枕 提交于 2019-12-11 05:14:38
问题 I am using lucene for indexing and searching on client side after searching the keyword i want to display the html files there . So is there any way to store and access the html files . actually the html files are storing images and links and they should be opened in the java api as normal html file . I am using the following code for lucene indexing try { IndexWriter indexWriter = new IndexWriter( FSDirectory.open(indexDir), new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);