jcomponent

Calling an ActionEvent

杀马特。学长 韩版系。学妹 提交于 2019-12-13 07:51:17
问题 I am in the process of learning and creating a custom JButton/Component. I have the most of what I need, except I do not know how to call actionPerformed on my ActionListners. Code: package myProjects; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Shape; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.*; import java.util.ArrayList; import javax.swing.JButton; import javax

Trouble with JApplets and calling paint/paintComponent

孤街浪徒 提交于 2019-12-13 06:27:42
问题 So I'm just doing some studying for finals here, and I'm having trouble getting this to work. What I have always done previously is call paintComponent(Graphics g) and things have worked just peachy. But now I'm getting a "paintComponent has protected access in JComponent" error when I go to compile. The only way I could get it to compile was to tell it to call paint. But even if it compiles, paint never gets called in the applet window. What am I not seeing here? public class LineDraw

JTable for JPanel with multiple type JComponent (Swing)

北战南征 提交于 2019-12-13 02:41:29
问题 This is a long question, but all code is needed (I was thinking a basic question, with not common components). I need to build a JTable with multiple Columns with multiple type Custom JPanel (with JSlider + JComboBox + JTextField ) in only one Column. I was reading: http://pekalicious.com/blog/custom-jpanel-cell-with-jbuttons-in-jtable/ In this question, I will use one Column with only one Customized JPanel with name PanelSpinnerRadioButton . The Custom Panel : PanelSpinnerRadioButton.java

Cannot do anything while writing to a SourceDataLine

我的未来我决定 提交于 2019-12-13 02:08:43
问题 I am somewhat new to audio in Java. What I am trying to do is as I am playing audio, I want to repaint my JComponent , but the SourceDataLine blocks all other lines of code including other Threads. Here is my play() method public void play() { final AudioFormat af =new AudioFormat(Note.SAMPLE_RATE, 8, 1, true, true); SourceDataLine line; try { line = AudioSystem.getSourceDataLine(af); line.open(af, Note.SAMPLE_RATE); line.start(); byte[] arr=data; for(int position=0;position<arr.length

How do I recursively disable my components in Swing?

 ̄綄美尐妖づ 提交于 2019-12-12 16:05:24
问题 How do I recursively disable all of my components in a JPanel? 回答1: void setEnabled(Component component, boolean enabled) { component.setEnabled(enabled); if (component instanceof Container) { for (Component child : ((Container) component).getComponents()) { setEnabled(child, enabled); } } } Be aware that the previous enabled/disabled state of each component will be lost, unless you keep track of it somewhere else. 来源: https://stackoverflow.com/questions/13920279/how-do-i-recursively-disable

What's the rule of thumb regarding Swing component extension?

早过忘川 提交于 2019-12-12 14:58:05
问题 When dedicating a class to a particular Swing component, is it better to extend that particular component, or construct it internally and provide a reference? public class Foo extends JComponent{ } OR public class Foo{ public JComponent getComponent(){ } } EDIT This is what I mean by dedicating public class Foo{ private static Foo INSTANCE; public static Foo getInstance(){ if(INSTANCE == null){ INSTANCE = new Foo(); } } public void createAndShowComponent(){ //do stuff } } Inside

How to use a swing Timer with JPanel

北慕城南 提交于 2019-12-12 05:42:22
问题 I'm fairly sure I understand how a swing timer works, I just cannot figure out how to apply it in my code. The way I apply it in my code doesn't allow it to draw because Graphics g is outside of its scope. import java.awt.*; import java.awt.event.*; import javax.swing.*; public class JayFrame extends JFrame { public JayFrame() { super("My Frame"); setContentPane(new DrawPane()); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setSize(1200, 675); setResizable(false); setVisible(true); } class

Swing Windowless Component?

怎甘沉沦 提交于 2019-12-12 02:54:37
问题 I want to show a spinning progress wheel thing (like this) when something's processing to show the user something's happening. Is there any way I can do this without popping up a whole window for it? I'm using swing. Thanks. 回答1: Here are two stripped-down instructional examples of how to pop-display an image on the screen. Adjust image source, position, size, exception handling etc. as necessary. Example 1 of 2, Semi-transparent using JLabel: public static void main(String args[]) throws

How to list JComponents from GridBagLayout?

坚强是说给别人听的谎言 提交于 2019-12-11 19:13:19
问题 I am trying to figure out how to print the component names and/or their values after a button is pressed. I currently am using a GridBagLayout with 2 columns and 6 rows but I don't know how to traverse the layout or anything like that inside of my actionPerformed() method. I think it may have to do with getContentPane() but I'm not entirely sure. 回答1: In the following code, I print: System.out.println(comp.getClass().getSimpleName() + " Bounds: " + comp.getBounds()); But for a much more

What is java eqivalent for getElementAt(double x, double y) from acm java Libraries(GraphicsProgram);

笑着哭i 提交于 2019-12-11 11:22:15
问题 in java i tried using getComponentAt(x, y) method from container class. but for given (x,y) co ordinates it is always returning me object of class javax.swing.JRootPane even if (x,y) contains some image/JLabel/JButton. import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import javax.swing.JButton; import javax.swing.JFrame; public class temp2 implements MouseListener{ public static void main(String[] arg){ frame = new JFrame("adsa"); frame.setBounds(0, 0, 1000, 1000); frame