누구든지이 문제에 대해 도움을받을 수 있습니까?테이블에 문자열 지정
String inventory[][] = {{"Chairs","Tables"},{"Bed","Sofas"}}
내가이 격자를 생성하는 중첩 for
루프와 drawLine
을 사용하지만 테이블 내부의 String
을 넣어 관리 할 수 있습니다 : 난 내가 JTable의 사용하지 않고 테이블에서 플롯 할 String
의 배열을 가지고. 누구든지 나를 도울 수 있습니까?
내 프로그램이 아니지만 이것은 인터넷 양식을 가지고있는 폐쇄 예제입니다. 내 프로그램이 조금 simillar입니다.
import java.awt.* ;
import java.awt.event.* ;
import javax.swing.* ;
import javax.swing.border.TitledBorder;
import javax.swing.border.EtchedBorder;
import java.awt.*;
import java.awt.event.*;
public class testtable extends JFrame {
private static final int DRAWING_SIZE = 600;
private static final int SUBDIVISIONS = 2;
private static final int SUBDIVISION_SIZE = DRAWING_SIZE/SUBDIVISIONS;
public testtable() {
setSize(800, 800);
setLayout(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1.0;
gbc.weighty = 1.0;
gbc.gridx = 0;
gbc.gridy = 0;
JLabel drawingBoard = new JLabel("Drawing Board");
gbc.anchor = GridBagConstraints.SOUTH;
drawingBoard.setFont(new Font("Serif", Font.BOLD, 28));
add(drawingBoard, gbc);
JPanel panel = new JPanel() {
@Override public void paintComponent(Graphics g) {
super.paintComponent(g);
Graphics2D g2 = (Graphics2D) g;
g2.setPaint(Color.GRAY);
for (int i = 1; i < SUBDIVISIONS; i++) {
int x = i * SUBDIVISION_SIZE;
g2.drawLine(x, 0, x, getSize().height);
}
for (int i = 1; i < SUBDIVISIONS; i++) {
int y = i * SUBDIVISION_SIZE;
g2.drawLine(0, y, getSize().width, y);
}
}
};
panel.setPreferredSize(new Dimension(DRAWING_SIZE, DRAWING_SIZE));
panel.setBackground(Color.WHITE);
panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
gbc.gridy++;
gbc.anchor = GridBagConstraints.CENTER;
add(panel, gbc);
JButton saveDrawing = new JButton("SAVE DRAWING");
gbc.gridy++;
gbc.anchor = GridBagConstraints.NORTH;
add(saveDrawing, gbc);
}
public static void main(String[] args) {
(new testtable()).setVisible(true);
}
}
지금 가지고있는 코드는 무엇입니까? 우리가 당신을 도울 수 있을지도 모릅니다. –
미안해, 내 논문에서 그 부분을 할 수는 없지만 여기는 인터넷을 통해 얻을 수있는 폐쇄적 인 예다. 정확히 동일하지는 않지만 닫습니다. – user1110191
아직 샘플을 제공하지 않으므로 최선의 방법은 추측입니다. 내 생각 엔 당신이 Graphics2D 메서드를 망치고 있다는 것입니까? 그런 다음 drawString 메서드를 사용하면됩니다. –