awt

JRadioButton selection color

假装没事ソ 提交于 2019-12-11 11:01:27
问题 When any Radio Button in my Java UI program is selected, the selection is shown by a black dot. I want to make it Green. I'm using Java Swing. I followed the answer given to this SO Question , but it's not working for me. It still shows a black dot when selected. public class OptionFrame extends JFrame { public OptionFrame(){ UIManager.put("RadioButton.focus", new ColorUIResource(Color.GREEN)); SwingUtilities.updateComponentTreeUI(this); } } I'm unable to understand why above code is not

How to create shape with a hole?

萝らか妹 提交于 2019-12-11 10:47:38
问题 How to create shape with a hole in Java? I want to create circle with circular hole inside. If I just add Ellipse2D to a Path I am getting no holes. UPDATE I found, that winding rule controls that: public class Try_Holes_01 { public static void main(String[] args) { //final Path2D path = new Path2D.Double(Path2D.WIND_EVEN_ODD); final Path2D path = new Path2D.Double(Path2D.WIND_NON_ZERO); path.append(new Ellipse2D.Double(100,100,200,200), false); path.append(new Ellipse2D.Double(120,120,100

Why doesn't the String object display that gets pressed key characters appended to it?

天涯浪子 提交于 2019-12-11 10:10:32
问题 I wrote a Java applet code using Key Event handling to demonstrate Non buffered input in Java. My code is working fine and the output is alright but I'm having trouble accomplishing another objective in this program: in the overriden keyPressed() method, I write the line: showStatus(s); , where s is the global static StringBuffer object which the characters typed from the keyboard are appended to. But the showStatus() method displays text on the status bar of the applet viewer. Therefore, the

set JButton size in gridLayout

﹥>﹥吖頭↗ 提交于 2019-12-11 09:06:26
问题 How to set the size of jbutton in gridlayout? otherwise the button size have lot of width and its not listening setSize or setBounds or setPreferedSize. addBut = new JButton("Add"); addBut.addActionListener(this); deleteBut = new JButton("Delete"); deleteBut.addActionListener(this); selectionPanel = new JPanel(); selectionPanel.setLayout(new GridLayout(2,2)); TitledBorder selectionBorder = new TitledBorder("Options"); selectionBorder.setTitleColor(Color.BLUE); selectionPanel.setBorder

How can I append a JTextArea from a method that doesn't contain the JTextArea?

℡╲_俬逩灬. 提交于 2019-12-11 09:03:17
问题 I'm making some test code to practice OOP, and I want to append a JTextArea from the "writeToArea" to the "initialize" method where the JTextArea is defined and initialized. I already tried to directly call the "output" variable, but this returns an "output cannot be resolved" error. I want so that whenever I call the "writeToArea" method in the main class, I'll be able to add lines to the "output" JTextArea in the "initialize" method. Here's the main class: public class Pangea { public

If Swing has more features to design a form. Then what is the use of AWT in java?

戏子无情 提交于 2019-12-11 08:48:46
问题 In java, Swing has more features than the AWT components. For example, In AWT, TextArea ta; Button btn; But its same in Swing as, JTextArea ta; JButton btn; But swing component has good in look. Then what's the need of AWT. Is there any useful feature? 回答1: AWT is useful if you want truer O/S fidelity and can accept a lowest-common-denominator for widget support. It's also immensely useful for building your own light-weight GUI on (suppose, for a game engine). For example, we needed a GUI

Cannot create multiple polygons in Java - only one

北城余情 提交于 2019-12-11 08:27:53
问题 Given the following code : import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.util.ArrayList; import java.util.Iterator; import javax.swing.JFrame; import javax.swing.JPanel; /** * * @author X2 * */ public class PolygonnerJframe { public static void main (String[] args) { JFrame frame = new JFrame("Draw polygons"); frame

what is Alternative of Paint and repaint function?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 07:52:12
问题 Is there any function which can be replaced with paint() and repaint() in java. I have a scenario. There is a triangle (Triangle 1) . when user will click in triangle another triangle (Triangle 2) will appear and 1st (Triangle 1) will be removed from screen. (coded using JFrame , paint() and repaint() ) I have achieved it so far. but problem is when I minimize or change size of window with mouse the output window, it just paint again Triangle 1 rather than Triangle 2 . OR Clear the whole

How can I customize the render of JRadioButton?

浪子不回头ぞ 提交于 2019-12-11 07:15:26
问题 I've created a JRadioButton subclass in which I override the paintComponent method like so: @Override protected void paintComponent(Graphics g) { g.drawImage( isSelected() ? getCheckedImg() : getBasicImg() , 0, 0, this); } but it seems that once the button is drawn, that's the image it uses forever. The isSelected test doesn't seem to have any effect. Are the graphics cached or something by Java? How do I provide my custom JRadioButton with a selected and unselected image? Do I have to write

Java Color from String “Yellow”

让人想犯罪 __ 提交于 2019-12-11 07:01:26
问题 Is there any way we can get color from String (like "White")? Color color; Field field = Class.forName("java.awt.Color").getField("Yellow"); color = (Color)field.get(null); I tried Converting a String to Color in Java and it throws error . What "Field" belongs to? What package do I need to import for it? 回答1: It is because the field that defines yellow is named YELLOW or yellow You have an uppercase Y, which cannot be mapped to a Color. Instead, try: Field field = Class.forName("java.awt