awt

How to properly use the MouseMotionListener to press JButtons?

依然范特西╮ 提交于 2019-12-05 15:24:48
I have made a small Conway Game of Life program. I'm about 80% done. I have used a grid of JButtons as the cells. Right now I have a ButtonListener on every button so you have to one-by-one draw the pattern you want by clicking on individual buttons. I want to be able to click and drag the mouse and select buttons quickly. I used the MotionListener class, implementing the MouseMotionListener and coded the mouseDragged method in an identical fashion as my actionPerformed method in my ButtonListener class. I thought the logic should be the same but I'm definitely missing something. I played

How to configure Google AppEngine to work with vector graphic?

吃可爱长大的小学妹 提交于 2019-12-05 14:20:14
In AppEngine standard environment with Java8 during attempt to use SVG next error appears. I get this error when I try to draw SVG on a XSLFSlide with POI like slide.draw(graphics2D) or to convert SVG to PNG with Batik. The problem seems to appear because fontconfig cannot find fonts. In debian distribution it solves by installing libfontconfig1 . How to solve it on AppEngine? java.lang.NullPointerException at sun.awt.FontConfiguration.getVersion(FontConfiguration.java:1264) at sun.awt.FontConfiguration.readFontConfigFile(FontConfiguration.java:219) at sun.awt.FontConfiguration.init

Converting an AWT application to SWT/JFace

坚强是说给别人听的谎言 提交于 2019-12-05 13:19:16
I am currently toying with the idea of converting a small/medium sized project from AWT to SWT, although Swing is not totally out of the picture yet. I was thinking about converting the main window to an SWT_AWT bridge object, but I have no idea how the semantics for this work. After that, I plan to update dialog for dialog, but not necessarily within one release. Is this possible? Has someone done a conversion like this and can give me some hints? Is there maybe even a tutorial somewhere out there? Is there maybe even a tool that can automate parts of this? I have tried googling, but to no

Is there an equivalent in Java for fieldset (HTML)?

不问归期 提交于 2019-12-05 12:00:19
问题 Is there an element in Java (i.e. Swing/AWT or SWT) that is equivalent to the HTML element fieldset ? 回答1: Create a Panel, create a titled border and you will be able to put inside all your field components. JPanel panel = new JPanel(); panel.add(new JLabel("foo")); panel.setBorder(BorderFactory.createTitledBorder("bar")); 回答2: Have a look at javax.swing.border.TitledBorder . You can set them on panels and are similar in appearance to HTML fieldsets. Border titleBorder = new TitledBorder(new

If Swing is deprecated, what is the alternative?

纵饮孤独 提交于 2019-12-05 10:53:44
问题 I heard that apparently Swing is being developed no longer. I like Swing and use it all the time. What should I now be using instead? 回答1: I never heard such thing and still developing swing apps. Don't give wings to rumors. But as an alternative you can use JavaFx or swt or buoy. 回答2: You probably read something about the 'Swing Application Framework', which while built using Swing, is not 'Swing'. From Swing Application Framework - Status and Roadmap. Development on an open source Reference

setSize not influencing size of button

こ雲淡風輕ζ 提交于 2019-12-05 10:17:59
I have a sample code : import java.awt.*; import javax.swing.*; import javax.swing.border.BevelBorder; public class AWT extends JFrame { public static void main(String[] args) { final JFrame frame = new JFrame(); frame.setPreferredSize(new Dimension(600, 450)); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setBackground(Color.green.darker()); Button btn_1 = new Button("Button 1"); btn_1.setBackground(Color.green.darker()); btn_1.setSize(40, 100); Button btn_2 = new Button("Button 2"); btn_2.setBackground(Color.green.darker()); btn_2.setSize(40, 100); Button btn_3 = new Button(

KeyListener in Textfield not firing when press enter

允我心安 提交于 2019-12-05 08:37:19
I'm trying to make a program that can converts fahrenheit to celcius in java. In program i have 2 Labels and 1 TextField for input. I want to make convert temperature when user types the temperature and presses Enter . To do that, i added a key listener to my textfield but it doesn't work. When i press Enter listener don't fire at all. And here's my code. public class TempConv extends JFrame{ private JLabel info; private JLabel result; private JTextField input; private String outcome; public TempConv(){ super("Temperature Converter"); setLayout(new BorderLayout()); info = new JLabel("Enter

Java check if Checkbox is checked

天大地大妈咪最大 提交于 2019-12-05 08:07:01
I use: CheckboxGroup cg = new CheckboxGroup(); Checkbox c1 = new Checkbox("A", false, cg); Checkbox c2 = new Checkbox("B", false, cg); Checkbox c3 = new Checkbox("C", true, cg); To create a group of three checkboxes. Now, I want to check which one of them is checked. I use: if (c1.isSelected()) { } but this gives The method isSelected() is undefined for the type Checkbox ... Recommended solution is add cast to c1, I do so and it gives Cannot cast from Checkbox to AbstractButton ... Again, how can I just check if a Checkbox if checked? Use getState() boolean checked = c1.getState(); if(c1

The Elegant way to handle Cyclic Event in Java?

≯℡__Kan透↙ 提交于 2019-12-05 07:49:11
i think this not a specific problem to me; everybody might have encountered this issue before. To properly illustrate it, here's a simple UI: As you can see, those two spinners are controlling a single variable -- "A". The only difference is that they control it using different views. Since these two spinners' displaying values are synchronized, cyclic event shows up. If i change the top spinner, "A" will be changed and the bottom spinner's value will also be updated accordingly. However , updating the bottom spinner's call (such as setValue) will also trigger another event instructing the top

Creating a GUI with multiple panels and one frame

泄露秘密 提交于 2019-12-05 07:21:22
问题 I am trying to create a simple GUI. I have a menu bar that is filled with various JMenuItems. Each menu item should link to a different "window". Currently, I am thinking the best way to do this is to create a single frame, and create various JPanels. My ActionListeners will toggle visibility of the different panels, and only one panel should be visible at a time. Is this the best way to go about the task? Or is there a better workaround. 回答1: Yes, the best way is to use a CardLayout of which